Fix wasip2 build by youknowone · Pull Request #6935 · RustPython/RustPython
📝 Walkthrough
Walkthrough
The pull request migrates RustPython away from the unstable wasip2 feature flag by providing custom stable implementations of wasip2-specific APIs. It removes feature gates, adds a new WASI p2-specific ffi module with OsStrExt and OsStringExt traits, updates API imports and usage, and extends CI to verify compilation for the wasm32-wasip2 target.
Changes
| Cohort / File(s) | Summary |
|---|---|
Feature gate removal src/lib.rs, crates/stdlib/src/lib.rs, crates/common/src/lib.rs |
Removes crate-level #![cfg_attr(...wasip2)] and #![feature(wasip2)] attributes, eliminating reliance on the unstable wasip2 feature flag. |
WASI p2 stable ffi implementation crates/common/src/os.rs |
Introduces a new pub mod ffi under cfg(all(target_os = "wasi", target_env = "p2")) with custom trait definitions: OsStrExt (as_bytes, from_bytes) and OsStringExt (from_vec, into_vec). Includes trait implementations for std::ffi types and a sealed module, leveraging UTF-8 guarantees for WASI p2 compatibility. |
API import and usage updates crates/stdlib/src/select.rs, src/settings.rs |
Updates RawFd re-export path from std::os::wasi::io::RawFd to std::os::fd::RawFd. Changes split_paths implementation to use as_encoded_bytes() and from_encoded_bytes_unchecked() instead of unstable OsStrExt trait methods. |
CI enhancement .github/workflows/ci.yaml |
Adds rust-toolchain installation and cargo check step for the wasm32-wasip2 target to verify compilation on WASI p2 builds. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- PR
#5985: Converts string-based APIs to byte-oriented operations (as_bytes, as_encoded_bytes), employing similar patterns for handling encoded bytes across the codebase.
Poem
🐰 No longer trapped by unstable gates so tight,
WASI p2 shines with implementations bright,
Custom traits bloom, where bytes dance free,
Stable foundations for all to see! ✨
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title "Fix wasip2 build" directly corresponds to the main objective of addressing wasm32-wasip2 compilation failures referenced in issues #6891 and #5704. |
| Linked Issues check | ✅ Passed | The PR addresses both linked issues by providing stable WASI p2 FFI implementations, adjusting platform imports, removing conditional wasip2 features, and updating the split_paths implementation to work with wasip2 without relying on unstable features. |
| Out of Scope Changes check | ✅ Passed | All changes are directly scoped to fixing wasip2 target compilation: CI workflow updates, WASI p2 FFI module implementations, feature flag removal, and import path adjustments align with the stated objectives. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ 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.