Skip to content

Commit 2953614

Browse files
Port WAMR to the FreeBSD platform and update the document (#1825)
1 parent 6fd8001 commit 2953614

8 files changed

Lines changed: 339 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include "platform_api_vmcore.h"
7+
8+
int
9+
bh_platform_init()
10+
{
11+
return 0;
12+
}
13+
14+
void
15+
bh_platform_destroy()
16+
{}
17+
18+
int
19+
os_printf(const char *format, ...)
20+
{
21+
int ret = 0;
22+
va_list ap;
23+
24+
va_start(ap, format);
25+
#ifndef BH_VPRINTF
26+
ret += vprintf(format, ap);
27+
#else
28+
ret += BH_VPRINTF(format, ap);
29+
#endif
30+
va_end(ap);
31+
32+
return ret;
33+
}
34+
35+
int
36+
os_vprintf(const char *format, va_list ap)
37+
{
38+
#ifndef BH_VPRINTF
39+
return vprintf(format, ap);
40+
#else
41+
return BH_VPRINTF(format, ap);
42+
#endif
43+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#ifndef _PLATFORM_INTERNAL_H
7+
#define _PLATFORM_INTERNAL_H
8+
9+
#include <inttypes.h>
10+
#include <stdbool.h>
11+
#include <assert.h>
12+
#include <time.h>
13+
#include <string.h>
14+
#include <stdio.h>
15+
#include <stdlib.h>
16+
#include <math.h>
17+
#include <stdarg.h>
18+
#include <ctype.h>
19+
#include <pthread.h>
20+
#include <signal.h>
21+
#include <semaphore.h>
22+
#include <limits.h>
23+
#include <dirent.h>
24+
#include <fcntl.h>
25+
#include <unistd.h>
26+
#include <poll.h>
27+
#include <sched.h>
28+
#include <errno.h>
29+
#include <netinet/in.h>
30+
#include <sys/types.h>
31+
#include <sys/socket.h>
32+
#include <sys/stat.h>
33+
#include <sys/mman.h>
34+
#include <sys/time.h>
35+
#include <sys/uio.h>
36+
#include <sys/ioctl.h>
37+
#include <sys/socket.h>
38+
#include <sys/resource.h>
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
#ifndef BH_PLATFORM_FREEBSD
45+
#define BH_PLATFORM_FREEBSD
46+
#endif
47+
48+
#define BH_HAS_DLFCN 1
49+
50+
/* Stack size of applet threads's native part. */
51+
#define BH_APPLET_PRESERVED_STACK_SIZE (32 * 1024)
52+
53+
/* Default thread priority */
54+
#define BH_THREAD_DEFAULT_PRIORITY 0
55+
56+
typedef pthread_t korp_tid;
57+
typedef pthread_mutex_t korp_mutex;
58+
typedef pthread_cond_t korp_cond;
59+
typedef pthread_t korp_thread;
60+
typedef sem_t korp_sem;
61+
62+
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
63+
64+
#define os_thread_local_attribute __thread
65+
66+
#define bh_socket_t int
67+
68+
#if WASM_DISABLE_HW_BOUND_CHECK == 0
69+
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
70+
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
71+
|| defined(BUILD_TARGET_RISCV64_LP64)
72+
73+
#include <setjmp.h>
74+
75+
#define OS_ENABLE_HW_BOUND_CHECK
76+
77+
typedef jmp_buf korp_jmpbuf;
78+
79+
#define os_setjmp setjmp
80+
#define os_longjmp longjmp
81+
#define os_alloca alloca
82+
83+
#define os_getpagesize getpagesize
84+
85+
typedef void (*os_signal_handler)(void *sig_addr);
86+
87+
int
88+
os_thread_signal_init(os_signal_handler handler);
89+
90+
void
91+
os_thread_signal_destroy();
92+
93+
bool
94+
os_thread_signal_inited();
95+
96+
void
97+
os_signal_unmask();
98+
99+
void
100+
os_sigreturn();
101+
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
102+
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
103+
104+
#ifdef __cplusplus
105+
}
106+
#endif
107+
108+
#endif /* end of _PLATFORM_INTERNAL_H */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
5+
6+
add_definitions(-DBH_PLATFORM_FREEBSD)
7+
8+
include_directories(${PLATFORM_SHARED_DIR})
9+
include_directories(${PLATFORM_SHARED_DIR}/../include)
10+
11+
include (${CMAKE_CURRENT_LIST_DIR}/../common/posix/platform_api_posix.cmake)
12+
13+
file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c)
14+
15+
set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_POSIX_SOURCE})
16+
17+
file (GLOB header ${PLATFORM_SHARED_DIR}/../include/*.h)
18+
LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})

doc/build_wamr.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,18 @@ $ ls ../build_out/
637637
libvmlib.a ) and an executable binary (*iwasm*) and copy *iwasm* to
638638
*build_out*. All original generated files are still under
639639
*product-mini/platforms/linux/build*.
640+
641+
FreeBSD
642+
-------------------------
643+
First, install the dependent packages:
644+
```shell
645+
sudo pkg install gcc cmake wget
646+
```
647+
648+
Then you can run the following commands to build iwasm with default configurations:
649+
```shell
650+
cd product-mini/platforms/freebsd
651+
mkdir build && cd build
652+
cmake ..
653+
make
654+
```
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required (VERSION 2.9)
5+
6+
project (iwasm)
7+
8+
set (WAMR_BUILD_PLATFORM "freebsd")
9+
10+
# Reset default linker flags
11+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
12+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
13+
14+
# Set WAMR_BUILD_TARGET, currently values supported:
15+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
16+
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
17+
if (NOT DEFINED WAMR_BUILD_TARGET)
18+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
19+
set (WAMR_BUILD_TARGET "AARCH64")
20+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
21+
set (WAMR_BUILD_TARGET "RISCV64")
22+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
23+
# Build as X86_64 by default in 64-bit platform
24+
set (WAMR_BUILD_TARGET "X86_64")
25+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
26+
# Build as X86_32 by default in 32-bit platform
27+
set (WAMR_BUILD_TARGET "X86_32")
28+
else ()
29+
message(SEND_ERROR "Unsupported build target platform!")
30+
endif ()
31+
endif ()
32+
33+
if (NOT CMAKE_BUILD_TYPE)
34+
set(CMAKE_BUILD_TYPE Release)
35+
endif ()
36+
37+
set(CMAKE_CXX_STANDARD 14)
38+
39+
if (NOT DEFINED WAMR_BUILD_INTERP)
40+
# Enable Interpreter by default
41+
set (WAMR_BUILD_INTERP 1)
42+
endif ()
43+
44+
if (NOT DEFINED WAMR_BUILD_AOT)
45+
# Enable AOT by default.
46+
set (WAMR_BUILD_AOT 1)
47+
endif ()
48+
49+
if (NOT DEFINED WAMR_BUILD_JIT)
50+
# Disable JIT by default.
51+
set (WAMR_BUILD_JIT 0)
52+
endif ()
53+
54+
if (NOT DEFINED WAMR_BUILD_FAST_JIT)
55+
# Disable Fast JIT by default
56+
set (WAMR_BUILD_FAST_JIT 0)
57+
endif ()
58+
59+
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
60+
# Enable libc builtin support by default
61+
set (WAMR_BUILD_LIBC_BUILTIN 1)
62+
endif ()
63+
64+
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
65+
# Enable libc wasi support by default
66+
set (WAMR_BUILD_LIBC_WASI 1)
67+
endif ()
68+
69+
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
70+
# Enable fast interpreter
71+
set (WAMR_BUILD_FAST_INTERP 1)
72+
endif ()
73+
74+
if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
75+
# Disable multiple module by default
76+
set (WAMR_BUILD_MULTI_MODULE 0)
77+
endif ()
78+
79+
if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
80+
# Disable pthread library by default
81+
set (WAMR_BUILD_LIB_PTHREAD 0)
82+
endif ()
83+
84+
if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
85+
# Disable wasm mini loader by default
86+
set (WAMR_BUILD_MINI_LOADER 0)
87+
endif ()
88+
89+
if (NOT DEFINED WAMR_BUILD_SIMD)
90+
# Enable SIMD by default
91+
set (WAMR_BUILD_SIMD 1)
92+
endif ()
93+
94+
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
95+
# Disable Debug feature by default
96+
set (WAMR_BUILD_DEBUG_INTERP 0)
97+
endif ()
98+
99+
if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
100+
set (WAMR_BUILD_FAST_INTERP 0)
101+
set (WAMR_BUILD_MINI_LOADER 0)
102+
set (WAMR_BUILD_SIMD 0)
103+
endif ()
104+
105+
set (WAMR_DISABLE_HW_BOUND_CHECK 1)
106+
107+
set (CMAKE_SHARED_LINKER_FLAGS "-Wl")
108+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
109+
110+
set (CMAKE_MACOSX_RPATH True)
111+
112+
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
113+
114+
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
115+
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
116+
117+
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
118+
119+
add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
120+
121+
install (TARGETS iwasm DESTINATION bin)
122+
123+
target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
124+
125+
add_library (libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
126+
127+
install (TARGETS libiwasm DESTINATION lib)
128+
129+
set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
130+
131+
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
132+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
rm -fr build && mkdir build
7+
cd build
8+
cmake .. -DWAMR_BUILD_JIT=1
9+
nproc=$(sysctl -n hw.ncpu)
10+
make -j ${nproc}
11+
cd ..
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2020 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
/usr/bin/env python3 ../../../build-scripts/build_llvm.py "$@"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include "../posix/main.c"

0 commit comments

Comments
 (0)