Test wasm32 without js by youknowone · Pull Request #6283 · RustPython/RustPython
Walkthrough
The PR replaces the broken wasm test infrastructure by relocating the wasm crate from wasm/wasm-unknown-test/ to a new structured example project at example_projects/wasm32_without_js/. It introduces a wasm producer crate (rustpython-without-js) and a wasm runtime consumer (wasm-runtime) using Wasmer, along with CI workflow updates.
Changes
| Cohort / File(s) | Summary |
|---|---|
CI Workflow Update .github/workflows/ci.yaml |
Updated wasm test step to reference new project structure; changed working directory from wasm/wasm-unknown-test to example_projects/wasm32_without_js, adjusted cargo build manifest paths, and added execution step for the wasm runtime. |
Old WASM Test Crate Removal wasm/wasm-unknown-test/Cargo.toml, wasm/wasm-unknown-test/src/lib.rs |
Deleted the broken wasm test crate entirely, removing manifest and FFI entry points (eval and __getrandom_v03_custom). |
Example Project Documentation & Config example_projects/wasm32_without_js/.gitignore, example_projects/wasm32_without_js/README.md |
Added project-level gitignore patterns and comprehensive build/run documentation for the wasm32 example. |
WASM Producer Crate example_projects/wasm32_without_js/rustpython-without-js/Cargo.toml, example_projects/wasm32_without_js/rustpython-without-js/src/lib.rs |
Created new cdylib crate with FFI bridge exposing eval() C function; implements Python interpreter execution via rustpython-vm and declares getrandom hook; also declares external C function stubs (kv_get, kv_put, get_code, print). |
WASM Runtime Crate example_projects/wasm32_without_js/wasm-runtime/.gitignore, example_projects/wasm32_without_js/wasm-runtime/Cargo.toml, example_projects/wasm32_without_js/wasm-runtime/README.md, example_projects/wasm32_without_js/wasm-runtime/src/main.rs |
Created new Wasmer-based runtime crate with in-memory KV store backend; implements host-side FFI functions (kv_get, kv_put, print), loads and instantiates wasm module, manages memory references, and executes eval function. |
Sequence Diagram
sequenceDiagram
participant Host as Host Runtime<br>(main.rs)
participant WasmModule as WASM Module<br>(eval)
participant RustPython as RustPython VM
participant KVStore as KV Store
Host->>Host: Load WASM module from path
Host->>Host: Initialize KV store with code
Host->>WasmModule: Call eval(code_ptr, code_len)
activate WasmModule
WasmModule->>RustPython: Create Interpreter
RustPython->>RustPython: Execute Python expr "1 + 3"
RustPython-->>WasmModule: Result repr
WasmModule->>Host: Call print(msg_ptr, msg_len)
activate Host
Host->>Host: Read string from WASM memory
Host->>Host: Print to stdout
Host-->>WasmModule: return 0
deactivate Host
WasmModule-->>Host: return 0 (success)
deactivate WasmModule
Host->>Host: Report result
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- WASM memory safety & pointer handling: Both producer and consumer use unsafe extern FFI with raw pointer dereference; verify boundary conditions and memory access correctness
- Getrandom integration: Custom
__getrandom_v03_customhook implementation needs validation; ensure it doesn't break wasm runtime - FFI signature matching: Verify that function signatures and calling conventions align between
rustpython-without-js/src/lib.rsandwasm-runtime/src/main.rs - Wasmer integration: Review memory environment setup and function environment exports in the runtime
- CI workflow paths: Confirm all manifest and artifact paths resolve correctly in the new structure
Possibly related PRs
- Fix wasm32-unknown-unknown target build #6278: Modifies the same wasm FFI entrypoint in
wasm/wasm-unknown-test/src/lib.rs, adjusting attributes and wasm-related dependencies. - Move
wasm/lib->crates/wasm#6280: Updates CI workflow references to the project's wasm crate layout, modifying manifest and test paths for wasm-related steps. - wasm_js rustlfags on top workspace #6116: Configures getrandom's WebAssembly backend via rustflags; this PR adds a complementary custom getrandom hook (
__getrandom_v03_custom).
Poem
🐰 Hop, hop, a test reborn! 🌟
From broken paths, a new structure sworn,
Producer and runtime dance in tandem grace,
Wasm flows through memory's bounded space,
No more broken dreams—the bridge is strong! 🎉
Pre-merge checks and finishing touches
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'Test wasm32 without js' directly and specifically refers to the main change: adding a working test and example for wasm32 compilation without JavaScript support. |
| Linked Issues check | ✅ Passed | The PR successfully addresses issue #6281 by replacing the broken wasm-unknown-test with a functioning example and test setup that compiles and executes correctly. |
| Out of Scope Changes check | ✅ Passed | All changes are scoped to replacing the broken wasm32 test setup with a new working example and runtime, directly addressing the issue without introducing unrelated modifications. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.