Skip to content

Commit

Permalink
build(plugin): Update wasmer to v4.2.5 (#8624)
Browse files Browse the repository at this point in the history
**Description:**

This is required to update rustc.
  • Loading branch information
kdy1 authored Feb 10, 2024
1 parent 361c9db commit 4e0d240
Show file tree
Hide file tree
Showing 14 changed files with 843 additions and 850 deletions.
436 changes: 185 additions & 251 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions bindings/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[workspace]
members = [
"binding_core_node",
"binding_core_wasm",
"binding_minifier_node",
"binding_minifier_wasm",
"swc_cli",
"binding_core_node",
"binding_core_wasm",
"binding_minifier_node",
"binding_minifier_wasm",
"swc_cli",
]
resolver = "2"

[profile.release]
# lto = true
Expand Down
1 change: 1 addition & 0 deletions bindings/binding_core_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ swc_core = { version = "0.90.6", features = [
"base_concurrent",
] }
swc_malloc = "0.5.10"
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread"] }
165 changes: 89 additions & 76 deletions bindings/binding_core_node/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,45 @@ impl Task for TransformTask {

let error_format = options.experimental.error_format.unwrap_or_default();

try_with(
self.c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
self.c.run(|| match &self.input {
Input::Program(ref s) => {
let program: Program =
deserialize_json(s).expect("failed to deserialize Program");
// TODO: Source map
self.c.process_js(handler, program, &options)
}

Input::File(ref path) => {
let fm = self.c.cm.load_file(path).context("failed to load file")?;
self.c.process_js_file(fm, handler, &options)
}

Input::Source { src } => {
let fm = self.c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
} else {
FileName::Real(options.filename.clone().into())
},
src.to_string(),
);

self.c.process_js_file(fm, handler, &options)
}
})
},
)
.convert_err()
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
try_with(
self.c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
self.c.run(|| match &self.input {
Input::Program(ref s) => {
let program: Program =
deserialize_json(s).expect("failed to deserialize Program");
// TODO: Source map
self.c.process_js(handler, program, &options)
}

Input::File(ref path) => {
let fm =
self.c.cm.load_file(path).context("failed to load file")?;
self.c.process_js_file(fm, handler, &options)
}

Input::Source { src } => {
let fm = self.c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
} else {
FileName::Real(options.filename.clone().into())
},
src.to_string(),
);

self.c.process_js_file(fm, handler, &options)
}
})
},
)
})
.convert_err()
}

fn resolve(&mut self, _env: Env, result: Self::Output) -> napi::Result<Self::JsValue> {
Expand Down Expand Up @@ -137,31 +142,35 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<

let error_format = options.experimental.error_format.unwrap_or_default();

try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
c.run(|| {
if is_module {
let program: Program =
deserialize_json(s.as_str()).context("failed to deserialize Program")?;
c.process_js(handler, program, &options)
} else {
let fm = c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
c.run(|| {
if is_module {
let program: Program = deserialize_json(s.as_str())
.context("failed to deserialize Program")?;
c.process_js(handler, program, &options)
} else {
FileName::Real(options.filename.clone().into())
},
s,
);
c.process_js_file(fm, handler, &options)
}
})
},
)
.convert_err()
let fm = c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
} else {
FileName::Real(options.filename.clone().into())
},
s,
);
c.process_js_file(fm, handler, &options)
}
})
},
)
})
.convert_err()
}

