Skip to content

Commit 32e856a

Browse files
committed
Build compiler_rt with exception tag definition
necesary at runtime when wasm eh is enabled
1 parent 4d474b1 commit 32e856a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cmake/wasi-sdk-sysroot.cmake

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ if(WASI_SDK_DEBUG_PREFIX_MAP)
3636
-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=wasisdk://v${wasi_sdk_version})
3737
endif()
3838

39+
set(wasi_sdk_exception_flags)
40+
if(WASI_SDK_EXCEPTIONS)
41+
# Flags required to enable standard WASM exception handling.
42+
list(APPEND wasi_sdk_exception_flags
43+
-fwasm-exceptions
44+
-mllvm
45+
-wasm-use-legacy-eh=false)
46+
endif()
47+
3948
# Default arguments for builds of cmake projects (mostly LLVM-based) to forward
4049
# along much of our own configuration into these projects.
4150
set(default_cmake_args
@@ -70,6 +79,14 @@ endif()
7079

7180
add_custom_target(compiler-rt-build)
7281
function(define_compiler_rt target)
82+
set(compiler_rt_flags ${WASI_SDK_CPU_CFLAGS})
83+
84+
# Build compiler_rt with the exception tag definition
85+
# necessary at runtime when exceptions are enabled
86+
if(WASI_SDK_EXCEPTIONS)
87+
list(APPEND compiler_rt_flags ${wasi_sdk_exception_flags})
88+
list(JOIN compiler_rt_flags " " compiler_rt_flags)
89+
7390
ExternalProject_Add(compiler-rt-build-${target}
7491
SOURCE_DIR "${llvm_proj_dir}/compiler-rt"
7592
CMAKE_ARGS
@@ -89,9 +106,9 @@ function(define_compiler_rt target)
89106
-DCOMPILER_RT_BUILD_ORC=OFF
90107
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
91108
-DCMAKE_C_COMPILER_TARGET=${target}
92-
-DCMAKE_C_FLAGS=${WASI_SDK_CPU_CFLAGS}
93-
-DCMAKE_CXX_FLAGS=${WASI_SDK_CPU_CFLAGS}
94-
-DCMAKE_ASM_FLAGS=${WASI_SDK_CPU_CFLAGS}
109+
-DCMAKE_C_FLAGS=${compiler_rt_flags}
110+
-DCMAKE_CXX_FLAGS=${compiler_rt_flags}
111+
-DCMAKE_ASM_FLAGS=${compiler_rt_flags}
95112
-DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
96113
EXCLUDE_FROM_ALL ON
97114
USES_TERMINAL_CONFIGURE ON
@@ -259,7 +276,7 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
259276
# a future endeavor.
260277
set(pic OFF)
261278
set(runtimes "libunwind;${runtimes}")
262-
list(APPEND extra_flags -fwasm-exceptions -mllvm -wasm-use-legacy-eh=false)
279+
list(APPEND extra_flags ${wasi_sdk_exception_flags})
263280
endif()
264281

265282
# The `wasm32-wasi` target is deprecated in clang, so ignore the deprecation

0 commit comments

Comments
 (0)