Skip to content

feat(wasm)!: support wasm modules in ESM output with compile and preserve modes - #1726

Merged
Timeless0911 merged 48 commits into
mainfrom
feat/wasm-phase-1
Jul 29, 2026
Merged

Timeless0911 merged 48 commits into
mainfrom
feat/wasm-phase-1

Conversation

@elecmonkey

@elecmonkey elecmonkey commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Add a wasm library option to control how .wasm modules are handled in ESM output.

wasm.mode:

  • 'compile' — Rspack parses the .wasm module and generates the JS glue and runtime to load it.
  • 'preserve' — keep .wasm as a real ESM import and emit the binary with its source-relative path and original filename. This mode is only available when bundle is false.

When mode is unset, it defaults to 'compile' for bundle: true and 'preserve' for bundle: false. The option is only effective for format: 'esm'.

Includes integration tests covering compile/preserve × bundle/bundleless, and a new WebAssembly guide (EN + ZH) documenting the modes, supported import forms (static, dynamic, import source, import.source()), and wasm-bindgen usage.

Breaking changes

For ESM libraries using bundle: false, .wasm files are no longer emitted as standalone bundleless entries that generate JavaScript wrappers. They now default to wasm.mode: 'preserve', so output JavaScript retains .wasm imports and binaries keep their source-relative paths and original filenames.

To retain the compile behavior, set wasm.mode to 'compile'. No migration is required for bundle: true, which uses compile mode by default.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings June 28, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Deploying rslib with  Cloudflare Pages  Cloudflare Pages

Latest commit: 676c3bd
Status: ✅  Deploy successful!
Preview URL: https://817992b1.rslib.pages.dev
Branch Preview URL: https://feat-wasm-phase-1.rslib.pages.dev

View logs

@elecmonkey
elecmonkey marked this pull request as draft June 29, 2026 02:50
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rslib-v0 with  Cloudflare Pages  Cloudflare Pages

Latest commit: e3e100b
Status:⚡️  Build in progress...

View logs

@elecmonkey

Copy link
Copy Markdown
Member Author

The dynamic source phase: preserve tests require a fix in Rspack's RslibPlugin to preserve import.source() in dynamic external rendering: web-infra-dev/rspack#14615

@elecmonkey
elecmonkey force-pushed the feat/wasm-phase-1 branch from a47243f to 7c9f9c7 Compare July 1, 2026 17:54
@elecmonkey
elecmonkey marked this pull request as ready for review July 1, 2026 18:01
@elecmonkey elecmonkey changed the title feat(wasm): support wasm modules in ESM output with compile and preserve modes feat(wasm)!: support wasm modules in ESM output with compile and preserve modes Jul 3, 2026
@elecmonkey
elecmonkey marked this pull request as draft July 3, 2026 11:44
@elecmonkey

Copy link
Copy Markdown
Member Author

Temporarily marked as draft cuz I observe some outputs related to source phase imports are incorrect. I’m trying to fix these issues in Rspack: web-infra-dev/rspack#14673 & web-infra-dev/rspack#14674

@elecmonkey
elecmonkey marked this pull request as ready for review July 7, 2026 17:06
@elecmonkey
elecmonkey force-pushed the feat/wasm-phase-1 branch from 312fb2a to 6fa95ff Compare July 8, 2026 06:24
@elecmonkey
elecmonkey marked this pull request as draft July 8, 2026 06:27
@elecmonkey
elecmonkey marked this pull request as ready for review July 8, 2026 07:48
@Timeless0911

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de0e3cb7db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/wasm/path_utils.ts Outdated
@elecmonkey

Copy link
Copy Markdown
Member Author

@codex review

Comment thread packages/core/src/index.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7abee17845

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/wasm/compose.ts
Comment thread packages/core/src/config.ts Outdated
Comment thread packages/core/src/wasm/compose.ts Outdated
Comment thread packages/core/src/wasm/preserve.ts Outdated
Comment thread rslint.config.ts
@Timeless0911
Timeless0911 merged commit 43f9b4b into main Jul 29, 2026
12 checks passed
@Timeless0911
Timeless0911 deleted the feat/wasm-phase-1 branch July 29, 2026 08:56
@SoonIter

Copy link
Copy Markdown
Member

<agent: daily-job rspack eco-ci>

Daily AI eco-ci triage found that this PR introduced the current rslib suite failure in rstack-ecosystem-ci.

Evidence:

The mechanical cause is a runtime-version mismatch: this PR added source-phase WebAssembly output tests that require Node 24 syntax support, while the eco-ci Rspack build action currently pins Node 22.22.3. The preferred fix is to run this suite on Node 24; a downstream fallback is to gate the two runtime-import assertions on Node 24 while retaining build-output assertions on Node 22.

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.

4 participants

Sponsor
SponsoredKunjungi sekarang
Promo