Skip to content

Commit 1058ba0

Browse files
authored
perf: Update swc and switch to wasmtime (#11303)
* perf: Update swc and switch to wasmtime * disable wasmer backend * fix swc tests * fix deny * vendor wasmtime backend
1 parent 244ec4c commit 1058ba0

File tree

13 files changed

+1086
-1646
lines changed

13 files changed

+1086
-1646
lines changed

Cargo.lock

Lines changed: 746 additions & 1606 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ inventory = { version = "0.3.17", default-features = false }
123123
rkyv = { version = "=0.8.8", default-features = false, features = ["std", "bytecheck"] }
124124

125125
# Must be pinned with the same swc versions
126-
pnp = { version = "0.12.1", default-features = false }
127-
swc = { version = "32.0.0", default-features = false }
128-
swc_config = { version = "3.1.1", default-features = false }
129-
swc_core = { version = "33.0.0", default-features = false, features = ["parallel_rayon"] }
130-
swc_ecma_lexer = { version = "21.0.0", default-features = false }
131-
swc_ecma_minifier = { version = "27.0.0", default-features = false }
132-
swc_error_reporters = { version = "16.0.1", default-features = false }
133-
swc_html = { version = "25.0.0", default-features = false }
134-
swc_html_minifier = { version = "27.0.0", default-features = false }
135-
swc_node_comments = { version = "14.0.0", default-features = false }
126+
pnp = { version = "0.12.1", default-features = false }
127+
swc = { version = "34.0.0", default-features = false }
128+
swc_config = { version = "3.1.1", default-features = false }
129+
swc_core = { version = "35.0.0", default-features = false, features = ["parallel_rayon"] }
130+
swc_ecma_lexer = { version = "22.0.0", default-features = false }
131+
swc_ecma_minifier = { version = "29.0.0", default-features = false }
132+
swc_error_reporters = { version = "16.0.1", default-features = false }
133+
swc_html = { version = "25.0.0", default-features = false }
134+
swc_html_minifier = { version = "29.0.0", default-features = false }
135+
swc_node_comments = { version = "14.0.0", default-features = false }
136+
swc_plugin_runner = { version = "18.0.0", default-features = false }
137+
138+
wasmtime = { version = "35.0.0", default-features = false }
139+
wasi-common = { version = "35.0.0", default-features = false }
136140

137141
rspack_dojang = { version = "0.1.11", default-features = false }
138142

@@ -340,9 +344,6 @@ opt-level = "s"
340344
[profile.release.package.swc_error_reporters]
341345
opt-level = "s"
342346

343-
[profile.release.package.http]
344-
opt-level = "s"
345-
346347
[profile.release.package.idna]
347348
opt-level = "s"
348349

crates/rspack_binding_api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version.workspace = true
1414
browser = ["dep:rspack_browser", "rspack_napi/browser"]
1515
color-backtrace = ["dep:color-backtrace"]
1616
debug_tool = ["rspack_core/debug_tool"]
17-
plugin = ["rspack_loader_swc/plugin"]
17+
plugin = ["rspack_loader_swc/plugin", "rspack_util/plugin"]
1818
sftrace-setup = ["dep:sftrace-setup", "rspack_allocator/sftrace-setup"]
1919

2020
[dependencies]

crates/rspack_binding_api/src/swc.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ fn _to_source_map_kind(source_maps: Option<SourceMapsConfig>) -> SourceMapKind {
4141
}
4242

4343
fn _transform(source: String, options: String) -> napi::Result<TransformOutput> {
44-
let options: SwcOptions = serde_json::from_str(&options)?;
44+
#[cfg_attr(not(feature = "plugin"), allow(unused_mut))]
45+
let mut options: SwcOptions = serde_json::from_str(&options)?;
46+
47+
#[cfg(feature = "plugin")]
48+
{
49+
options.runtime_options = options.runtime_options.plugin_runtime(std::sync::Arc::new(
50+
rspack_util::swc::runtime::WasmtimeRuntime,
51+
));
52+
}
53+
4554
let compiler = JavaScriptCompiler::new();
4655
let module_source_map_kind = _to_source_map_kind(options.source_maps.clone());
56+
4757
compiler
4858
.transform(
4959
source,

crates/rspack_loader_swc/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ ignored = ["swc"]
1111
[features]
1212
default = []
1313
plugin = [
14-
"swc_core/plugin_transform_host_native",
14+
"rspack_util/plugin",
15+
16+
# plugin_transform_host_native cannot be enabled directly to avoid wasmer dependency
17+
"swc_core/__plugin_transform_host",
18+
"swc_core/__plugin_transform_host_schema_v1",
1519
"swc_core/plugin_transform_host_native_filesystem_cache",
16-
"swc_core/plugin_transform_host_native_shared_runtime",
1720
]
1821

1922
[dependencies]
@@ -36,6 +39,7 @@ swc_config = { workspace = true }
3639
swc_core = { workspace = true, features = ["base", "ecma_ast", "common", "ecma_preset_env", "ecma_helpers_inline"] }
3740
tokio = { workspace = true }
3841
tracing = { workspace = true }
42+
rspack_util = { workspace = true, optional = true }
3943

4044

4145
[target.'cfg(not(target_family = "wasm"))'.dependencies]

crates/rspack_loader_swc/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ impl SwcLoader {
8080
"`env` and `jsc.target` cannot be used together".to_string(),
8181
));
8282
}
83+
84+
#[cfg(feature = "plugin")]
85+
{
86+
swc_options.runtime_options =
87+
swc_options
88+
.runtime_options
89+
.plugin_runtime(std::sync::Arc::new(
90+
rspack_util::swc::runtime::WasmtimeRuntime,
91+
));
92+
}
93+
8394
swc_options
8495
};
8596

crates/rspack_util/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ unicase = { workspace = true }
2929
swc_config = { workspace = true }
3030
swc_core = { workspace = true, features = ["base", "ecma_ast"] }
3131

32+
# wasm runtime
33+
anyhow = { workspace = true, optional = true }
34+
once_cell = { workspace = true, optional = true }
35+
wasmtime = { workspace = true, optional = true, features = ["runtime", "cranelift", "threads"] }
36+
wasi-common = { workspace = true, optional = true, features = ["sync", "wasmtime"] }
37+
swc_plugin_runner = { workspace = true, optional = true }
38+
3239
rspack_regex = { workspace = true }
3340
signal-hook = { workspace = true, optional = true }
3441

3542
[features]
3643
debug_tool = ["signal-hook"] # only used for local debug and should not be enabled in production release
44+
plugin = [ "anyhow", "once_cell", "wasmtime", "wasi-common", "swc_plugin_runner" ]

crates/rspack_util/src/swc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(feature = "plugin")]
2+
pub mod runtime;
3+
14
use rustc_hash::FxHashSet;
25
use swc_config::types::BoolOr;
36
use swc_core::{

0 commit comments

Comments
 (0)