Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
422 changes: 167 additions & 255 deletions deps/swc/Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion deps/swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/*",
"tools/generate-code",
"tools/swc-releaser",
"tools/swc-native-addon-pack",
]
resolver = "2"

Expand All @@ -29,7 +30,7 @@ backtrace = "0.3"
base64 = "0.22.1"
bitflags = "2.5.0"
blake3 = "1.5.4"
browserslist-rs = "0.20.0"
browserslist-rs = { version = "0.21.2", features = ["deflate"] }
bumpalo = "3.16.0"
bytes-str = "0.2.5"
cargo_metadata = "0.18.1"
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_core_node/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn parse_file_sync(path: String, opts: Buffer) -> napi::Result<String> {
try_with(c.cm.clone(), false, ErrorFormat::Normal, |handler| {
let fm =
c.cm.load_file(Path::new(path.as_str()))
.expect("failed to read program file");
.context("failed to read program file")?;

let local_comments = SwcComments::default();
let comments = if options.comments {
Expand Down
4 changes: 3 additions & 1 deletion deps/swc/bindings/binding_core_node/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ pub fn transform_file_sync(
error_format,
|handler| {
c.run(|| {
let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file");
let fm =
c.cm.load_file(Path::new(&s))
.context("failed to load file")?;
c.process_js_file(fm, handler, &options)
})
},
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_core_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
name = "binding_core_wasm"
publish = false
repository = { workspace = true }
version = "1.16.2"
version = "1.16.13"

[lib]
bench = false
Expand Down
1 change: 1 addition & 0 deletions deps/swc/bindings/binding_core_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ export interface UmdConfig extends BaseModuleConfig {
export interface AmdConfig extends BaseModuleConfig {
type: "amd";
moduleId?: string;
moduleRoot?: string;
}
export interface SystemjsConfig {
type: "systemjs";
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_es_ast_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = { workspace = true }
name = "binding_es_ast_viewer"
publish = false
repository = { workspace = true }
version = "1.16.2"
version = "1.16.13"

[dependencies]
anyhow = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_html_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
name = "binding_html_wasm"
publish = false
repository = { workspace = true }
version = "1.16.2"
version = "1.16.13"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion deps/swc/bindings/binding_minifier_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = { workspace = true }
name = "binding_minifier_wasm"
publish = false
repository = { workspace = true }
version = "1.16.2"
version = "1.16.13"

[lib]
bench = false
Expand Down
1 change: 1 addition & 0 deletions deps/swc/bindings/binding_minifier_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,7 @@ export interface UmdConfig extends BaseModuleConfig {
export interface AmdConfig extends BaseModuleConfig {
type: "amd";
moduleId?: string;
moduleRoot?: string;
}
export interface SystemjsConfig {
type: "systemjs";
Expand Down
26 changes: 26 additions & 0 deletions deps/swc/bindings/binding_native_addon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "binding_native_addon"
version = "0.1.0"
edition = "2021"
rust-version = "1.73"
license = "Apache-2.0"
publish = false
build = "build.rs"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
embedded-payload = []

[dependencies]
swc_native_addon = { path = "../../crates/swc_native_addon" }
libloading = "=0.8.1"
tracing = { version = "=0.1.41", default-features = false, features = ["std"] }

[build-dependencies]
swc_native_addon = { path = "../../crates/swc_native_addon" }
tempfile = "=3.12.0"

[dev-dependencies]
tempfile = "=3.12.0"
24 changes: 24 additions & 0 deletions deps/swc/bindings/binding_native_addon/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
The registration descriptor and constructor contract in src/legacy.rs follow
the public N-API NAPI_MODULE_X interface in Node.js v10.0.0's src/node_api.h.
The following Node.js attribution is retained for that interface adaptation.
No implementation from SWC PR #12000 or the napi-rs compression PoC is used.

Copyright Node.js contributors. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
81 changes: 81 additions & 0 deletions deps/swc/bindings/binding_native_addon/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::{env, fs, path::PathBuf};

use swc_native_addon::{
format::{NativeTarget, Payload},
integrity::RuntimeIntegrity,
};

fn main() {
println!("cargo:rerun-if-env-changed=SWC_NATIVE_BINDING_PAYLOAD");
let output = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("payload.rs");
if env::var_os("CARGO_FEATURE_EMBEDDED_PAYLOAD").is_none() {
fs::write(
output,
"static PAYLOAD: &[u8] = &[];\nstatic INTEGRITY: &[u8] = &[];\n",
)
.unwrap();
return;
}
let target = env::var("TARGET").unwrap();
let target = NativeTarget::parse(&target).expect("native carrier target");
let path = PathBuf::from(
env::var_os("SWC_NATIVE_BINDING_PAYLOAD")
.expect("embedded-payload requires SWC_NATIVE_BINDING_PAYLOAD=/absolute/payload.swcn"),
);
assert!(
path.is_absolute(),
"SWC_NATIVE_BINDING_PAYLOAD must be absolute"
);
println!("cargo:rerun-if-changed={}", path.display());
let bytes = fs::read(&path).expect("read native addon payload");
let payload = Payload::parse(&bytes).expect("validate native addon payload header");
assert_eq!(
payload.header.target, target,
"embedded native addon payload target does not match Cargo TARGET"
);
let output_parent = output.parent().expect("OUT_DIR has a parent");
let mut raw = tempfile::Builder::new()
.prefix(".swc-native-addon-validate-")
.tempfile_in(output_parent)
.expect("stage decoded native addon validation");
payload
.decode_into(&mut raw)
.expect("decode embedded native addon bytes");
payload
.verify_target(&mut raw)
.expect("validate embedded native addon target");
let integrity = RuntimeIntegrity::from_raw(&payload.header, &mut raw)
.expect("derive runtime integrity from SHA-512 verified raw addon");
let integrity_path = output.with_file_name("integrity.swcn");
fs::write(&integrity_path, integrity.encode()).expect("snapshot native runtime integrity");
// Copy to OUT_DIR so a later input replacement cannot change the validated
// payload between build-script validation and rustc's include_bytes call.
let embedded = output.with_file_name("payload.swcn");
fs::write(&embedded, &bytes).expect("snapshot validated addon payload");
// Retain a complete, mapped payload for final-artifact verification. LTO
// may otherwise fold header reads and eliminate parts of include_bytes.
// Section names fit the Mach-O (16-byte) and PE (8-byte) limits.
fs::write(
output,
format!(
r#"#[used]
#[cfg_attr(target_os = "linux", link_section = ".swc_native")]
#[cfg_attr(target_os = "macos", link_section = "__TEXT,__swc_native")]
#[cfg_attr(windows, link_section = ".swcn")]
static EMBEDDED_PAYLOAD: [u8; {}] = *include_bytes!({:?});
static PAYLOAD: &[u8] = &EMBEDDED_PAYLOAD;
#[used]
#[cfg_attr(target_os = "linux", link_section = ".swc_integrity")]
#[cfg_attr(target_os = "macos", link_section = "__TEXT,__swc_integrity")]
#[cfg_attr(windows, link_section = ".swci")]
static EMBEDDED_INTEGRITY: [u8; {}] = *include_bytes!({:?});
static INTEGRITY: &[u8] = &EMBEDDED_INTEGRITY;
"#,
payload.header.compressed_len + swc_native_addon::format::HEADER_LEN as u64,
embedded,
swc_native_addon::integrity::INTEGRITY_LEN,
integrity_path,
),
)
.unwrap();
}
58 changes: 58 additions & 0 deletions deps/swc/bindings/binding_native_addon/src/legacy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Node 10.0 predates lookup of napi_register_module_v1 by symbol. Its original
//! napi_module_register entry point is required even though all APIs used by
//! the initializer itself exist there. New Node versions also accept this hook.
//!
//! Constructors only register metadata. Decompression, IO, and native loading
//! stay in the initializer, outside the Windows loader lock.
//! See ../NOTICE for the Node.js MIT attribution of this public ABI adaptation.

use std::{
ffi::{c_char, c_void},
ptr,
};

use crate::napi::Register;

#[repr(C)]
struct Module {
version: i32,
flags: u32,
filename: *const c_char,
register: Register,
name: *const c_char,
private: *mut c_void,
reserved: [*mut c_void; 4],
}

static mut MODULE: Module = Module {
version: 1,
flags: 0,
filename: b"swc-native-carrier\0".as_ptr().cast(),
register: crate::napi_register_module_v1,
name: b"swc_native_carrier\0".as_ptr().cast(),
private: ptr::null_mut(),
reserved: [ptr::null_mut(); 4],
};

unsafe extern "C" fn register() {
#[cfg(unix)]
let process = libloading::os::unix::Library::this();
#[cfg(windows)]
let process = match libloading::os::windows::Library::this() {
Ok(process) => process,
Err(_) => return,
};
// Test executables are not Node hosts. They can link the rlib without
// registering anything; Node always exports this original N-API function.
if let Ok(register) =
process.get::<unsafe extern "C" fn(*mut Module)>(b"napi_module_register\0")
{
register(ptr::addr_of_mut!(MODULE));
}
}

#[used]
#[cfg_attr(target_os = "linux", link_section = ".init_array")]
#[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
#[cfg_attr(windows, link_section = ".CRT$XCU")]
static INITIALIZER: unsafe extern "C" fn() = register;
Loading
Loading