Skip to content

Commit 8ec03a5

Browse files
authored
add porting codes of rt-thread (#494)
1 parent 8a47778 commit 8ec03a5

23 files changed

Lines changed: 1294 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The iwasm supports the following architectures:
5151
Following platforms are supported. Refer to [WAMR porting guide](./doc/port_wamr.md) for how to port WAMR to a new platform.
5252

5353
- [Linux](./doc/build_wamr.md#linux), [Linux SGX (Intel Software Guard Extension)](./doc/linux_sgx.md), [MacOS](./doc/build_wamr.md#macos), [Android](./doc/build_wamr.md#android), [Windows](./doc/build_wamr.md#windows)
54-
- [Zephyr](./doc/build_wamr.md#zephyr), [AliOS-Things](./doc/build_wamr.md#alios-things), [VxWorks](./doc/build_wamr.md#vxworks), [NuttX](./doc/build_wamr.md#nuttx)
54+
- [Zephyr](./doc/build_wamr.md#zephyr), [AliOS-Things](./doc/build_wamr.md#alios-things), [VxWorks](./doc/build_wamr.md#vxworks), [NuttX](./doc/build_wamr.md#nuttx), [RT-Thread](./doc/build_wamr.md#RT-Thread)
5555

5656
### Build iwasm VM core (mini product)
5757

SConscript

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
# for module compiling
8+
import os
9+
10+
from building import *
11+
12+
objs = []
13+
cwd = GetCurrentDir()
14+
list = os.listdir(cwd)
15+
16+
if GetDepend(['PKG_USING_WAMR']):
17+
wamr_entry_sconscript = os.path.join(cwd, "product-mini", "platforms", "rt-thread", 'SConscript')
18+
19+
if os.path.isfile(wamr_entry_sconscript):
20+
objs = objs + SConscript(wamr_entry_sconscript)
21+
else:
22+
print("[WAMR] entry script wrong:", wamr_entry_sconscript)
23+
Return('objs')
24+
25+
wamr_runlib_sconsript = os.path.join(cwd, "build-scripts", 'SConscript')
26+
27+
if os.path.isfile(wamr_runlib_sconsript):
28+
objs = objs + SConscript(wamr_runlib_sconsript)
29+
else:
30+
print("[WAMR] runtime lib script wrong:", wamr_runlib_sconsript)
31+
32+
Return('objs')
33+

build-scripts/SConscript

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
import os
8+
from building import *
9+
10+
cwd = GetCurrentDir()
11+
objs = []
12+
13+
WAMR_ROOT_DIR = os.path.join(cwd, "..")
14+
15+
16+
SHARED_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'shared')
17+
18+
IWASM_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'iwasm')
19+
20+
APP_MGR_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-mgr')
21+
22+
APP_FRAMEWORK_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-framework')
23+
24+
DEPS_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'deps')
25+
26+
if GetDepend(['WAMR_BUILD_INTERP']):
27+
script_path = os.path.join(IWASM_DIR, 'interpreter', 'SConscript')
28+
objs += SConscript(script_path)
29+
30+
31+
if GetDepend(['WAMR_BUILD_AOT']):
32+
script_path = os.path.join(IWASM_DIR, 'aot', 'SConscript')
33+
objs += SConscript(script_path)
34+
if GetDepend(['WAMR_BUILD_JIT']):
35+
script_path = os.path.join(IWASM_DIR, 'compilation', 'SConscript')
36+
objs += SConscript(script_path)
37+
38+
39+
if GetDepend(['WAMR_BUILD_APP_FRAMEWORK']):
40+
objs += SConscript(os.path.join(APP_FRAMEWORK_DIR, 'SConscript'))
41+
objs += SConscript(os.path.join(SHARED_DIR, 'coap', 'SConscript'))
42+
objs += SConscript(os.path.join(APP_MGR_DIR, 'app-manager', 'SConscript'))
43+
objs += SConscript(os.path.join(APP_MGR_DIR, 'app-mgr-shared', 'SConscript'))
44+
45+
46+
47+
if GetDepend(['WAMR_BUILD_LIBC_BUILTIN']):
48+
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-builtin', 'SConscript'))
49+
50+
51+
52+
if GetDepend(['WAMR_BUILD_LIBC_WASI']):
53+
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-wasi', 'SConscript'))
54+
55+
56+
if GetDepend(['WAMR_BUILD_LIB_PTHREAD']):
57+
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-pthread', 'SConscript'))
58+
# TODO: 这里加一下
59+
60+
61+
62+
# if (WAMR_BUILD_THREAD_MGR EQUAL 1)
63+
# include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
64+
# endif ()
65+
66+
if GetDepend(['WAMR_BUILD_THREAD_MGR']):
67+
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'thread-mgr', 'SConscript'))
68+
69+
70+
71+
# if (WAMR_BUILD_LIBC_EMCC EQUAL 1)
72+
# include (${IWASM_DIR}/libraries/libc-emcc/libc_emcc.cmake)
73+
# endif()
74+
75+
if GetDepend(['WAMR_BUILD_LIBC_EMCC']):
76+
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-emmc', 'SConscript'))
77+
78+
objs += SConscript(os.path.join(cwd, 'SConscript_config'));
79+
80+
81+
objs += SConscript(os.path.join(SHARED_DIR, 'platform', 'rt-thread', 'SConscript'))
82+
objs += SConscript(os.path.join(SHARED_DIR, 'mem-alloc', 'SConscript'))
83+
objs += SConscript(os.path.join(IWASM_DIR, 'common', 'SConscript'))
84+
objs += SConscript(os.path.join(SHARED_DIR, 'utils', 'SConscript'))
85+
86+
87+
88+
Return('objs')

build-scripts/SConscript_config

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
3+
import os
4+
import re
5+
6+
from building import *
7+
#
8+
# Copyright (c) 2021, RT-Thread Development Team
9+
#
10+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
#
12+
13+
Import('rtconfig')
14+
15+
src = Split('''
16+
''')
17+
objs = []
18+
cwd = GetCurrentDir()
19+
20+
IWASM_INC_DIR = os.path.join(cwd, '..', 'core', 'iwasm', 'include')
21+
22+
# include_directories (${IWASM_DIR}/include)
23+
24+
CPPPATH = [IWASM_INC_DIR]
25+
26+
if rtconfig.BUILD == 'debug':
27+
CPPDEFINES = ['BH_DEBUG=1']
28+
else:
29+
CPPDEFINES = ['BH_DEBUG=0']
30+
31+
if rtconfig.ARCH == 'arm':
32+
if re.match('^cortex-m.*', rtconfig.CPU):
33+
print('[WAMR] using thumbv4t')
34+
CPPDEFINES += ['BUILD_TARGET_THUMB']
35+
CPPDEFINES += [r'BUILD_TARGET=\"thumbv4t\"']
36+
elif re.match('^cortex-a.*', rtconfig.CPU):
37+
print('[WAMR] using armv7')
38+
CPPDEFINES += ['BUILD_TARGET_ARM']
39+
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"']
40+
elif re.match('^cortex-r.*', rtconfig.CPU):
41+
print('[WAMR] using armv7')
42+
CPPDEFINES += ['BUILD_TARGET_ARM']
43+
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"']
44+
elif rtconfig.CPU == 'armv6':
45+
print('[WAMR] using armv6')
46+
CPPDEFINES += ['BUILD_TARGET_ARM']
47+
CPPDEFINES += [r'BUILD_TARGET=\"armv6\"']
48+
elif re.match('^arm9*', rtconfig.CPU):
49+
print('[WAMR] using armv4')
50+
CPPDEFINES += ['BUILD_TARGET_ARM']
51+
CPPDEFINES += [r'BUILD_TARGET=\"armv4\"']
52+
53+
else:
54+
print("[WAMR] unknown arch", rtconfig.ARCH)
55+
56+
57+
LIBS = ['m']
58+
59+
if GetDepend(['WAMR_BUILD_INTERP']):
60+
CPPDEFINES += ['WASM_ENABLE_INTERP=1']
61+
if GetDepend(['WAMR_BUILD_FAST_INTERP']):
62+
CPPDEFINES += ['WASM_ENABLE_FAST_INTERP=1']
63+
print("[WAMR] fast interpreter was enabled")
64+
else:
65+
CPPDEFINES += ['WASM_ENABLE_FAST_INTERP=0']
66+
print("[WAMR] fast interpreter was disabled")
67+
else:
68+
CPPDEFINES += ['WASM_ENABLE_INTERP=0']
69+
70+
CPPDEFINES += ['WASM_ENABLE_JIT=0']
71+
72+
if GetDepend(['WAMR_BUILD_MULTI_MODULE']):
73+
CPPDEFINES += ['WASM_ENABLE_MULTI_MODULE=1']
74+
else:
75+
CPPDEFINES += ['WASM_ENABLE_MULTI_MODULE=0']
76+
77+
if GetDepend(['WAMR_BUILD_SPEC_TEST']):
78+
CPPDEFINES += ['WASM_ENABLE_SPEC_TEST=1']
79+
print("[WAMR] spec test compatible mode was enabled")
80+
81+
if GetDepend(['WAMR_BUILD_BULK_MEMORY']):
82+
CPPDEFINES += ['WASM_ENABLE_BULK_MEMORY=1']
83+
print("[WAMR] Bulk memory feature was enabled")
84+
else:
85+
CPPDEFINES += ['WASM_ENABLE_BULK_MEMORY=0']
86+
87+
if GetDepend(['WAMR_BUILD_SHARED_MEMORY']):
88+
CPPDEFINES += ['WASM_ENABLE_SHARED_MEMORY=1']
89+
print("[WAMR] Shared memory enabled")
90+
else:
91+
CPPDEFINES += ['WASM_ENABLE_SHARED_MEMORY=0']
92+
93+
if GetDepend(['WAMR_BUILD_MINI_LOADER']):
94+
CPPDEFINES += ['WASM_ENABLE_MINI_LOADER=1']
95+
print("[WAMR] mini loader enabled")
96+
else:
97+
CPPDEFINES += ['WASM_ENABLE_MINI_LOADER=0']
98+
99+
if GetDepend(['WAMR_DISABLE_HW_BOUND_CHECK']):
100+
CPPDEFINES += ['WASM_DISABLE_HW_BOUND_CHECK=1']
101+
print("[WAMR] Hardware boundary check disabled")
102+
103+
if GetDepend(['WAMR_BUILD_SIMD']):
104+
CPPDEFINES += ['WASM_ENABLE_SIMD=1']
105+
print('[WAMR] SIMD enabled')
106+
107+
if GetDepend(['WAMR_BUILD_MEMORY_PROFILING']):
108+
CPPDEFINES += ['WASM_ENABLE_MEMORY_PROFILING=1']
109+
print('[WAMR] Memory profiling enabled')
110+
111+
if GetDepend(['WAMR_BUILD_CUSTOM_NAME_SECTION']):
112+
CPPDEFINES += ['WASM_ENABLE_CUSTOM_NAME_SECTION=1']
113+
print('[WAMR] Custom name section enabled')
114+
115+
if GetDepend(['WAMR_BUILD_TAIL_CALL']):
116+
CPPDEFINES += ['WASM_ENABLE_TAIL_CALL=1']
117+
print('[WAMR] Tail call enabledd')
118+
119+
120+
group = DefineGroup('wamr_config_common', src, depend = ['PKG_USING_WAMR'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
121+
122+
Return('group')
123+

core/iwasm/aot/SConscript

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
from building import *
8+
import re
9+
Import('rtconfig')
10+
11+
cwd = GetCurrentDir()
12+
13+
src = Split('''
14+
aot_loader.c
15+
aot_runtime.c
16+
''')
17+
18+
if rtconfig.ARCH == 'arm':
19+
if re.match('^cortex-m.*', rtconfig.CPU):
20+
src += ['arch/aot_reloc_thumb.c']
21+
elif re.match('^cortex-a.*', rtconfig.CPU):
22+
src += ['arch/aot_reloc_arm.c']
23+
24+
25+
CPPPATH = [cwd, cwd + '/../include']
26+
27+
CPPDEFINES = ['WASM_ENABLE_AOT=1']
28+
29+
group = DefineGroup('iwasm_aot', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
30+
31+
Return('group')

core/iwasm/common/SConscript

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
from building import *
8+
import re
9+
10+
Import('rtconfig')
11+
12+
cwd = GetCurrentDir()
13+
14+
src = Glob('*.c')
15+
16+
if rtconfig.ARCH == 'arm':
17+
if re.match('^cortex-m.*', rtconfig.CPU):
18+
src += ['arch/invokeNative_thumb.s']
19+
elif re.match('^cortex-a.*', rtconfig.CPU):
20+
src += ['arch/invokeNative_arm.s']
21+
22+
CPPPATH = [cwd, cwd + '/../include']
23+
24+
group = DefineGroup('iwasm_common', src, depend = [''], CPPPATH = CPPPATH)
25+
26+
Return('group')

core/iwasm/interpreter/SConscript

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
from building import *
8+
9+
cwd = GetCurrentDir()
10+
11+
src = Split('''
12+
wasm_runtime.c
13+
''')
14+
15+
if GetDepend(['WAMR_BUILD_FAST_INTERP']):
16+
src += ["wasm_interp_fast.c"]
17+
else:
18+
src += ["wasm_interp_classic.c"]
19+
20+
if GetDepend(['WAMR_BUILD_MINI_LOADER']):
21+
src += ["wasm_mini_loader.c"]
22+
else:
23+
src += ["wasm_loader.c"]
24+
25+
26+
CPPPATH = [cwd]
27+
28+
group = DefineGroup('iwasm_interpreter', src, depend = [''], CPPPATH = CPPPATH)
29+
30+
Return('group')
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
from building import *
8+
9+
cwd = GetCurrentDir()
10+
11+
src = Split('''
12+
libc_pthread_wrapper.c
13+
''')
14+
15+
CPPPATH = [cwd]
16+
17+
18+
group = DefineGroup('iwasm_libc_pthread', src, depend = [''], CPPPATH = CPPPATH)
19+
20+
Return('group')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (c) 2021, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
#
6+
7+
from building import *
8+
9+
cwd = GetCurrentDir()
10+
11+
#src = Split('''
12+
#libc_builtin_wrapper.c
13+
#''')
14+
15+
src = Glob('*.c')
16+
17+
CPPDEFINES = ['WASM_ENABLE_LIBC_BUILTIN=1']
18+
19+
CPPPATH = [cwd]
20+
21+
22+
group = DefineGroup('iwasm_libc_builtin', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
23+
24+
Return('group')

0 commit comments

Comments
 (0)