Can not build RustPython to wasm32-wasip2
Summary
I am trying to build RustPython into .wasm file which can run Python program with ssl as dependency. I found that wasm32-wasip2 supports std fully, which means it supports socket proposal that wasm32-wasip1 does not.
But I failed.
Details
rustc version:
$ rustc --version rustc 1.88.0-nightly (38c560ae6 2025-04-15)
I also add #![feature(wasip2)] to the crate attributes and here is the diff:
diff --git a/common/src/lib.rs b/common/src/lib.rs index 25501e4f5..2ee3a78b5 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,5 +1,5 @@ //! A crate to hold types and functions common to all rustpython components. - +#![feature(wasip2)] #![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii))] #[macro_use] diff --git a/stdlib/src/lib.rs b/stdlib/src/lib.rs index a910c5854..8da304ac6 100644 --- a/stdlib/src/lib.rs +++ b/stdlib/src/lib.rs @@ -1,5 +1,6 @@ // to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of // how `mod` works, but we want this sometimes for pymodule declarations +#![feature(wasip2)] #![allow(clippy::module_inception)] #[macro_use]
Then I run the command below:
export RUSTFLAGS="-C linker=wasm-ld" cargo build --release --target wasm32-wasip2 --features "freeze-stdlib,ssl"
It fails with the log:
warning: unused import: `utils::ToCString` --> vm/src/stdlib/os.rs:145:9 | 145 | utils::ToCString, | ^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused imports: `IntoPyException`, `Py`, and `TryFromBorrowedObject` --> vm/src/stdlib/signal.rs:15:19 | 15 | convert::{IntoPyException, TryFromBorrowedObject}, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ 16 | signal, Py, PyObjectRef, PyResult, VirtualMachine, | ^^ warning: `rustpython-vm` (lib) generated 2 warnings (run `cargo fix --lib -p rustpython-vm` to apply 2 suggestions) Compiling rustpython-stdlib v0.4.0 (/home/jzd/projects/RustPython/stdlib) error[E0433]: failed to resolve: use of unresolved module or unlinked crate `ssl` --> stdlib/src/lib.rs:154:23 | 154 | "_ssl" => ssl::make_module, | ^^^ use of unresolved module or unlinked crate `ssl` | = help: if you wanted to use a crate named `ssl`, use `cargo add ssl` to add it to your `Cargo.toml` For more information about this error, try `rustc --explain E0433`. error: could not compile `rustpython-stdlib` (lib) due to 1 previous error
What can I do to make it work? I need the feature ssl to enable python library couchdb and redis.