Compare commits

...

2 Commits

Author SHA1 Message Date
liang.he
dd4e361af9
Merge 797a442ed1 into 6c3f6fd017 2025-08-31 16:34:46 +08:00
liang.he@intel.com
797a442ed1 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.
2025-08-31 08:33:04 +00:00
12 changed files with 106 additions and 113 deletions

View File

@ -37,6 +37,14 @@ permissions:
jobs:
build:
runs-on: ${{ inputs.runner }}
strategy:
matrix:
include:
- build_options: ""
suffix: ""
- build_options: "-DWAMR_BUILD_GC=1"
suffix: "-gc"
permissions:
contents: write # for uploading release artifacts
@ -58,7 +66,7 @@ jobs:
- name: generate wamrc binary release
run: |
cmake -S . -B build
cmake -S . -B build ${{ matrix.build_options }}
cmake --build build --config Release --parallel 4
working-directory: wamr-compiler
@ -89,17 +97,17 @@ jobs:
- name: Compress the binary on Windows
if: inputs.runner == 'windows-latest' && inputs.release
run: |
tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
tar -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
Compress-Archive -Path wamrc.exe -DestinationPath wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
working-directory: wamr-compiler/build/Release
- name: compress the binary on non-Windows
if: inputs.runner != 'windows-latest' && inputs.release
run: |
# Follow the symlink to the actual binary file
tar --dereference -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
tar --dereference -czf wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
zip wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
working-directory: wamr-compiler/build
- name: upload release tar.gz
@ -109,8 +117,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_content_type: application/x-gzip
- name: upload release zip
@ -120,6 +128,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-compiler/build/wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: wamrc-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_path: wamr-compiler/build/wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: wamrc${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_content_type: application/zip

View File

@ -417,7 +417,6 @@ jobs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2204,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
@ -464,14 +463,6 @@ jobs:
with:
os: ${{ matrix.os }}
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- name: Build Sample [wasm-c-api]
run: |
VERBOSE=1

View File

@ -3953,15 +3953,7 @@ unsupport_simd:
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
unsupport_ref_types:
aot_set_last_error("reference type instruction was found, "
"try removing --disable-ref-types option "
"or adding --enable-gc option");
return false;
#endif
#if WASM_ENABLE_GC != 0
unsupport_gc:
aot_set_last_error("GC instruction was found, "
"try adding --enable-gc option");
"try removing --disable-ref-types option ");
return false;
#endif
@ -3969,7 +3961,7 @@ unsupport_gc:
unsupport_gc_and_ref_types:
aot_set_last_error(
"reference type or gc instruction was found, try removing "
"--disable-ref-types option or adding --enable-gc option");
"--disable-ref-types option");
return false;
#endif

View File

