Skip to content

Commit da638b3

Browse files
committed
Allow compiling the wasm32-wasi std library with atomics
The issue #102157 demonstrates how currently the `-Z build-std` option will fail when re-compiling the standard library with `RUSTFLAGS` like `RUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"`. This change attempts to resolve those build issues by depending on the the WebAssembly `futex` module and providing an implementation for `env_lock`. Fixes #102157.
1 parent 0265a3e commit da638b3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: library/std/src/sys/wasi/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub mod cmath;
2525
pub mod env;
2626
pub mod fd;
2727
pub mod fs;
28+
#[allow(unused)]
29+
#[path = "../wasm/atomics/futex.rs"]
30+
pub mod futex;
2831
pub mod io;
2932
#[path = "../unsupported/locks/mod.rs"]
3033
pub mod locks;

Diff for: library/std/src/sys/wasi/os.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ mod libc {
2424
}
2525
}
2626

27-
#[cfg(not(target_feature = "atomics"))]
2827
pub unsafe fn env_lock() -> impl Any {
29-
// No need for a lock if we're single-threaded, but this function will need
30-
// to get implemented for multi-threaded scenarios
28+
cfg_if::cfg_if! {
29+
if #[cfg(target_feature = "atomics")] {
30+
todo!()
31+
} else {
32+
// No need for a lock if we're single-threaded, but this function will need
33+
// to get implemented for multi-threaded scenarios
34+
}
35+
}
3136
}
3237

3338
pub fn errno() -> i32 {

0 commit comments

Comments
 (0)