-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
wasm: Add support for WASI threads in CMake build system #71978
Conversation
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.
@swift-ci smoke test |
@swift-ci test WebAssembly |
@@ -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") |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
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 with "-threads" environment field 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.I chose
wasm32-unknown-wasi-threads
by following wasi-sdk: https://github.com/WebAssembly/wasi-sdk/blob/f1ebc52a74394cdf885d03bfde13899b3d5c6d2d/wasi-sdk-pthread.cmake#L9