@ -46,15 +46,14 @@ set(WAMR_BUILD_INTERP 1)
if (NOT DEFINED WAMR_BUILD_AOT)
set(WAMR_BUILD_AOT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_JIT)
set(WAMR_BUILD_JIT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_DUMP_CALL_STACK)
set(WAMR_BUILD_DUMP_CALL_STACK 0)
endif ()
if (NOT DEFINED WAMR_BUILD_GC)
set(WAMR_BUILD_GC 0)
endif ()
set(WAMR_BUILD_GC 0)
set(WAMR_BUILD_SIMD 1)
set(WAMR_BUILD_REF_TYPES 1)
set(WAMR_BUILD_LIBC_BUILTIN 1)
@ -160,45 +159,30 @@ ExternalProject_Add(WASM_MODULE
################ WASM MODULES TO AOT
if (WAMR_BUILD_AOT EQUAL 1)
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build)
message(CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}")
find_file(WAMR_COMPILER
wamrc
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler)
ExternalProject_Add(wamrc_local
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
)
if(WAMR_COMPILER)
message(CHECK_PASS "found")
else()
message(CHECK_FAIL "not found")
endif()
if((NOT EXISTS ${WAMR_COMPILER}) )
message(FATAL_ERROR "Please build wamrc under the path=${WAMR_ROOT_DIR}/wamr-compiler/ ")
else()
message(STATUS "WAMR_COMPILER is ${WAMR_COMPILER}")
endif()
if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-dump-call-stack")
endif ()
if (WAMR_BUILD_GC EQUAL 1)
list(APPEND WAMR_AOT_COMPILE_OPTIONS "--enable-gc")
endif ()
add_custom_target(
wasm_to_aot
ALL
DEPENDS
WASM_MODULE ${WAMR_COMPILER}
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
COMMAND
${WAMR_COMPILER} ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
DEPENDS WASM_MODULE wamrc_local
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mA.aot ./mA.wasm
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mB.aot ./mB.wasm
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc ${WAMR_AOT_COMPILE_OPTIONS} -o mC.aot ./mC.wasm
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

View File

@ -1,20 +1,23 @@
# WAMR MULTI-MODUEL SAMPLE
**WAMR supports *multi-module* in both *interpreter* mode and *aot* mode.**
**WAMR supports _multi-module_ in both _interpreter_ mode and _aot_ mode.**
Multi-modules will determine the running mode based on the type of the main module.
## Interpreter mode
``` shell
$ mkdir build
```bash
$ cmake -S . -B build
$ cmake --build
$ cd build
$ cmake ..
$ make
$ # It will build multi_module runtime and
$ # wasm file under the ./build .
$ # If you have built wamrc,
$ # aot file will also generate.
$ ./multi_module mC.wasm
$ ...
$ ./multi_module mC.aot
$ ...
```
## Aot mode
```bash
$ cmake -S . -B build -DWAMR_BUILD_AOT=1
$ cmake --build
$ cd build
$ ./multi_module mC.aot
```

View File

@ -62,6 +62,9 @@ if(NOT DEFINED WAMR_BUILD_AOT)
set(WAMR_BUILD_AOT 0)
endif()
include(CMakePrintHelpers)
cmake_print_variables(WAMR_BUILD_INTERP WAMR_BUILD_AOT)
if(NOT DEFINED WAMR_BUILD_JIT)
set(WAMR_BUILD_JIT 0)
endif()
@ -71,11 +74,7 @@ set(WAMR_BUILD_LIBC_WASI 0)
set(WAMR_BUILD_MULTI_MODULE 1)
set(WAMR_BUILD_DUMP_CALL_STACK 1)
set(WAMR_BUILD_REF_TYPES 1)
# If not defined WAMR_BUILD_GC, set it to 0
if(NOT DEFINED WAMRC_BUILD_WITH_GC)
set(WAMRC_BUILD_WITH_GC 0)
endif()
set(WAMR_BUILD_GC 0)
if(NOT DEFINED WAMR_BUILD_FAST_INTERP)
set(WAMR_BUILD_FAST_INTERP 1)
@ -130,17 +129,16 @@ if (${WAT2WASM_VERSION} VERSION_LESS 1.0.26)
endif ()
if(${WAMR_BUILD_AOT} EQUAL 1 AND ${WAMR_BUILD_INTERP} EQUAL 0)
## locate wamrc
find_program(WAMRC
wamrc
PATHS ${WAMR_ROOT_DIR}/wamr-compiler/build/
include(ExternalProject)
ExternalProject_Add(wamrc_local
SOURCE_DIR ${WAMR_ROOT_DIR}/wamr-compiler
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${WAMR_ROOT_DIR}/wamr-compiler -B build --install-prefix ${CMAKE_CURRENT_BINARY_DIR}
BUILD_COMMAND ${CMAKE_COMMAND} --build build
INSTALL_COMMAND ${CMAKE_COMMAND} --install build
)
if(NOT WAMRC)
message(SEND_ERROR "can not find wamrc. refer to \
https://github.com/bytecodealliance/wasm-micro-runtime#build-wamrc-aot-compiler"
)
endif()
endif()
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
@ -182,16 +180,11 @@ foreach(EX ${EXAMPLES})
add_dependencies(${EX} ${EX}_WASM)
# generate .aot file
if(${WAMR_BUILD_AOT} EQUAL 1)
if(${WAMRC_BUILD_WITH_GC} EQUAL 1)
set(WAMRC_GC_FLAGS "--enable-gc")
else()
set(WAMRC_GC_FLAGS "")
endif()
if(${WAMR_BUILD_AOT} EQUAL 1 AND ${WAMR_BUILD_INTERP} EQUAL 0)
add_custom_target(${EX}_AOT
COMMAND ${WAMRC} ${WAMRC_GC_FLAGS} -o ${PROJECT_BINARY_DIR}/${EX}.aot
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bin/wamrc -o ${PROJECT_BINARY_DIR}/${EX}.aot
${PROJECT_BINARY_DIR}/${EX}.wasm
DEPENDS ${EX}_WASM
DEPENDS ${EX}_WASM wamrc_local
BYPRODUCTS ${PROJECT_BINARY_DIR}/${EX}.aot
VERBATIM
COMMENT "generate a aot file ${PROJECT_BINARY_DIR}/${EX}.aot"

View File

@ -1162,7 +1162,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output='de
cmd.append("--enable-multi-thread")
if opts.gc:
cmd.append("--enable-gc")
cmd.append("--enable-tail-call")
if output == 'object':

View File

@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14)
project(wasm-apps-aot-stack-frame)
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1 --enable-gc)
set (WAMRC_OPTION --enable-dump-call-stack --bounds-checks=1)
if (WAMR_BUILD_TARGET STREQUAL "X86_32")
set (WAMRC_OPTION ${WAMRC_OPTION} --target=i386)

View File

@ -1157,7 +1157,6 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
cmd.append("--enable-multi-thread")
if opts.gc:
cmd.append("--enable-gc")
cmd.append("--enable-tail-call")
if opts.extended_const:

View File

@ -835,7 +835,7 @@ function build_iwasm_with_cfg()
fi
}
function build_wamrc()
function build_wamrc_with_cfg()
{
if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then
echo "suppose wamrc is already built"
@ -852,10 +852,7 @@ function build_wamrc()
&& ./${BUILD_LLVM_SH} \
&& if [ -d build ]; then rm -r build/*; else mkdir build; fi \
&& cd build \
&& cmake .. \
-DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
-DWAMR_BUILD_SHRUNK_MEMORY=0 \
-DWAMR_BUILD_EXTENDED_CONST_EXPR=${ENABLE_EXTENDED_CONST_EXPR} \
&& cmake $* .. \
&& make -j 4
}
@ -1073,6 +1070,18 @@ function trigger()
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=$WAMR_BUILD_SANITIZER"
fi
local WAMRC_BUILD_FLAGS=""
WAMRC_BUILD_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0"
if [[ ${ENABLE_GC} == 1 ]]; then
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_GC=1"
fi
if [[ ${ENABLE_EXTENDED_CONST_EXPR} == 1 ]]; then
WAMRC_BUILD_FLAGS+=" -DWAMR_BUILD_EXTENDED_CONST_EXPR=1"
fi
# Make sure we're using the builtin WASI libc implementation
# if we're running the wasi certification tests.
if [[ $TEST_CASE_ARR ]]; then
@ -1148,7 +1157,7 @@ function trigger()
build_iwasm_with_cfg $BUILD_FLAGS
fi
if [ -z "${WAMRC_CMD}" ]; then
build_wamrc
build_wamrc_with_cfg $WAMRC_BUILD_FLAGS
WAMRC_CMD=${WAMRC_CMD_DEFAULT}
fi
for suite in "${TEST_CASE_ARR[@]}"; do

View File

@ -55,7 +55,17 @@ add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1)
add_definitions(-DWASM_ENABLE_MEMORY64=1)
add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=1)
add_definitions(-DWASM_ENABLE_GC=1)
# Sync with iwasm in config_common.cmake. Turn off GC by default.
# can be turned on by setting WAMR_BUILD_GC to 1
if (NOT DEFINED WAMR_BUILD_GC)
message ("-- GC disabled")
set(WAMR_BUILD_GC 0)
add_definitions(-DWASM_ENABLE_GC=0)
else ()
message ("-- GC enabled")
set(WAMR_BUILD_GC 1)
add_definitions(-DWASM_ENABLE_GC=1)
endif ()
set (WAMR_BUILD_STRINGREF 1)
set (WAMR_STRINGREF_IMPL_SOURCE "STUB")
@ -285,7 +295,11 @@ include (${SHARED_DIR}/utils/shared_utils.cmake)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
include (${IWASM_DIR}/common/iwasm_common.cmake)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
if (WAMR_BUILD_GC EQUAL 1)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
else ()
message (STATUS "WAMR GC is disabled")
endif ()
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)

View File

@ -179,7 +179,6 @@ print_help()
printf(" --enable-memory-profiling Enable memory usage profiling\n");
printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n");
printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n");
printf(" --enable-gc Enable GC (Garbage Collection) feature\n");
printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n");
printf(" --enable-builtin-intrinsics=<flags>\n");
printf(" Enable the specified built-in intrinsics, it will override the default\n");
@ -424,7 +423,13 @@ main(int argc, char *argv[])
option.enable_aux_stack_check = true;
option.enable_bulk_memory = true;
option.enable_ref_types = true;
#if WASM_ENABLE_GC != 0
/* gc depends on AOT_STACK_FRAME */
option.enable_gc = true;
option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
#else
option.enable_gc = false;
#endif
option.enable_extended_const = false;
aot_call_stack_features_init_default(&option.call_stack_features);
@ -573,10 +578,6 @@ main(int argc, char *argv[])
else if (!strcmp(argv[0], "--enable-indirect-mode")) {
option.is_indirect_mode = true;
}
else if (!strcmp(argv[0], "--enable-gc")) {
option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD;
option.enable_gc = true;
}
else if (!strcmp(argv[0], "--disable-llvm-intrinsics")) {
option.disable_llvm_intrinsics = true;
}