From cd551c3fc03b0ae83f31e68e7bd3468d5fc3838a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Jul 2026 10:07:40 -0700 Subject: [PATCH] std: Switch implementations of `thread_local!` for WASI This commit is a change for all WASI targets to use a different underlying implementation in the standard library for `thread_local!`. Previously all wasm targets, without the `atomics` feature, were funneled into the `no_threads` implementation and various fallbacks in the `thread_local` module. The upcoming `wasm32-wasip3` target, however, will actually have threads and will need different treatment. Additionally the modules that `wasm32-wasip3` needs all already work on all other WASI targets as well -- for example the `pthread_*` symbols needed to manage destructors are exposed by `wasi-libc`. The end result is that the `wasm32-wasip3` target will be "ready for threads" as soon as `wasi-libc` has support. Other targets shouldn't have any functional difference from before, too. --- library/std/src/sys/thread_local/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs index d48bb1c8b721e..cb954e475be1b 100644 --- a/library/std/src/sys/thread_local/mod.rs +++ b/library/std/src/sys/thread_local/mod.rs @@ -25,7 +25,7 @@ cfg_select! { any( - all(target_family = "wasm", not(target_feature = "atomics")), + all(target_family = "wasm", not(target_feature = "atomics"), not(target_os = "wasi")), target_os = "uefi", target_os = "zkvm", target_os = "trusty", @@ -54,7 +54,10 @@ cfg_select! { /// destructor for each variable. On these platforms, we keep track of the /// destructors ourselves and register (through the [`guard`] module) only a /// single callback that runs all of the destructors in the list. -#[cfg(all(target_thread_local, not(all(target_family = "wasm", not(target_feature = "atomics")))))] +#[cfg(all( + target_thread_local, + not(all(target_family = "wasm", not(target_feature = "atomics"), not(target_os = "wasi"))) +))] pub(crate) mod destructors { cfg_select! { any( @@ -93,9 +96,7 @@ pub(crate) mod guard { pub(crate) use windows::enable; } any( - all(target_family = "wasm", not( - all(target_os = "wasi", target_env = "p1", target_feature = "atomics") - )), + all(target_family = "wasm", not(target_os = "wasi")), target_os = "uefi", target_os = "zkvm", target_os = "trusty", @@ -150,7 +151,7 @@ pub(crate) mod key { ), all(not(target_thread_local), target_vendor = "apple"), target_os = "teeos", - all(target_os = "wasi", target_env = "p1", target_feature = "atomics"), + target_os = "wasi", ) => { mod racy; mod unix;