-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for WASM targets #45
Conversation
At first glance, this looks reasonable to me. I'll try to do a full review on it in the next few days. The cfg conditionals are starting to get a bit hairy and I want to make sure things are 👌🏻 😅 |
Yeah, wasm being available on both web and wasi do not help here ... |
I cleaned up the code as suggested in the review, and added support to run the tests. running tests for wasm32-wasi# install wasmtime
curl https://wasmtime.dev/install.sh -sSf | bash
export CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime run"
cargo test --target wasm32-wasi running tests for wasm32-unknown-unknown# install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# run tests on firefox
wasm-pack test --firefox --headless
# run tests on chrome
wasm-pack test --chrome --headless
# run tests on node (require commenting out the configure_wasm_tests module in lib.rs)
# this currently fails with ReferenceError: Window is not defined due to
wasm-pack test --node |
@@ -155,6 +155,7 @@ mod tests { | |||
use std::time::Duration; | |||
|
|||
#[test] | |||
#[cfg_attr(target_arch = "wasm32", ignore)] // WASM is single threaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own curiosity: does std::thread::spawn
not work at all on WASM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least currently, yes. There are proposals to add threading to WASM, both in browsers and WASI, but they are still in early stage.
I've added some documentation on accuracy, let me know if there is a better way to do express these limitations |
@Luthaf Changes look good to me, just need to run |
@Luthaf Sorry for the delay here. Thanks again for your contribution! 🌮 |
thanks a lot for the release! |
This PR adds support for
Monotonic
on both WASM targets:wasm32-unknown-unknown
(web) andwasm32-wasi
(wasi). On the web, it uses window.performance.now(); and on wasi it uses clock_time_get with a monotonic clock.I did not ran the tests on these targets, but I'll try to do so in the next few days.