Skip to content

Commit 6df6153

Browse files
committed
Enhance build configuration to support optional gc
There will be two sets of binaries for iwasm and wamrc. One set without a suffix indicates there is no GC support. Another set with the suffixes "-gc" and "-gc-eh" includes GC support. Users cannot disable GC through command line options; they need to choose the appropriate set to use.
1 parent 6c3f6fd commit 6df6153

File tree

11 files changed

+108
-104
lines changed

11 files changed

+108
-104
lines changed

.github/workflows/build_wamrc.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ permissions:
3737
jobs:
3838
build:
3939
runs-on: ${{ inputs.runner }}
40+
strategy:
41+
matrix:
42+
include:
43+
- build_options: ""
44+
suffix: ""
45+
- build_options: "-DWAMR_BUILD_GC=1"
46+
suffix: "-gc"
47+
4048
permissions:
4149
contents: write # for uploading release artifacts
4250

@@ -58,7 +66,7 @@ jobs:
5866

5967
- name: generate wamrc binary release
6068
run: |
61-
cmake -S . -B build
69+
cmake -S . -B build ${{ matrix.build_options }}
6270
cmake --build build --config Release --parallel 4
6371
working-directory: wamr-compiler
6472

@@ -89,17 +97,17 @@ jobs:
8997
- name: Compress the binary on Windows
9098
if: inputs.runner == 'windows-latest' && inputs.release
9199
run: |
92-
tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
93-
Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
94-
mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
100+
tar -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
101+
Compress-Archive -Path wamrc.exe -DestinationPath wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
102+
mv wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
95103
working-directory: wamr-compiler/build/Release
96104

97105
- name: compress the binary on non-Windows
98106
if: inputs.runner != 'windows-latest' && inputs.release
99107
run: |
100108
# Follow the symlink to the actual binary file
101-
tar --dereference -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
102-
zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
109+
tar --dereference -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
110+
zip wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
103111
working-directory: wamr-compiler/build
104112

105113
- name: upload release tar.gz
@@ -109,8 +117,8 @@ jobs:
109117
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110118
with:
111119
upload_url: ${{ inputs.upload_url }}
112-
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
113-
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
120+
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
121+
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
114122
asset_content_type: application/x-gzip
115123

116124
- name: upload release zip
@@ -120,6 +128,6 @@ jobs:
120128
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121129
with:
122130
upload_url: ${{ inputs.upload_url }}
123-
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
124-
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
131+
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
132+
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
125133
asset_content_type: application/zip

core/iwasm/compilation/aot_compiler.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,23 +3953,15 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
39533953
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
39543954
unsupport_ref_types:
39553955
aot_set_last_error("reference type instruction was found, "
3956-
"try removing --disable-ref-types option "
3957-
"or adding --enable-gc option");
3958-
return false;
3959-
#endif
3960-
3961-
#if WASM_ENABLE_GC != 0
3962-
unsupport_gc:
3963-
aot_set_last_error("GC instruction was found, "
3964-
"try adding --enable-gc option");
3956+
"try removing --disable-ref-types option ");
39653957
return false;
39663958
#endif
39673959

39683960
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
39693961
unsupport_gc_and_ref_types:
39703962
aot_set_last_error(
39713963
"reference type or gc instruction was found, try removing "
3972-
"--disable-ref-types option or adding --enable-gc option");
3964+
"--disable-ref-types option");
39733965
return false;
39743966
#endif
39753967

samples/multi-module/CMakeLists.txt

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ set(WAMR_BUILD_INTERP 1)
4646
if (NOT DEFINED WAMR_BUILD_AOT)
4747
set(WAMR_BUILD_AOT 0)
4848
endif ()
49+
4950
if (NOT DEFINED WAMR_BUILD_JIT)
5051
set(WAMR_BUILD_JIT 0)
5152
endif ()
5253
if (NOT DEFINED WAMR_BUILD_DUMP_CALL_STACK)
5354
set(WAMR_BUILD_DUMP_CALL_STACK 0)
5455
endif ()
55-
if (NOT DEFINED WAMR_BUILD_GC)
56-
set(WAMR_BUILD_GC 0)
57-
endif ()
56+
set(WAMR_BUILD_GC 0)
5857
set(WAMR_BUILD_SIMD 1)
5958
set(WAMR_BUILD_REF_TYPES 1)
6059
set(WAMR_BUILD_LIBC_BUILTIN 1)
@@ -160,45 +159,30 @@ ExternalProject_Add(WASM_MODULE
160159

161160
################ WASM MODULES TO AOT
162161
if (WAMR_BUILD_AOT EQUAL 1)
163-
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build)
164-
message(CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}")
165-
find_file(WAMR_COMPILER
166-
wamrc
167-
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build"
168-
NO_DEFAULT_PATH
169-
NO_CMAKE_FIND_ROOT_PATH
162+
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler)
163+
164+
ExternalProject_Add(wamrc_local
165+
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
166+
BUILD_ALWAYS TRUE
167+
UPDATE_COMMAND ""
168+
PATCH_COMMAND ""
169+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
170+
BUILD_COMMAND ${CMAKE_COMMAND} --build build
171+
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
170172
)
171-
if(WAMR_COMPILER)
172-
message(CHECK_PASS "found")
173-
else()
174-
message(CHECK_FAIL "not found")
175-
endif()
176-
if((NOT EXISTS ${WAMR_COMPILER}) )
177-
message(FATAL_ERROR "Please build wamrc under the path=${WAMR_ROOT_DIR}/wamr-compiler/ ")
178-
else()
179-
message(STATUS "WAMR_COMPILER is ${WAMR_COMPILER}")
180-
endif()
181173

182174
if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
183175
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-dump-call-stack")
184176
endif ()
185-
if (WAMR_BUILD_GC EQUAL 1)
186-
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-gc")
187-
endif ()
188177

189178
add_custom_target(
190179
wasm_to_aot
191180
ALL
192-
DEPENDS
193-
WASM_MODULE ${WAMR_COMPILER}
194-
COMMAND
195-
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
196-
COMMAND
197-
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
198-
COMMAND
199-
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
200-
WORKING_DIRECTORY
201-
${CMAKE_BINARY_DIR}
181+
DEPENDS WASM_MODULE wamrc_local
182+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
183+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
184+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
185+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
202186
)
203187
endif()
204188

samples/multi-module/README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
# WAMR MULTI-MODUEL SAMPLE
2-
**WAMR supports *multi-module* in both *interpreter* mode and *aot* mode.**
2+
3+
**WAMR supports _multi-module_ in both _interpreter_ mode and _aot_ mode.**
34

45
Multi-modules will determine the running mode based on the type of the main module.
56

7+
## Interpreter mode
68

