Skip to content

Add WASI Preview 2 (wasip2) support#4851

Draft
Enrique726 wants to merge 5 commits intorolldown:mainfrom
Enrique726:feature/wasi-preview2-support
Draft

Add WASI Preview 2 (wasip2) support#4851
Enrique726 wants to merge 5 commits intorolldown:mainfrom
Enrique726:feature/wasi-preview2-support

Conversation

@Enrique726
Copy link

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

  • Added WasiP2 variant to the Platform enum in platform.rs
  • Updated TryFrom implementation to support string conversion for "wasi", "wasip1", and "wasip2"
  • Created wasi_features.rs with utility functions for WASI platform detection and configuration
  • Created wasi_config.rs for WASI-specific configuration options
  • Updated platform detection in normalize_options.rs
  • Modified BundlerBuilder to apply WASI-specific configurations
  • Created directory structure and files for the wasm32-wasip2 binding
  • Implemented @rolldown/wasip2 package for clean API exposure
  • Updated Cargo.toml with release-wasip2 profile
  • Added tests for platform detection, string conversion, and configuration utilities

Features

  • Detection of WASI environments (both Preview 1 and Preview 2)
  • WASI-specific configuration options based on version
  • Dedicated package for WASI Preview 2 builds
  • Fallback approach for testing without WebAssembly Component Model
  • Support for both WASI versions while maintaining backward compatibility

Testing

All tests pass successfully, validating:

  • Platform detection between WASI Preview 1 and 2
  • String conversion for platform types
  • WASI-specific configuration options
  • Build system functionality

Future Enhancements

  • Deeper WebAssembly Component Model integration as it matures
  • WASI Preview 2-specific optimizations
  • Extended testing in various WASI runtimes
  • Additional documentation and usage examples

Fixes #898

@Boshen Boshen requested a review from Brooooooklyn June 6, 2025 15:07
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to .gitignore this directory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@Brooooooklyn
Copy link
Member

bugbot run

@cursor
Copy link

cursor bot commented Jun 7, 2025

🚨 BugBot failed to run

Remote 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be moved to ./crates/rolldown_common and run using Vitest.

Copy link
Member

@Brooooooklyn Brooooooklyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Enrique726 Hey, thanks for your contribution. I left some comments on your PR.
The following changes are needed:

  1. 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
  2. The build scripts and code need to remove the checks for nightly and component-model, currently in the wasi environment we ensure that component-model is already enabled
  3. Some scripts need to be rewritten in TypeScript, and testing should be unified using Vitest tests

@Boshen Boshen marked this pull request as draft June 7, 2025 08:43
@Brooooooklyn Brooooooklyn requested a review from Copilot June 9, 2025 07:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +88 to +94
// 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';
}
Copy link

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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

Copilot uses AI. Check for mistakes.
@Enrique726 Enrique726 requested a review from Brooooooklyn June 9, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve WASI support

4 participants