Skip to content

Commit

Permalink
fix: test bindings on x86_64-unknown-linux-musl (#306)
Browse files Browse the repository at this point in the history
* fix: test bindings on x86_64-unknown-linux-musl

```bash
Error: Error relocating /build/resvgjs.linux-x64-musl.node: mprotect: initial-exec TLS resolves to dynamic definition in /build/resvgjs.linux-x64-musl.node

  › Object.<anonymous> (js-binding.js:175:31)
  › Module._compile (node_modules/pirates/lib/index.js:117:24)

  ✘ __test__/index.spec.ts exited with a non-zero exit code: 1
```

* chore: migrate to mimalloc

---------

Co-authored-by: LongYinan <[email protected]>
  • Loading branch information
yisibl and Brooooooklyn authored Mar 11, 2024
1 parent 83517ce commit 543684c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
build: |-
set -e &&
yarn build &&
llvm-strip -x *.node
strip *.node
- host: macos-14
target: aarch64-apple-darwin
build: |
Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ pathfinder_simd = { version = "0.5.2", features = ["pf-no-simd"] }
futures = "0.3.21"
woff2 = "0.3.0"

[target.'cfg(all(not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")), not(all(target_os = "windows", target_arch = "aarch64")), not(target_arch = "wasm32")))'.dependencies]
mimalloc-rust = { version = "0.2" }
[target.'cfg(not(any(target_os = "linux", target_family = "wasm")))'.dependencies]
mimalloc = "0.1"

[target.'cfg(target_os = "linux")'.dependencies]
mimalloc = { version = "0.1", features = ["local_dynamic_tls"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2.87"
Expand Down
43 changes: 43 additions & 0 deletions js-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,49 @@ switch (platform) {
loadError = e
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'resvgjs.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./resvgjs.linux-riscv64-musl.node')
} else {
nativeBinding = require('@resvg/resvg-js-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'resvgjs.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./resvgjs.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@resvg/resvg-js-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'resvgjs.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./resvgjs.linux-s390x-gnu.node')
} else {
nativeBinding = require('@resvg/resvg-js-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ mod options;
use error::Error;
use usvg::NodeExt;

#[cfg(all(
not(target_arch = "wasm32"),
not(debug_assertions),
not(all(target_os = "windows", target_arch = "aarch64")),
not(all(target_os = "linux", target_arch = "aarch64", target_env = "musl")),
))]
#[cfg(all(not(target_family = "wasm"), not(debug_assertions),))]
#[global_allocator]
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
Expand Down
Binary file modified wasm/index_bg.wasm
Binary file not shown.

0 comments on commit 543684c

Please sign in to comment.