@@ -36,6 +36,15 @@ if(WASI_SDK_DEBUG_PREFIX_MAP)
3636 -fdebug-prefix -map=${CMAKE_CURRENT_SOURCE_DIR} =wasisdk://v${wasi_sdk_version} )
3737endif ()
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.
4150set (default_cmake_args
@@ -70,6 +79,13 @@ endif()
7079
7180add_custom_target (compiler-rt-build )
7281function (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+ list (APPEND compiler_rt_flags ${wasi_sdk_exception_flags} )
87+ list (JOIN compiler_rt_flags " " compiler_rt_flags)
88+
7389 ExternalProject_Add(compiler-rt-build -${target}
7490 SOURCE_DIR "${llvm_proj_dir} /compiler-rt"
7591 CMAKE_ARGS
@@ -89,9 +105,9 @@ function(define_compiler_rt target)
89105 -DCOMPILER_RT_BUILD_ORC=OFF
90106 -DCOMPILER_RT_BUILD_GWP_ASAN=OFF
91107 -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 }
108+ -DCMAKE_C_FLAGS=${compiler_rt_flags }
109+ -DCMAKE_CXX_FLAGS=${compiler_rt_flags }
110+ -DCMAKE_ASM_FLAGS=${compiler_rt_flags }
95111 -DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
96112 EXCLUDE_FROM_ALL ON
97113 USES_TERMINAL_CONFIGURE ON
@@ -259,7 +275,7 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
259275 # a future endeavor.
260276 set (pic OFF )
261277 set (runtimes "libunwind;${runtimes} " )
262- list (APPEND extra_flags -fwasm-exceptions -mllvm -wasm-use-legacy-eh= false )
278+ list (APPEND extra_flags ${wasi_sdk_exception_flags} )
263279 endif ()
264280
265281 # The `wasm32-wasi` target is deprecated in clang, so ignore the deprecation
0 commit comments