Skip to content

Commit fbdec30

Browse files
authored
Add an option to specify CFLAGS for wasm features and make lime1 the default (#527)
Add a cmake option WASI_SDK_CPU_CFLAGS to specify CFLAGS to control wasm features to enable/disable. Make the default `-mcpu=lime1`. Comparing to the default "generic" target of the recent llvm, this effectively * disables reference-types and bulk-memory (enable their partial counterparts instead) * enables extended-const Note: as of writing this, a few popular runtimes, including wasm3 and wasm-micro-runtime, don't support extented-const yet. Note: regardless of this, wasi-libc enables necessary features for certain files. (bulk-memory and exception-handling) cf. #525 References: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md bytecodealliance/wasm-micro-runtime#4272
1 parent dadbd94 commit fbdec30

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ jobs:
169169
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang \
170170
-DCMAKE_SYSTEM_NAME=WASI \
171171
-DWASI_SDK_INCLUDE_TESTS=ON \
172+
-DWASI_SDK_CPU_CFLAGS="" \
172173
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=OFF \
173174
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=OFF
174175
- run: ninja -C build

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ in compiling WebAssembly code. Supported CMake flags are:
8585
* `-DWASI_SDK_DEBUG_PREFIX_MAKE=OFF` - disable `-fdebug-prefix-map` when
8686
building C/C++ code to use full host paths instead.
8787
* `-DWASI_SDK_INCLUDE_TESTS=ON` - used for building tests.
88+
* `-DWASI_SDK_CPU_CFLAGS=..` - used to specify CFLAGS to tweak wasm features
89+
to enable/disable. The default is `-mcpu=lime1`.
8890
* `-DWASI_SDK_TEST_HOST_TOOLCHAIN=ON` - test the host toolchain's wasi-libc and
8991
sysroot libraries, don't build or use fresh libraries for tests.
9092
* `-DWASI_SDK_TARGETS=..` - a list of targets to build, by default all WASI

cmake/wasi-sdk-sysroot.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ option(WASI_SDK_DEBUG_PREFIX_MAP "Pass `-fdebug-prefix-map` for built artifacts"
2424
option(WASI_SDK_INCLUDE_TESTS "Whether or not to build tests by default" OFF)
2525
option(WASI_SDK_INSTALL_TO_CLANG_RESOURCE_DIR "Whether or not to modify the compiler's resource directory" OFF)
2626
option(WASI_SDK_LTO "Whether or not to build LTO assets" ON)
27+
set(WASI_SDK_CPU_CFLAGS "-mcpu=lime1" CACHE STRING "CFLAGS to specify wasm features to enable")
2728

2829
set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install)
2930
set(wasi_sysroot ${wasi_tmp_install}/share/wasi-sysroot)
@@ -87,6 +88,7 @@ function(define_compiler_rt target)
8788
-DCOMPILER_RT_BUILD_ORC=OFF
8889
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
8990
-DCMAKE_C_COMPILER_TARGET=${target}
91+
-DCMAKE_C_FLAGS=${WASI_SDK_CPU_CFLAGS}
9092
-DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
9193
EXCLUDE_FROM_ALL ON
9294
USES_TERMINAL_CONFIGURE ON
@@ -161,7 +163,7 @@ function(define_wasi_libc_sub target target_suffix lto)
161163
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
162164
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir})
163165
set(extra_cflags_list
164-
"${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
166+
"${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
165167
list(JOIN extra_cflags_list " " extra_cflags)
166168

167169
if(${target} MATCHES threads)
@@ -238,6 +240,7 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
238240
get_property(dir_compile_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
239241
get_property(dir_link_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_OPTIONS)
240242
set(extra_flags
243+
${WASI_SDK_CPU_CFLAGS}
241244
${target_flags}
242245
--target=${target}
243246
${dir_compile_opts}

0 commit comments

Comments
 (0)