diff --git a/.cargo/config.toml b/.cargo/config.toml index d47f983e47..595ea43d69 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,3 +9,6 @@ rustflags = [ "-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup", ] + +[unstable] +build-std = ["std", "panic_abort"] diff --git a/Cargo.toml b/Cargo.toml index 2b2c09c0b0..fb7d64731c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,5 +75,5 @@ default-features = false features = ["multi_thread"] [profile.release] -lto = 'fat' +lto = "fat" codegen-units = 1 diff --git a/docs/source/install.rst b/docs/source/install.rst index 86698df1b6..071f25e347 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -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/> @@ -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 =============== diff --git a/releasenotes/notes/pyodide-support-2172f2313b06f10d.yaml b/releasenotes/notes/pyodide-support-2172f2313b06f10d.yaml new file mode 100644 index 0000000000..543443cb81 --- /dev/null +++ b/releasenotes/notes/pyodide-support-2172f2313b06f10d.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + `rustworkx` now has experimental support for `Pyodide `__. + 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. diff --git a/src/lib.rs b/src/lib.rs index 8da3e7f18f..1b352d28f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -710,5 +710,21 @@ fn rustworkx(py: Python<'_>, m: &Bound) -> PyResult<()> { m.add_class::()?; m.add_class::()?; 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"); + }); +}