7-
``` shell
8-
$ mkdir build
9+
```bash
10+
$ cmake -S . -B build
11+
$ cmake --build
912
$ cd build
10-
$ cmake ..
11-
$ make
12-
$ # It will build multi_module runtime and
13-
$ # wasm file under the ./build .
14-
$ # If you have built wamrc,
15-
$ # aot file will also generate.
1613
$ ./multi_module mC.wasm
17-
$ ...
18-
$ ./multi_module mC.aot
19-
$ ...
14+
```
15+
16+
## Aot mode
2017

18+
```bash
19+
$ cmake -S . -B build -DWAMR_BUILD_AOT=1
20+
$ cmake --build
21+
$ cd build
22+
$ ./multi_module mC.aot
23+
```

samples/wasm-c-api/CMakeLists.txt

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ if (NOT DEFINED WAMR_BUILD_TARGET)
5454
endif ()
5555
endif ()
5656

57+
# Only one of WAMR_BUILD_INTERP and WAMR_BUILD_AOT is enabled
5758
if(NOT DEFINED WAMR_BUILD_INTERP)
5859
set(WAMR_BUILD_INTERP 1)
5960
endif()
6061

6162
if(NOT DEFINED WAMR_BUILD_AOT)
6263
set(WAMR_BUILD_AOT 0)
64+
else()
65+
set(WAMR_BUILD_AOT 1)
66+
set(WAMR_BUILD_INTERP 0)
6367
endif()
6468

6569
if(NOT DEFINED WAMR_BUILD_JIT)
@@ -71,11 +75,7 @@ set(WAMR_BUILD_LIBC_WASI 0)
7175
set(WAMR_BUILD_MULTI_MODULE 1)
7276
set(WAMR_BUILD_DUMP_CALL_STACK 1)
7377
set(WAMR_BUILD_REF_TYPES 1)
74-
75-
# If not defined WAMR_BUILD_GC, set it to 0
76-
if(NOT DEFINED WAMRC_BUILD_WITH_GC)
77-
set(WAMRC_BUILD_WITH_GC 0)
78-
endif()
78+
set(WAMR_BUILD_GC 0)
7979

8080
if(NOT DEFINED WAMR_BUILD_FAST_INTERP)
8181
set(WAMR_BUILD_FAST_INTERP 1)
@@ -129,18 +129,17 @@ if (${WAT2WASM_VERSION} VERSION_LESS 1.0.26)
129129
set(WAT2WASM_FLAGS "--enable-reference-types")
130130
endif ()
131131

132-
if(${WAMR_BUILD_AOT} EQUAL 1 AND ${WAMR_BUILD_INTERP} EQUAL 0)
133-
## locate wamrc
134-
find_program(WAMRC
135-
wamrc
136-
PATHS ${WAMR_ROOT_DIR}/wamr-compiler/build/
132+
if(${WAMR_BUILD_AOT} EQUAL 1)
133+
include(ExternalProject)
134+
ExternalProject_Add(wamrc_local
135+
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
136+
BUILD_ALWAYS TRUE
137+
UPDATE_COMMAND ""
138+
PATCH_COMMAND ""
139+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
140+
BUILD_COMMAND ${CMAKE_COMMAND} --build build
141+
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
137142
)
138-
139-
if(NOT WAMRC)
140-
message(SEND_ERROR "can not find wamrc. refer to \
141-
https://github.com/bytecodealliance/wasm-micro-runtime#build-wamrc-aot-compiler"
142-
)
143-
endif()
144143
endif()
145144
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
146145

@@ -183,15 +182,11 @@ foreach(EX ${EXAMPLES})
183182

184183
# generate .aot file
185184
if(${WAMR_BUILD_AOT} EQUAL 1)
186-
if(${WAMRC_BUILD_WITH_GC} EQUAL 1)
187-
set(WAMRC_GC_FLAGS "--enable-gc")
188-
else()
189-
set(WAMRC_GC_FLAGS "")
190-
endif()
185+
191186
add_custom_target(${EX}_AOT
192-
COMMAND ${WAMRC} ${WAMRC_GC_FLAGS} -o ${PROJECT_BINARY_DIR}/${EX}.aot
187+
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc -o ${PROJECT_BINARY_DIR}/${EX}.aot
193188
${PROJECT_BINARY_DIR}/${EX}.wasm
194-
DEPENDS ${EX}_WASM
189+
DEPENDS ${EX}_WASM wamrc_local
195190
BYPRODUCTS ${PROJECT_BINARY_DIR}/${EX}.aot
196191
VERBATIM
197192
COMMENT "generate a aot file ${PROJECT_BINARY_DIR}/${EX}.aot"

tests/requirement-engineering/gc-aot/runtest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output='de
11621162
cmd.append("--enable-multi-thread")
11631163

11641164
if opts.gc:
1165-
cmd.append("--enable-gc")
11661165
cmd.append("--enable-tail-call")
11671166

11681167
if output == 'object':

tests/unit/aot-stack-frame/wasm-apps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14)
55

66
project(wasm-apps-aot-stack-frame)
77

8-
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1 --enable-gc)
8+
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1)
99

1010
if (WAMR_BUILD_TARGET STREQUAL "X86_32")
1111
set (WAMRC_OPTION ${WAMRC_OPTION} --target=i386)

tests/wamr-test-suites/spec-test-script/runtest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
11571157
cmd.append("--enable-multi-thread")
11581158

11591159
if opts.gc:
1160-
cmd.append("--enable-gc")
11611160
cmd.append("--enable-tail-call")
11621161

11631162
if opts.extended_const:

tests/wamr-test-suites/test_wamr.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ function build_iwasm_with_cfg()
835835
fi
836836
}
837837

838-
function build_wamrc()
838+
function build_wamrc_with_cfg()
839839
{
840840
if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then
841841
echo "suppose wamrc is already built"
@@ -852,10 +852,7 @@ function build_wamrc()
852852
&& ./${BUILD_LLVM_SH} \
853853
&& if [ -d build ]; then rm -r build/*; else mkdir build; fi \
854854
&& cd build \
855-
&& cmake .. \
856-
-DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
857-
-DWAMR_BUILD_SHRUNK_MEMORY=0 \
858-
-DWAMR_BUILD_EXTENDED_CONST_EXPR=${ENABLE_EXTENDED_CONST_EXPR} \
855+
&& cmake $* .. \
859856
&& make -j 4
860857
}
861858

@@ -1073,6 +1070,18 @@ function trigger()
10731070
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=$WAMR_BUILD_SANITIZER"
10741071
fi
10751072

1073+
local WAMRC_BUILD_FLAGS=""
1074+
WAMRC_BUILD_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
1075+
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0"
1076+
1077+
if [[ ${ENABLE_GC} == 1 ]]; then
1078+
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_GC=1"
1079+
fi
1080+
1081+
if [[ ${ENABLE_EXTENDED_CONST_EXPR} == 1 ]]; then
1082+
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_EXTENDED_CONST_EXPR=1"
1083+
fi
1084+
10761085
# Make sure we're using the builtin WASI libc implementation
10771086
# if we're running the wasi certification tests.
10781087
if [[ $TEST_CASE_ARR ]]; then
@@ -1148,7 +1157,7 @@ function trigger()
11481157
build_iwasm_with_cfg $BUILD_FLAGS
11491158
fi
11501159
if [ -z "${WAMRC_CMD}" ]; then
1151-
build_wamrc
1160+
build_wamrc_with_cfg $WAMRC_BUILD_FLAGS
11521161
WAMRC_CMD=${WAMRC_CMD_DEFAULT}
11531162
fi
11541163
for suite in "${TEST_CASE_ARR[@]}"; do

wamr-compiler/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1)
5555
add_definitions(-DWASM_ENABLE_MEMORY64=1)
5656
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
5757

58-
add_definitions(-DWASM_ENABLE_GC=1)
58+
# Sync with iwasm in config_common.cmake. Turn off GC by default.
59+
# can be turned on by setting WAMR_BUILD_GC to 1
60+
if (NOT DEFINED WAMR_BUILD_GC)
61+
message ("-- GC disabled")
62+
set(WAMR_BUILD_GC 0)
63+
add_definitions(-DWASM_ENABLE_GC=0)
64+
else ()
65+
message ("-- GC enabled")
66+
set(WAMR_BUILD_GC 1)
67+
add_definitions(-DWASM_ENABLE_GC=1)
68+
endif ()
5969

6070
set (WAMR_BUILD_STRINGREF 1)
6171
set (WAMR_STRINGREF_IMPL_SOURCE "STUB")
@@ -285,7 +295,11 @@ include (${SHARED_DIR}/utils/shared_utils.cmake)
285295
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
286296
include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
287297
include (${IWASM_DIR}/common/iwasm_common.cmake)
288-
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
298+
if (WAMR_BUILD_GC EQUAL 1)
299+
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
300+
else ()
301+
message (STATUS "WAMR GC is disabled")
302+
endif ()
289303
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
290304
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
291305
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)

0 commit comments

Comments
 (0)