Replace wasmer with wasmtime for SWC plugin WASM engine#91533
Merged
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Mar 17, 2026
Merging this PR will not alter performance
Comparing Footnotes
|
mischnic
reviewed
Mar 17, 2026
|
85hu5WTLEudeW1exQBcXch4HMYk422wo7nJxej6AwdJC |
3a26fe4 to
48d399c
Compare
53edebe to
66859ea
Compare
48d399c to
dc7f06b
Compare
66859ea to
b5afe19
Compare
556ef7f to
76f0037
Compare
dc7f06b to
74a9431
Compare
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
76f0037 to
3f1dc27
Compare
74a9431 to
1d8e326
Compare
Contributor
Tests Passed |
bgw
approved these changes
Apr 8, 2026
eed0393 to
2e40d0f
Compare
Swap out swc_plugin_backend_wasmer (wasmer 6.1.0-rc) with a new swc_plugin_backend_wasmtime crate to reduce native binary size. - Create crates/swc-plugin-backend-wasmtime implementing the swc_plugin_runner Runtime/Instance/Caller traits via wasmtime - Update workspace Cargo.toml: add wasmtime deps, remove wasmer deps and release profiles - Wire WasmtimeRuntime into both code paths: - Turbopack: turbopack-ecmascript-plugins - Webpack/SWC NAPI: next-napi-bindings transform.rs - Remove swc_core/plugin_backend_wasmer feature flag usage - Integration points designed for future swappability (e.g. Node NAPI WASM engine) Fix compilation errors in wasmtime backend implementation - Remove unused import (std::sync::Arc) - Use raw pointer approach for Caller trait implementation to work around Rust lifetime constraints with wasmtime::Caller parameter - Implement runtime::Caller trait methods using unsafe pointer access, which is safe because the pointer lifetime is controlled within the host function closure The key challenge was that wasmtime's closure signature provides a Caller parameter with a specific lifetime that doesn't satisfy the trait object requirements for runtime::Caller. The solution uses unsafe pointer casting with careful lifetime management to bridge the gap between wasmtime's API and swc_plugin_runner's trait interface. Remove wasmer from compilation graph Replace swc_core/plugin_transform_host_native with granular internal features (__plugin_transform_host + __plugin_transform_host_schema_v1) to bypass __plugin_transform_env_native, which is the only feature path that pulls in wasmer via swc -> swc_plugin_backend_wasmer. Since we provide WasmtimeRuntime explicitly, we don't need swc's env-native backend wiring. This removes wasmer and all its sub-crates from cargo tree entirely, eliminating unnecessary compilation time.
2127a74 to
b82c568
Compare
Contributor
Author
Merge activity
|
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

What?
Replace wasmer with wasmtime as the WASM runtime for SWC plugins.
Why?
wasmer/defaultvswasmer/js-default) and large binary sizeswc_plugin_backend_wasmtimeon crates.io, so we can use it directly instead of maintaining our own implementationHow?
swc_plugin_backend_wasmtimev9.0.0 crate from crates.io instead of a custom local implementationswc_core/plugin_transform_host_native(which pulls in wasmer via__plugin_transform_env_native) with granular features:__plugin_transform_host+__plugin_transform_host_schema_v1WasmtimeRuntimeexplicitly in both the NAPI bindings and turbopack plugin pathswasmtime/wasmtime-wasiworkspace dependencies — the upstream crate manages its own wasmtime versionswc_plugin_backend_wasmtime,swc_plugin_runner,wasmtime,wasmtime-internal-cranelift)vergen = "=9.0.6"to avoid avergen-libversion conflict withvergen-gitcl1.0.8Binary size impact (darwin-arm64, compared against current canary)