From b5ddfd5be429fbfaab1c71ae8d0b87ce55506c72 Mon Sep 17 00:00:00 2001 From: Sebastian Urban Date: Mon, 9 Mar 2026 08:50:09 +0100 Subject: [PATCH] Fix thread::available_parallelism on WASI targets The refactoring in ba462864f11 ("std: Use more unix.rs code on WASI targets") moved WASI from its own thread module into the shared unix.rs module. However, it did not carry over the available_parallelism() implementation for WASI, causing it to fall through to the unsupported catch-all. This silently regressed the support originally added in f0b7008648d. Fix this by adding WASI to the sysconf-based cfg_select arm alongside other platforms that use libc::sysconf(_SC_NPROCESSORS_ONLN). This delegates to wasi-libc, which currently always returns 1 but opens up the possibility for wasi-libc to report actual processor counts in the future. This requires libc to export _SC_NPROCESSORS_ONLN for WASI targets, which has been added in libc 0.2.184. --- library/std/src/sys/thread/unix.rs | 1 + library/std/tests/thread.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/thread/unix.rs b/library/std/src/sys/thread/unix.rs index 2f3ef1741cdfc..81ef39581d74d 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -155,6 +155,7 @@ pub fn available_parallelism() -> io::Result> { target_os = "aix", target_vendor = "apple", target_os = "cygwin", + target_os = "wasi", ) => { #[allow(unused_assignments)] #[allow(unused_mut)] diff --git a/library/std/tests/thread.rs b/library/std/tests/thread.rs index dc8eadd75148b..ef13ce44d3180 100644 --- a/library/std/tests/thread.rs +++ b/library/std/tests/thread.rs @@ -85,7 +85,6 @@ fn thread_local_hygeiene() { target_env = "sgx", target_os = "solid_asp3", target_os = "teeos", - target_os = "wasi" ), should_panic )]