Skip to content

Can not build RustPython to wasm32-wasip2 #5704

Closed

Description

@miraclejzd

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.

Activity

  1. youknowone commented on Apr 17, 2025

    @youknowone
    Member

    you will find mod ssl is disabled for the entire wasm32

  2. miraclejzd commented on Apr 17, 2025

    @miraclejzd
    Author

    you will find mod ssl is disabled for the entire wasm32

    It is.
    Do you plan to support ssl for wasm32-wasip2? I think it's an important feature for python :)

  3. youknowone commented on Apr 17, 2025

    @youknowone
    Member

    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.

  4. arihant2math commented on Apr 17, 2025

    @arihant2math
    Contributor

    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.

  5. miraclejzd commented on Apr 17, 2025

    @miraclejzd
    Author

    To my knowledge it is not possible to support ssl for wasm, (barring some major shift in architecture) due to this: sfackler/rust-openssl#1016.

    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 :(

  6. youknowone commented on Apr 17, 2025

    @youknowone
    Member

    Thank you for the reference! We may can do similar way.

    One caveat. The linked wasmer/python is saying it is built on top of wasix, wasmer's variant of wasi.
    Then that build will be only compatible to wasmer.

  7. miraclejzd commented on Apr 17, 2025

    @miraclejzd
    Author

    Thank you for the reference! We may can do similar way.

    One caveat. The linked wasmer/python is saying it is built on top of wasix, wasmer's variant of wasi. Then that build will be only compatible to wasmer.

    Absolutely! wasmer/python is wasix-based so that it can not work with wasmtime and 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 :)

  8. JMLX42 commented on Dec 9, 2025

    @JMLX42
    Contributor

    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.

    @arihant2math Can't we use rust-tls ?

    In the grand scheme of things, shouldn't RustPython for WASI rely on wasi:http anyway?

  9. youknowone commented on Dec 10, 2025

    @youknowone
    Member

    good news is that now RustPython has rustls version of SSL as default

  10. JMLX42 commented on Dec 12, 2025

    @JMLX42
    Contributor

    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

  11. youknowone commented on Dec 12, 2025

    @youknowone
    Member

    Sounds great! Thank you for the testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions