Skip to content

feat: support rspack wasi with node.js#9872

Merged
h-a-n-a merged 6 commits intoweb-infra-dev:mainfrom
CPunisher:03-31-feat/wasi-execution
Apr 3, 2025
Merged

feat: support rspack wasi with node.js#9872
h-a-n-a merged 6 commits intoweb-infra-dev:mainfrom
CPunisher:03-31-feat/wasi-execution

Conversation

@CPunisher
Copy link
Contributor

@CPunisher CPunisher commented Apr 1, 2025

Summary

Here are some final works to make rspack wasi available in node.js. Now you can run rspack wasi on rspack/rolldown benchmark (remember to use NAPI_RS_FORCE_WASI=1):

  1. Fix regex passing from js to rs. Although I don't know why globalThis.Object.prototype is an External other than JsObject.
  2. Copy canonicalize from rspack_resolver because fs::canonicalize doesn't support wasm.
  3. Enable tokio multi thread feature to avoid tokio::spawn blocking the program.

BUT PAY ATTENTION:

  1. Only release mode is avaliable. If you build rspack with build:cli:dev:wasm, you will get random memory errors. Currently I don't figure it out yet.
  2. Rspack doesn't exit when it finishes works. Currently I don't call shutdownAsyncRuntime in js side because rayon thread pool also blocks the program. I'd like to handle these two cases in next pr.
  3. You may get memory allocation failure in very big project.

Checklist

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

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Apr 1, 2025
@netlify
Copy link

netlify bot commented Apr 1, 2025

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 1350ac6
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/67ebe3dc9c3a2d00099a1ba5

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 1, 2025

CodSpeed Performance Report

Merging #9872 will not alter performance

Comparing CPunisher:03-31-feat/wasi-execution (1350ac6) with main (93af8c8)

Summary

✅ 8 untouched benchmarks

@chenjiahan chenjiahan requested review from h-a-n-a and hardfist April 2, 2025 12:50
@h-a-n-a h-a-n-a merged commit 493c919 into web-infra-dev:main Apr 3, 2025
39 checks passed
@h-a-n-a
Copy link
Contributor

h-a-n-a commented Apr 3, 2025

Thanks!

let path = dunce::canonicalize(path)?;
Ok(path.assert_utf8())
// Comes from rspack_resolver
use std::path::Component;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this wasi only and should be put into cfg_if!?

Copy link
Contributor Author

@CPunisher CPunisher Apr 3, 2025

Choose a reason for hiding this comment

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

.get_named_property::<JsObject>("prototype")?
.get_named_property::<Function>("toString")?;
.get_named_property_unchecked::<JsObject>("prototype")?
.get_named_property_unchecked::<Function>("toString")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

why this changed?

Copy link
Contributor Author

@CPunisher CPunisher Apr 3, 2025

Choose a reason for hiding this comment

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

I'm not sure but from my experiments:

  1. .get_named_property_unchecked::<JsObject>("prototype") returns an External in wasm rather than JsObject.
  2. But _unchecked in .get_named_property_unchecked::<Function>("toString")? is actually needless.

@CPunisher CPunisher mentioned this pull request Apr 4, 2025
8 tasks
@CPunisher CPunisher deleted the 03-31-feat/wasi-execution branch July 30, 2025 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants