-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow compiling the wasm32-wasi
std library with atomics
#102372
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
There are a couple of things I could use help with in this PR:
$ /.../rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc kernel.rs --target wasm32-wasi --crate-type=cdylib -o kernel.wasm -C link-args="--shared-memory" -C target-feature='+atomics,+atomics' --sysroot /.../rust/build/x86_64-unknown-linux-gnu/stage1
...
error: linker `rust-lld` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error; 1 warning emitted |
UNIX uses an |
You'll need to set I've historically dabbled in getting (FWIW historical test runs turned up no actual failures, just a lot of infrastructural changes to get things working) |
If you're interested this is my historical work to get the test suite running with [target.wasm32-wasi]
runtool = 'wasmtime run --disable-cache --' in |
This is still a draft. Feel free to kick it back to me with at-rustbot ready once it's ready for review. @rustbot author |
As @alexcrichton notes above, the in-tree testing story still has some way to go, so I manually tested that this change works using the following sequence of steps:
$ git rev-parse HEAD
05b3b876e63cdc919c79f5127a7ae8dbdb7b095f
$ make THREAD_MODEL=posix
// first, enabled building the linker by setting `lld = true` in the [rust] section; then:
$ echo '[target.wasm32-wasi]' >> config.toml
$ echo 'wasi-root = "/.../wasi-libc/sysroot"' >> config.toml
$ RUSTFLAGS="-C target-feature=+atomics,+bulk-memory" ./x.py build library --target wasm32-wasi
$ rustup toolchain link stage1 build/x86_64-unknown-linux-gnu/stage1
$ rustc +stage1 kernel.rs -o kernel.wasm --target wasm32-wasi --crate-type=cdylib -C link-args="--shared-memory" -C target-feature='+atomics,+atomics'
$ wasm2wat --enable-threads kernel.wasm | grep '(memory'
(import "env" "memory" (memory (;0;) 17 16384 shared)) |
442e536
to
587e971
Compare
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Ok, I guess: @rustbot label +T-libs-api -T-libs |
Oh, never mind: @rustbot label -T-libs-api +T-libs |
Have you done a check for the places we might |
I think you mean I would say that compiling Rust with atomics and shared memory is still a highly risky venture and that this PR only fixes an issue that I am aware of. There will likely be others once people start experimenting with this. |
Uh, yeah, and just a grep for cfgs with wasm in them I guess (in case they were on
This is pretty concerning (assuming you mean that there are likely issues in |
Oh, it requires -Zbuild-std? Hm... |
Yeah, this PR just fixes compilation with features that are already exposed (even if experimentally behind |
Allow compiling the `wasm32-wasi` std library with atomics The issue rust-lang#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 rust-lang#102157.
Failed on rollup: #102908 (comment) |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (2a92176): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
The regressions are recent diesel noise, and unrelated to this PR and the wasi target. @rustbot label: +perf-regression-triaged |
Allow compiling the `wasm32-wasi` std library with atomics The issue rust-lang#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 rust-lang#102157.
The issue #102157 demonstrates how currently the
-Z build-std
option will fail when re-compiling the standard library withRUSTFLAGS
likeRUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"
. This change attempts to resolve those build issues by depending on the the WebAssemblyfutex
module and providing an implementation forenv_lock
. Fixes #102157.