wasm32 support for twenty-first#265
Conversation
makes twenty-first "wasm-friendly" such that it builds when target_arch is wasm32. This enables twenty-first to be used inside a web-browser's web-assembly environment. Tests do not presently build for wasm32 target. Addressing that is more complicated and will be the focus of subsequent commits.
This adds the necessary Cargo.toml magic for `cargo test` to build tests correctly, both #[test] and #[proptest]. However the wasm test harness ignores #[test] and #[proptest] so tests are not actually run in that environment. The source files will need to be modified to make the tests visible to wasm test harness in a future commit.
annotates tests to indicate they should be compiled for wasm32 target by decorating with #[wasm_bindgen_test] when target_arch = wasm32.
It remains 32 on 64 bit systems. This avoids isize::MAX overflow for 32 bit systems and fixes a failing test case
The test uses assert_snapshot() which performs wasm32 disallowed operation(s)
9caacb6 to
d960e06
Compare
|
👀 Very interesting! Would be really cool if we could get our dependencies to all run on wasm-32. What I've seen looks good, with minimal changes/decorations to get this to work. I'll let others weigh in though, as devops is not my forté. |
jan-ferdinand
left a comment
There was a problem hiding this comment.
Thanks for taking this on. I've left a number of comments inline. Additionally:
- I can't
wasm-pack buildbecause apparently, “crate-type must be cdylib to compile towasm32-unknown-unknown”. The suggestion is to addcrate-type = ["cdylib", "rlib"]to the Cargo.toml's[lib]section. I don't know what the implications of this are. Do you? - Running
wasm-pack test --node(which works) results in one test failure, in particular,ntt_on_empty_input. Runningcargo t ntt_on_empty_inputresults in a pass. Seems like we need to do some debugging. - Before merging, I'd like to have a CI script that builds twenty-first for a wasm target and executes the full test suite successfully.
| proptest-arbitrary-interop = "0.1" | ||
| test-strategy = "0.4" | ||
| trybuild = "1.0" | ||
| proptest-arbitrary-interop = {git="https://github.com/dan-da/proptest-arbitrary-interop.git", version = "0.1", rev="d9fcf5b"} |
There was a problem hiding this comment.
Let's hope that your PR on the upstream crate gets merged, but I'm not holding my breath. In order to publish twenty-first on crates.io, we must not have git dependencies per their policy. There are two obvious ways forward, and maybe there are more:
- We (or you) publish your fork as a new crate to crates.io, twenty-first then depends on that crate.
- We copy the entire content of your fork into twenty-first and remove the dependency. (We should publicly expose this for downstream usage.)
I don't like either method too much. I think I slightly favor the latter approach. Perhaps you see a better option still?
There was a problem hiding this comment.
yeah, I don't really like either option. I just added a comment to that PR asking if its likely to be merged soon. If no reply by end of week, I suppose we should move forward with one of the two options.
well, I just learned:
Apparently adding Hopefully we can make this specific to the wasm32 build.
I observed same/similar. Though I was using However I also saw multiple test failures running
This is novel behavior and I concluded that perhaps there is some shared state happening between tests. But since it was happening on master I put it firmly in the "not my problem" box. If anything, the wasm32 tests behaved better under the wasm test harness, because only one of them failed when run with Regardless, my position is that:
I consider CI scripts to be outside scope of this PR. Anyway, it is not a skill I possess. I would suggest that could be done in a followup and should not block merging this PR. |
Adds wasm32 support. See included README files:
This PR is a series of commits. The very first commit only changes Cargo.toml and is sufficient to enable wasm32 support for
cargo buildmeaning that crates that depend on twenty-first can use it in their wasm32 builds. So it can be considered the "bare minimum" for wasm32 support.The remainder of the commits mainly tackle the challenge of getting our unit tests and especially proptests working in the wasm32 environment, which is substantially more complicated.
There are also a couple of commits that address failing test cases. One of these failing tests found a problem with twenty-first when executing in a 32-bit environment. This is addressed in 19a11a4, and should be carefully reviewed for correctness. This is the only change that was made to non-test library code in any of the commits, afaik.
This PR may be easiest to grok by:
note: the README files were generated by Gemini LLM, with coaching and minor edits. Also the LLM was very helpful for navigating through the complex issues getting the tests to build and execute.