Skip to content

wasm: Add support for WASI threads in CMake build system #71978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")

#
# User-configurable WebAssembly specific options.
#

option(SWIFT_ENABLE_WASI_THREADS
"Build the Standard Library with WASI threads support"
FALSE)

#
# User-configurable Darwin-specific options.
#
Expand Down
12 changes: 10 additions & 2 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ macro(configure_sdk_unix name architectures)
if("${prefix}" STREQUAL "LINUX")
set(_default_threading_package "linux")
elseif("${prefix}" STREQUAL "WASI")
set(_default_threading_package "none")
if(SWIFT_ENABLE_WASI_THREADS)
set(_default_threading_package "pthreads")
else()
set(_default_threading_package "none")
endif()
endif()
get_threading_package(${prefix} ${_default_threading_package}
SWIFT_SDK_${prefix}_THREADING_PACKAGE)
Expand Down Expand Up @@ -418,7 +422,11 @@ macro(configure_sdk_unix name architectures)
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
endif()
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SYSROOT_PATH}")
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
if(SWIFT_ENABLE_WASI_THREADS)
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi-threads")
Copy link
Contributor

@MaxDesiatov MaxDesiatov Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no other way to express this other than using the last triple component? Is this the triple that Clang uses for WASI threads as well? I find it confusing that we have wasm32-unknown-none-wasm with the last triple component denoting the object format, and wasm32-unknown-wasi-threads for denoting a platform feature. OTOH this is not much different from armv7-unknown-linux-musl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed how wasi-sdk and wasi-libc call the target: https://github.com/WebAssembly/wasi-sdk/blob/f1ebc52a74394cdf885d03bfde13899b3d5c6d2d/wasi-sdk-pthread.cmake#L9

Target triple parser is very complicated... The fourth component of triple can be interpreted as environment or object file format.
https://github.com/llvm/llvm-project/blob/a872a35251b833aaddec2172710ff234236afbd8/llvm/lib/TargetParser/Triple.cpp#L1071-L1076

else()
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
endif()
else()
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
endif()
Expand Down