Add WASI Preview 2 (wasip2) support#4851
Conversation
There was a problem hiding this comment.
Need to .gitignore this directory?
There was a problem hiding this comment.
Added the target-wasm/ directory to .gitignore as suggested. This will prevent the build artifacts from being committed to the repository. Thanks for the recommendation!
|
bugbot run |
🚨 BugBot failed to runRemote branch not found for this Pull Request. It may have been merged or deleted (requestId: serverGenReqId_2815386c-05ed-41c5-9589-6d362de383eb). |
| /** | ||
| * Test script to verify platform string conversion for WASI platforms | ||
| */ | ||
| import { tryFrom } from './crates/rolldown_common/src/inner_bundler_options/types/platform.js'; |
There was a problem hiding this comment.
These tests should be moved to ./crates/rolldown_common and run using Vitest.
Brooooooklyn
left a comment
There was a problem hiding this comment.
@Enrique726 Hey, thanks for your contribution. I left some comments on your PR.
The following changes are needed:
- nightly and component-model are not required, NAPI-RS has already handled this, we need to ensure that rolldown can be developed normally under stable Rust
- The build scripts and code need to remove the checks for nightly and
component-model, currently in thewasienvironment we ensure thatcomponent-modelis already enabled - Some scripts need to be rewritten in
TypeScript, and testing should be unified using Vitest tests
…form detection, convert tests to TypeScript
There was a problem hiding this comment.
Pull Request Overview
This PR implements support for WASI Preview 2 (wasip2) in Rolldown, adding platform detection, configuration options, dedicated bindings, and accompanying tests and CI workflows.
- Added new Platform variants and string conversion support for WASI Preview 2
- Introduced WASI-specific configuration functions and adjusted filename templates for WASI outputs
- Updated documentation, tests, and CI workflows for WASI Preview 2 integration
Reviewed Changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| docs/contrib-guide/building-and-running.md | Updated documentation to include instructions for building WASI Preview 2 versions |
| crates/rolldown_common/src/inner_bundler_options/types/platform.rs | Added new enum variants and string conversion support for WASI Preview 2 |
| crates/rolldown_common/src/wasi_features.{rs,js} | Introduced utility functions for WASI platform and preview detection |
| crates/rolldown/src/wasi_config.{rs,js} | Added WASI-specific configuration options and environment settings |
| crates/rolldown/src/utils/normalize_options.rs | Adjusted platform override for wasm target environment |
| crates/rolldown/src/bundler_builder.rs | Configured WASI resolve options and output filename template adjustments |
| Cargo.toml, CI workflows | Added new release profile and updated workflows for WASI Preview 2 tests |
| // Add RUSTUP_TOOLCHAIN=nightly | ||
| environment['RUSTUP_TOOLCHAIN'] = 'nightly'; | ||
|
|
||
| // For Preview 2, we need component model | ||
| if (is_wasi_preview2(platform)) { | ||
| environment['RUSTFLAGS'] = '-Z wasm-component-model'; | ||
| } |
There was a problem hiding this comment.
The JavaScript implementation of add_wasi_environment_settings sets the nightly toolchain and component model flags, while the Rust version omits these settings. Consider aligning the behavior across both implementations to avoid potential confusion for users relying on consistent environment configuration.
| // Add RUSTUP_TOOLCHAIN=nightly | |
| environment['RUSTUP_TOOLCHAIN'] = 'nightly'; | |
| // For Preview 2, we need component model | |
| if (is_wasi_preview2(platform)) { | |
| environment['RUSTFLAGS'] = '-Z wasm-component-model'; | |
| } | |
| // No additional environment settings are required for WASI platforms | |
| // Ensure consistent behavior with the Rust implementation |
Add WASI Preview 2 (wasip2) support
Description
This pull request implements support for WASI Preview 2 in Rolldown, addressing issue #898. The implementation adds proper platform detection, configuration options, and package infrastructure for WASI Preview 2 environments.
Changes
WasiP2variant to thePlatformenum inplatform.rsTryFromimplementation to support string conversion for "wasi", "wasip1", and "wasip2"wasi_features.rswith utility functions for WASI platform detection and configurationwasi_config.rsfor WASI-specific configuration optionsnormalize_options.rsBundlerBuilderto apply WASI-specific configurationsFeatures
Testing
All tests pass successfully, validating:
Future Enhancements
Fixes #898