Skip to content

Commit 52188ef

Browse files
committed
Add an option to specify CFLAGS for wasm features and make lime1 the default
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 8db0c61 commit 52188ef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ jobs:
166166
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang \
167167
-DCMAKE_SYSTEM_NAME=WASI \
168168
-DWASI_SDK_INCLUDE_TESTS=ON \
169+
-DWASI_SDK_CPU_CFLAGS="" \
169170
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=OFF \
170171
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=OFF
171172
- run: ninja -C build

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)
@@ -84,6 +85,7 @@ ExternalProject_Add(compiler-rt-build
8485
-DCOMPILER_RT_BUILD_ORC=OFF
8586
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
8687
-DCMAKE_C_COMPILER_TARGET=wasm32-wasi
88+
-DCMAKE_C_FLAGS=${WASI_SDK_CPU_CFLAGS}
8789
-DCOMPILER_RT_OS_DIR=wasi
8890
-DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
8991
EXCLUDE_FROM_ALL ON
@@ -151,7 +153,7 @@ function(define_wasi_libc_sub target target_suffix lto)
151153
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
152154
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir})
153155
set(extra_cflags_list
154-
"${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
156+
"${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
155157
list(JOIN extra_cflags_list " " extra_cflags)
156158

157159
ExternalProject_Add(wasi-libc-${target}${target_suffix}-build
@@ -223,6 +225,7 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
223225
get_property(dir_compile_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
224226
get_property(dir_link_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_OPTIONS)
225227
set(extra_flags
228+
${WASI_SDK_CPU_CFLAGS}
226229
${target_flags}
227230
--target=${target}
228231
${dir_compile_opts}

0 commit comments

Comments
 (0)