Skip to content

Commit 6667579

Browse files
authored
chore(napi): make mimalloc optional to build (oxc-project#495)
1 parent 57fa56f commit 6667579

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

napi/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ napi-derive = { version = "3.0.0-alpha" }
1818
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["std", "fmt"] } # Omit the `regex` feature
1919

2020
[target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies]
21-
mimalloc-safe = { version = "0.1.50", features = ["skip_collect_on_exit"] }
21+
mimalloc-safe = { version = "0.1.50", optional = true, features = ["skip_collect_on_exit"] }
2222

2323
[target.'cfg(all(target_os = "linux", not(target_arch = "arm")))'.dependencies]
24-
mimalloc-safe = { version = "0.1.50", features = ["skip_collect_on_exit", "local_dynamic_tls"] }
24+
mimalloc-safe = { version = "0.1.50", optional = true, features = ["skip_collect_on_exit", "local_dynamic_tls"] }
2525

2626
[build-dependencies]
2727
napi-build = "2.1.6"
28+
29+
[features]
30+
default = []
31+
allocator = ["dep:mimalloc-safe"]

napi/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#[cfg(all(not(target_arch = "arm"), not(target_os = "freebsd"), not(target_family = "wasm")))]
1+
#[cfg(all(
2+
feature = "allocator",
3+
not(target_arch = "arm"),
4+
not(target_os = "freebsd"),
5+
not(target_family = "wasm")
6+
))]
27
#[global_allocator]
38
static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
49

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
],
2323
"scripts": {
2424
"test": "vitest run -r ./napi",
25-
"build": "napi build --platform --release --manifest-path napi/Cargo.toml",
2625
"build:debug": "napi build --platform --manifest-path napi/Cargo.toml",
27-
"postbuild": "node napi/patch.mjs"
26+
"build": "pnpm run build:debug --features allocator --release",
27+
"postbuild:debug": "node napi/patch.mjs"
2828
},
2929
"devDependencies": {
3030
"@napi-rs/cli": "3.0.0-alpha.78",

0 commit comments

Comments
 (0)