Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.wasm32-unknown-emscripten]
rustflags = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it seems like pyodide-build overrides these, so I will open an issue to talk to them and check for alternatives. In the meantime, this is helpful for reference and when we compile outside pyodide-build

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also is useful for rustworkx-core and using rustworkx without python in wasm.

"-C", "target-feature=+atomics,+bulk-memory,+mutable-globals",
"-C", "link-arg=-sSIDE_MODULE=2",
"-C", "link-arg=-sWASM_BIGINT",
"-Z", "emscripten-wasm-eh",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nightly option, is it needed, or do we only support building wasm on nightly rust? I was able to build with the latest stable if I exclude this option

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They use nightly for pyodide-build, see https://pyodide.org/en/stable/development/abi.html#id2

I think pyodide will be stuck with nightly for a while. That’s why I am so reticent to say we support it. I pinned the nightly version in the Pixi CL exactly for that reason

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I guess my concern here is that having this in the .cargo/config.toml with a -Z flag prevents us from building rustworkx-core against the emscripten target without pyodide. My preference would be to remove it from the default config and inject the flag when it's needed during a pyodide build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the PR. Pixi should always get those flags anyway, we use the pyodide-build CLI to retrieve the flags

]

[unstable]
build-std = ["std", "panic_abort"]
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ default-features = false
features = ["multi_thread"]

[profile.release]
lto = 'fat'
lto = "fat"
codegen-units = 1
16 changes: 16 additions & 0 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ source.
- i686 or x86_64
- :ref:`tier-4`
-
* - Pyodide
- WASM (Emscripten)
- :ref:`tier-experimental`
-


.. _manylinux 2014: https://peps.python.org/pep-0599/>
Expand Down Expand Up @@ -166,6 +170,18 @@ functioning Python environment and may require a C/C++ compiler or additional
programs to build dependencies from source as part of the installation process.
Support for these platforms are best effort only.

.. _tier-experimental:

Tier Experimental
-----------------

Tier Experimental platforms are not tested upstream as part of the development process.
Pre-compiled binaries are built by the external community in separate repositories. Not all of rustworkx might compile for
platforms of this tier and features can be removed. Often, platforms in this tier use unstable features
from the Rust compiler and might break at any time. Support for these platforms are best effort only.

Currently, the only platform in this tier is Pyodide, which is a port of Python that can run in the browser and on Node.js.

Using rustworkx
===============

Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/pyodide-support-2172f2313b06f10d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
`rustworkx` now has experimental support for `Pyodide <https://pyodide.org/en/stable/>`__.
Pyodide is a Python distribution for WebAssembly that runs in the browser.
This is the first release that compiles with Pyodide and will allow users to run `rustworkx`
in web applications. Because Pyodide wheels are not available in PyPI,
we are working with the Pyodide team to publish them in the Pyodide package index.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,5 +710,21 @@ fn rustworkx(py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
m.add_class::<Type>()?;
m.add_class::<KeySpec>()?;
m.add_wrapped(wrap_pymodule!(generators::generators))?;
#[cfg(target_os = "emscripten")]
setup_rayon_for_pyodide();
Ok(())
}

#[cfg(target_os = "emscripten")]
static PYODIDE_INIT: std::sync::Once = std::sync::Once::new();

#[cfg(target_os = "emscripten")]
pub fn setup_rayon_for_pyodide() {
PYODIDE_INIT.call_once(|| {
rayon::ThreadPoolBuilder::new()
.num_threads(1)
.use_current_thread()
.build_global()
.expect("failing setting up threads for pyodide");
});
}
Loading