Skip to content

Commit 82740fe

Browse files
wasm: Add support for WASI threads in CMake build system
This patch adds a new CMake option, `SWIFT_ENABLE_WASI_THREADS`, to enable building the Standard Library using WASI threads primitives (https://github.com/WebAssembly/wasi-threads). With this option, the Standard Library will be built for the new "wasm32-unknown-wasi-threads" target. We add the new triple because the WASI threads proposal requires extra syscalls and object files compiled to "wasm32-unknown-wasi" and "wasm32-unknown-wasi-threads" are not compatible and cannot be linked together.
1 parent 43cdee3 commit 82740fe

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
487487
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
488488
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
489489

490+
#
491+
# User-configurable WebAssembly specific options.
492+
#
493+
494+
option(SWIFT_ENABLE_WASI_THREADS
495+
"Build the Standard Library with WASI threads support"
496+
FALSE)
497+
490498
#
491499
# User-configurable Darwin-specific options.
492500
#

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ macro(configure_sdk_unix name architectures)
329329
if("${prefix}" STREQUAL "LINUX")
330330
set(_default_threading_package "linux")
331331
elseif("${prefix}" STREQUAL "WASI")
332-
set(_default_threading_package "none")
332+
if(SWIFT_ENABLE_WASI_THREADS)
333+
set(_default_threading_package "pthreads")
334+
else()
335+
set(_default_threading_package "none")
336+
endif()
333337
endif()
334338
get_threading_package(${prefix} ${_default_threading_package}
335339
SWIFT_SDK_${prefix}_THREADING_PACKAGE)
@@ -418,7 +422,11 @@ macro(configure_sdk_unix name architectures)
418422
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
419423
endif()
420424
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SYSROOT_PATH}")
421-
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
425+
if(SWIFT_ENABLE_WASI_THREADS)
426+
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi-threads")
427+
else()
428+
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
429+
endif()
422430
else()
423431
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
424432
endif()

0 commit comments

Comments
 (0)