Open
Description
What is the expected enhancement?
CPython 3.11 will add support for WASM. It would be nice for us to be able to run in WASM, as it would allow us to run in the browser along other Python libraries.
To accomplish that, we would need to build our library for the wasm32-unknown-emscripten
Rust target. Setting up Emscripten is the biggest challenge for this, but should be doable with cross
.
Activity
IvanIsCoding commentedon Oct 18, 2022
Also, if we compile to WASM we could use JupyterLite to build an interactive on-line tutorial that runs entirely on the browser and doesn't depend on Binder or external tools.
IvanIsCoding commentedon Oct 25, 2022
First challenge to take note:
rand_pcg::Pcg64
is not available in WASM, we will probably have to fallback toPcg32
in WASMjtpio commentedon Dec 10, 2023
That would be great!
One way to do this would be to try to get
rustworkx
on Emscripten Forge (like conda-forge but for emscripten) by adding a new recipe to the repo: https://github.com/emscripten-forge/recipesThe package would then be available for use with the Xeus Python kernel for JupyterLite: https://github.com/jupyterlite/xeus-python-kernel/
Otherwise for Pyodide support that would mean opening a new PR on the repo to add the package: https://github.com/pyodide/pyodide. And waiting for a new Pyodide release.
Either way it would indeed be nice to be able to try the library directly in the browser!
IvanIsCoding commentedon Dec 10, 2023
That is very interesting! I wans't aware of that. I remember someone created a conda-forge recipe for us: https://github.com/conda-forge/rustworkx-feedstock. So we could look into creating an emscript-forge recipe as well.
One of the biggest challenges though is that
wasm32-unknown-emscripten
is the first architecture that our code hasn't compiled to. So we will need to make surerustworkx-core
andrustworkx
work with it firstsorin-bolos commentedon Apr 29, 2025
I'm interested in having this feature and I'm available to put in the work
IvanIsCoding commentedon Apr 30, 2025
I was taking a look at https://github.com/sorin-bolos/rustworkx/pull/1/files, I think for
rand_pcg
using features to detect the platform is fine.But for
rayon
, really it should have a fallthrough. There's a discussion in rayon-rs/rayon#1155. If we need to patch each use ofrayon
inrustworkx
andrustworkx-core
the PR will become unmergeable. We need to make it default to single threaded by default somehow.IvanIsCoding commentedon Apr 30, 2025
Even exploring something among these lines seems more approachable: https://github.com/RReverser/wasm-bindgen-rayon?tab=readme-ov-file#building-rust-code
This is worth exploring as well: https://www.reddit.com/r/rust_gamedev/comments/1dvumtw/multithreaded_rust_in_the_browser_via_emscripten/?rdt=43533
rand
crate to 0.9 and bump related dependencies #1445IvanIsCoding commentedon May 9, 2025
Two things:
rand
crate to 0.9 and bump related dependencies #1445 takes care ofrand
thankfully, at leastrustworkx-core
compiles. I don't know aboutrustworkx
yet as I have not set up thepyodide
buildrayon
, feat: Polars build for Pyodide pola-rs/polars#20383 has a possible way forward. They compile theemscripten
build with a threadpool of just one thread. We could get away with itrustworkx
build and run with pyiodide #1447