-
-
Notifications
You must be signed in to change notification settings - Fork 757
feat(wasm): support wasm compilation #9585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
h-a-n-a
merged 17 commits into
web-infra-dev:main
from
CPunisher:02-06-feat/wasm-compile
Mar 11, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bf1c8bc
mimalloc
CPunisher e48d9f7
wasm build
CPunisher bea7aa2
rspack_futures
CPunisher 605a627
rspack_tracing otel optional
CPunisher 475699b
tokio features
CPunisher 7ac8a54
stacker
CPunisher ba70aae
gitignore wasm files
CPunisher af7dd97
Add @napi-rs/wasm-runtime
CPunisher b347e84
disable ctor
CPunisher 0b787b3
bump lightningcss
CPunisher 9dd46ec
fix rebase error
CPunisher dd6e9a2
Update napi wasm auto-generation
CPunisher 46181aa
Add CI
CPunisher 63640a1
Fix CI build command
CPunisher 6f128d0
Update test snapshot
CPunisher b308eae
Update artifact to make ci happy but don't release
CPunisher 32ffa06
Fix duplicated step id
CPunisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /*.node | ||
| /*.node | ||
| /*.wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from '@rspack/binding-wasm32-wasi' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { | ||
| instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, | ||
| getDefaultContext as __emnapiGetDefaultContext, | ||
| WASI as __WASI, | ||
| createOnMessage as __wasmCreateOnMessageForFsProxy, | ||
| } from '@napi-rs/wasm-runtime' | ||
| import { memfs } from '@napi-rs/wasm-runtime/fs' | ||
| import __wasmUrl from './rspack.wasm32-wasi.wasm?url' | ||
|
|
||
| export const { fs: __fs, vol: __volume } = memfs() | ||
|
|
||
| const __wasi = new __WASI({ | ||
| version: 'preview1', | ||
| fs: __fs, | ||
| preopens: { | ||
| '/': '/', | ||
| }, | ||
| }) | ||
|
|
||
| const __emnapiContext = __emnapiGetDefaultContext() | ||
|
|
||
| const __sharedMemory = new WebAssembly.Memory({ | ||
| initial: 16384, | ||
| maximum: 65536, | ||
| shared: true, | ||
| }) | ||
|
|
||
| const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer()) | ||
|
|
||
| const { | ||
| instance: __napiInstance, | ||
| module: __wasiModule, | ||
| napiModule: __napiModule, | ||
| } = __emnapiInstantiateNapiModuleSync(__wasmFile, { | ||
| context: __emnapiContext, | ||
| asyncWorkPoolSize: 4, | ||
| wasi: __wasi, | ||
| onCreateWorker() { | ||
| const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), { | ||
| type: 'module', | ||
| }) | ||
| worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs)) | ||
|
|
||
| return worker | ||
| }, | ||
| overwriteImports(importObject) { | ||
| importObject.env = { | ||
| ...importObject.env, | ||
| ...importObject.napi, | ||
| ...importObject.emnapi, | ||
| memory: __sharedMemory, | ||
| } | ||
| return importObject | ||
| }, | ||
| beforeInit({ instance }) { | ||
| for (const name of Object.keys(instance.exports)) { | ||
| if (name.startsWith('__napi_register__')) { | ||
| instance.exports[name]() | ||
| } | ||
| } | ||
| }, | ||
| }) | ||
| export const Dependency = __napiModule.exports.Dependency | ||
| export const EntryDataDto = __napiModule.exports.EntryDataDto | ||
| export const EntryDataDTO = __napiModule.exports.EntryDataDTO | ||
| export const EntryDependency = __napiModule.exports.EntryDependency | ||
| export const EntryOptionsDto = __napiModule.exports.EntryOptionsDto | ||
| export const EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO | ||
| export const JsChunk = __napiModule.exports.JsChunk | ||
| export const JsChunkGraph = __napiModule.exports.JsChunkGraph | ||
| export const JsChunkGroup = __napiModule.exports.JsChunkGroup | ||
| export const JsCompilation = __napiModule.exports.JsCompilation | ||
| export const JsCompiler = __napiModule.exports.JsCompiler | ||
| export const JsContextModuleFactoryAfterResolveData = __napiModule.exports.JsContextModuleFactoryAfterResolveData | ||
| export const JsContextModuleFactoryBeforeResolveData = __napiModule.exports.JsContextModuleFactoryBeforeResolveData | ||
| export const JsDependencies = __napiModule.exports.JsDependencies | ||
| export const JsDependenciesBlock = __napiModule.exports.JsDependenciesBlock | ||
| export const JsEntries = __napiModule.exports.JsEntries | ||
| export const JsExportsInfo = __napiModule.exports.JsExportsInfo | ||
| export const JsModule = __napiModule.exports.JsModule | ||
| export const JsModuleGraph = __napiModule.exports.JsModuleGraph | ||
| export const JsModuleGraphConnection = __napiModule.exports.JsModuleGraphConnection | ||
| export const JsResolver = __napiModule.exports.JsResolver | ||
| export const JsResolverFactory = __napiModule.exports.JsResolverFactory | ||
| export const JsStats = __napiModule.exports.JsStats | ||
| export const RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx | ||
| export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName | ||
| export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace | ||
| export const formatDiagnostic = __napiModule.exports.formatDiagnostic | ||
| export const JsLoaderState = __napiModule.exports.JsLoaderState | ||
| export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity | ||
| export const RawRuleSetConditionType = __napiModule.exports.RawRuleSetConditionType | ||
| export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace | ||
| export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.