Repository navigation
Can not build RustPython to wasm32-wasip2 #5704
Copy link
Copy link
Closed
Description
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 errorWhat can I do to make it work? I need the feature ssl to enable python library couchdb and redis.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
youknowone commentedon Apr 17, 2025
you will find
mod sslis disabled for the entire wasm32miraclejzd commentedon Apr 17, 2025
It is.
Do you plan to support ssl for wasm32-wasip2? I think it's an important feature for python :)
youknowone commentedon Apr 17, 2025
We usually don't have plans but cover more features step by step.
Yes, it is important. And a lot of things are important features for python. Please help us to support it.
arihant2math commentedon Apr 17, 2025
To my knowledge it is not possible to support ssl for wasm, (barring some major shift in architecture) due to this:
rust-openssl/rust-openssl#1016.
miraclejzd commentedon Apr 17, 2025
Well, I am not familiar with Rust(and RustPython). But in CPython, it is possible to add ssl support, check out wasmer/python . We can use pre-built openssl and link it to CPython. I am trying to find the same solution to RustPython, but due to my poor Rust knowledge, it's hard :(
youknowone commentedon Apr 17, 2025
Thank you for the reference! We may can do similar way.
One caveat. The linked
wasmer/pythonis saying it is built on top of wasix, wasmer's variant of wasi.Then that build will be only compatible to wasmer.
miraclejzd commentedon Apr 17, 2025
Absolutely!
wasmer/pythonis wasix-based so that it can not work withwasmtimeand other wasi-based wasm runtime. That's why I want to build a wasi-based python interpreter.I will continue trying to find the solution. If you have any other idea, I will keep paying attention :)
JMLX42 commentedon Dec 9, 2025
@arihant2math Can't we use rust-tls ?
In the grand scheme of things, shouldn't RustPython for WASI rely on
wasi:httpanyway?youknowone commentedon Dec 10, 2025
good news is that now RustPython has rustls version of SSL as default
JMLX42 commentedon Dec 12, 2025
RustPython builds just fine for wasm-wasip2. The only catch is that one must use nightly because p2 is still considered unstable:
rust-lang/rust#130323
youknowone commentedon Dec 12, 2025
Sounds great! Thank you for the testing