diff --git a/napi/minify/Cargo.toml b/napi/minify/Cargo.toml index db69350c136b3..4ceda0115b9c3 100644 --- a/napi/minify/Cargo.toml +++ b/napi/minify/Cargo.toml @@ -34,10 +34,14 @@ napi = { workspace = true } napi-derive = { workspace = true } [target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"], optional = true } [target.'cfg(any(all(target_os = "linux", not(target_arch = "arm")), target_os = "freebsd"))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"], optional = true } [build-dependencies] napi-build = { workspace = true } + +[features] +default = [] +allocator = ["dep:mimalloc-safe"] diff --git a/napi/minify/package.json b/napi/minify/package.json index 0861b505ba8ab..5610b3be62a30 100644 --- a/napi/minify/package.json +++ b/napi/minify/package.json @@ -5,7 +5,7 @@ "browser": "browser.js", "scripts": { "build-dev": "napi build --no-dts-cache --platform", - "build": "pnpm run build-dev --release", + "build": "pnpm run build-dev --features allocator --release", "test": "vitest run --dir ./test && tsc" }, "engines": { diff --git a/napi/minify/src/lib.rs b/napi/minify/src/lib.rs index 98f8bbeb810e4..011b9d4c34d64 100644 --- a/napi/minify/src/lib.rs +++ b/napi/minify/src/lib.rs @@ -1,6 +1,6 @@ #![expect(clippy::needless_pass_by_value, clippy::missing_errors_doc)] -#[cfg(all(not(target_arch = "arm"), not(target_family = "wasm")))] +#[cfg(all(feature = "allocator", not(target_arch = "arm"), not(target_family = "wasm")))] #[global_allocator] static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc; diff --git a/napi/parser/Cargo.toml b/napi/parser/Cargo.toml index a8b0cea024d21..a4ca7cdb3a64f 100644 --- a/napi/parser/Cargo.toml +++ b/napi/parser/Cargo.toml @@ -33,10 +33,14 @@ napi = { workspace = true, features = ["async"] } napi-derive = { workspace = true } [target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"], optional = true } [target.'cfg(any(all(target_os = "linux", not(target_arch = "arm")), target_os = "freebsd"))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"], optional = true } [build-dependencies] napi-build = { workspace = true } + +[features] +default = [] +allocator = ["dep:mimalloc-safe"] diff --git a/napi/parser/package.json b/napi/parser/package.json index b577d3a201650..2f16821a0647f 100644 --- a/napi/parser/package.json +++ b/napi/parser/package.json @@ -5,7 +5,7 @@ "browser": "wasm.mjs", "scripts": { "build-dev": "napi build --no-dts-cache --platform --js bindings.js", - "build": "pnpm run build-dev --release", + "build": "pnpm run build-dev --features allocator --release", "build-wasi": "pnpm run build-dev --release --target wasm32-wasip1-threads", "build-npm-dir": "rm -rf npm-dir && napi create-npm-dirs --npm-dir npm-dir && pnpm napi artifacts --npm-dir npm-dir --output-dir .", "test": "pnpm run test-node run && tsc", diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index f41cbf68c4d1c..4b680e0fc1dc2 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -1,7 +1,7 @@ // Napi value need to be passed as value #![expect(clippy::needless_pass_by_value)] -#[cfg(all(not(target_arch = "arm"), not(target_family = "wasm")))] +#[cfg(all(feature = "allocator", not(target_arch = "arm"), not(target_family = "wasm")))] #[global_allocator] static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc; diff --git a/napi/transform/Cargo.toml b/napi/transform/Cargo.toml index e4e1326bcdef4..58ff2b1a39f00 100644 --- a/napi/transform/Cargo.toml +++ b/napi/transform/Cargo.toml @@ -32,10 +32,14 @@ napi = { workspace = true } napi-derive = { workspace = true } [target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit"], optional = true } [target.'cfg(any(all(target_os = "linux", not(target_arch = "arm")), target_os = "freebsd"))'.dependencies] -mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"] } +mimalloc-safe = { workspace = true, features = ["skip_collect_on_exit", "local_dynamic_tls"], optional = true } [build-dependencies] napi-build = { workspace = true } + +[features] +default = [] +allocator = ["dep:mimalloc-safe"] diff --git a/napi/transform/package.json b/napi/transform/package.json index 734803c0023fb..87608a5ffc15f 100644 --- a/napi/transform/package.json +++ b/napi/transform/package.json @@ -5,7 +5,7 @@ "browser": "browser.js", "scripts": { "build-dev": "napi --no-dts-cache build --platform", - "build": "pnpm run build-dev --release", + "build": "pnpm run build-dev --features allocator --release", "test": "vitest run --dir ./test && tsc" }, "engines": { diff --git a/napi/transform/src/lib.rs b/napi/transform/src/lib.rs index 506e5d2f4c06f..42fe9625b6e95 100644 --- a/napi/transform/src/lib.rs +++ b/napi/transform/src/lib.rs @@ -1,4 +1,4 @@ -#[cfg(all(not(target_arch = "arm"), not(target_family = "wasm")))] +#[cfg(all(feature = "allocator", not(target_arch = "arm"), not(target_family = "wasm")))] #[global_allocator] static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;