#[napi]
Expand Down Expand Up @@ -203,22 +212,26 @@ pub fn transform_file_sync(

let error_format = options.experimental.error_format.unwrap_or_default();

try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
c.run(|| {
if is_module {
let program: Program =
deserialize_json(s.as_str()).context("failed to deserialize Program")?;
c.process_js(handler, program, &options)
} else {
let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file");
c.process_js_file(fm, handler, &options)
}
})
},
)
.convert_err()
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
try_with(
c.cm.clone(),
!options.config.error.filename.into_bool(),
error_format,
|handler| {
c.run(|| {
if is_module {
let program: Program = deserialize_json(s.as_str())
.context("failed to deserialize Program")?;
c.process_js(handler, program, &options)
} else {
let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file");
c.process_js_file(fm, handler, &options)
}
})
},
)
})
.convert_err()
}
15 changes: 7 additions & 8 deletions crates/binding_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ swc_ecma_transforms = { optional = true, version = "0.229.3", path = "../swc_ecm
swc_ecma_visit = { optional = true, version = "0.98.2", path = "../swc_ecma_visit" }

# Optional deps for the wasm binding macro
anyhow = { optional = true, version = "1.0.71" }
anyhow = { optional = true, version = "1.0.71" }
console_error_panic_hook = { optional = true, version = "0.1.7" }
js-sys = { optional = true, version = "0.3.59" }
once_cell = { optional = true, version = "1.18.0" }
serde = { optional = true, version = "1", features = ["derive"] }
serde-wasm-bindgen = { optional = true, version = "0.4.5" }
# https://github.com/wasmerio/wasmer/blob/77898a7767eb7057834fdc1a80b239e6b68cf44e/lib/wasix/Cargo.toml#L92
wasm-bindgen = { optional = true, version = "=0.2.84", features = [
js-sys = { optional = true, version = "0.3.59" }
once_cell = { optional = true, version = "1.18.0" }
serde = { optional = true, version = "1", features = ["derive"] }
serde-wasm-bindgen = { optional = true, version = "0.4.5" }
wasm-bindgen = { optional = true, version = "0.2.91", features = [
"enable-interning",
] }
wasm-bindgen-futures = { optional = true, version = "=0.4.34" }
wasm-bindgen-futures = { optional = true, version = "0.4.41" }
10 changes: 4 additions & 6 deletions crates/swc_plugin_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ plugin_transform_host_native = [
"wasmer-wasix/host-threads",
"wasmer-compiler-cranelift/default",
]
plugin_transform_host_native_shared_runtime = [
"tokio",
"wasmer-wasix/webc_runner",
]
plugin_transform_host_native_shared_runtime = ["tokio"]

# Supports a cache allow to store compiled bytecode into filesystem location.
# This feature implies in-memory cache support. This is not supported on wasm32 target.
Expand All @@ -58,8 +55,8 @@ serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
tokio = { version = "1", default-features = false, optional = true }
tracing = "0.1.37"
wasmer = { version = "4.0.0", default-features = false }
wasmer-wasix = { version = "0.9.0", default-features = false }
wasmer = { version = "4.2.5", default-features = false }
wasmer-wasix = { version = "0.18.0", default-features = false }

swc_common = { version = "0.33.17", path = "../swc_common", features = [
"concurrent",
Expand Down Expand Up @@ -88,6 +85,7 @@ swc_ecma_parser = { version = "0.143.3", path = "../swc_ecma_parser" }
swc_ecma_visit = { version = "0.98.2", path = "../swc_ecma_visit" }
swc_malloc = { version = "0.5.10", path = "../swc_malloc" }
testing = { version = "0.35.18", path = "../testing" }
tokio = { version = "1", features = ["rt"] }

[[bench]]
harness = false
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_plugin_runner/src/wasix_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn build_wasi_runtime(
use wasmer_wasix::{
runtime::{
module_cache::{ModuleCache, SharedCache},
package_loader::BuiltinPackageLoader,
package_loader::UnsupportedPackageLoader,
resolver::MultiSource,
task_manager::tokio::TokioTaskManager,
},
Expand All @@ -68,9 +68,9 @@ pub fn build_wasi_runtime(
let cache =
SharedCache::default().with_fallback(wasmer_wasix::runtime::module_cache::in_memory());

let dummy_loader = BuiltinPackageLoader::new_with_client(".", Arc::new(StubHttpClient));
let dummy_loader = UnsupportedPackageLoader;
let rt = PluggableRuntime {
rt: Arc::new(TokioTaskManager::shared()),
rt: Arc::new(TokioTaskManager::default()),
networking: Arc::new(virtual_net::UnsupportedVirtualNetworking::default()),
engine: Some(ENGINE.lock().clone()),
tty: None,
Expand Down
Loading

0 comments on commit 4e0d240

Please sign in to comment.