Remove the requirement for nightly on wasmer-wasix
when the js
feature is activated
#4132
Labels
📦 lib-wasi
About wasmer-wasi
lib-wasix
Issues related to the WASIX toolchain.
priority-low
Low priority issue
Milestone
Describe the bug
As of #4119, compiling
wasmer-wasix
with thejs
feature requires a nightly compiler in order to do multi-processing correctly. This is a tracking issue for removing that requirement.Why is nightly required?
The
wasmer-wasix
crate implements multi-threading in the browser by spinning up some web workers and running Rust code (compiled to WebAssembly) on them to implement a basic thread pool. All workers share the sameSharedArrayBuffer
for their linear memory, which requires the WebAssembly threading proposal. From there, messages get sent to worker threads using atokio::sync::mpsc
channel, which usesCondvar
under the hood.The way you enable atomics in Rust is with the
-Ctarget-feature=+atomics,+bulk-memory
rustflags.Unfortunately,
std
comes pre-compiled forwasm32-unknown-unknown
(that's whatrustup target add ...
downloads), so even if you set$RUSTFLAGS
or put the flags in.cargo/config.toml
, things likeCondvar
will use the "unsupported" implementation which always panics.You can fix this by telling
cargo
to rebuild the standard library with the correct$RUSTFLAGS
. You can set this automatically by modifying your.cargo/config.toml
file:The
build-std
feature is unstable, and therefore only available on nightly.You can run
wasm-pack
tests on nightly using the followingSteps to reproduce
There are a couple ways you can reproduce this.
If you are running a web app that uses the
wasmer-wasix
crate under the hood, you may see an exception like this from one of the worker threads:This happens because creating a
wasmer_wasix::runtime::task_manager::WebTaskManager
requires setting up a thread pool, and the newly spawned web worker hit thatpanic!("condvar wait not supported")
when it started listening for events. The threadpool has no way of knowing this, so from aWebTaskManager
's perspective it's the task just looks like it takes forever to run.A simpler way to reproduce this is using
wasm-pack test
and these tests from thewasmer-wasix
crate:Those tests should fail with the following:
If you made the above changes to
.cargo/config.toml
and have a nightly compiler installed, tests usingWebTaskManager
will now pass if you runwasm-pack test
in a nightly environment.$ rustup run nightly wasm-pack test --chrome --features=wasmer/js,wasmer/std,js --no-default-features
Additional context
See the original conversation with me and @john-sharratt on Slack.
The text was updated successfully, but these errors were encountered: