From 983df4ca95fcfe6e29a45198a56602e927933455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Tue, 28 May 2024 20:42:36 +0800 Subject: [PATCH] fix: armv7 segmentfault --- Cargo.toml | 2 +- js-binding.js | 35 +++++++++++++++++++++++++---------- src/lib.rs | 1 + wasm/index.d.ts | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d8674eb..07c470b4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ woff2 = "0.3.0" [target.'cfg(not(any(target_os = "linux", target_family = "wasm")))'.dependencies] mimalloc = "0.1" -[target.'cfg(target_os = "linux")'.dependencies] +[target.'cfg(all(target_os = "linux", not(target_arch = "arm")))'.dependencies] mimalloc = { version = "0.1", features = ["local_dynamic_tls"] } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/js-binding.js b/js-binding.js index fa66a4c2..195d976d 100644 --- a/js-binding.js +++ b/js-binding.js @@ -224,17 +224,32 @@ switch (platform) { } break case 'arm': - localFileExisted = existsSync( - join(__dirname, 'resvgjs.linux-arm-gnueabihf.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./resvgjs.linux-arm-gnueabihf.node') - } else { - nativeBinding = require('@resvg/resvg-js-linux-arm-gnueabihf') + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'resvgjs.linux-arm-musleabihf.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./resvgjs.linux-arm-musleabihf.node') + } else { + nativeBinding = require('@resvg/resvg-js-linux-arm-musleabihf') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'resvgjs.linux-arm-gnueabihf.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./resvgjs.linux-arm-gnueabihf.node') + } else { + nativeBinding = require('@resvg/resvg-js-linux-arm-gnueabihf') + } + } catch (e) { + loadError = e } - } catch (e) { - loadError = e } break case 'riscv64': diff --git a/src/lib.rs b/src/lib.rs index c99b440c..13dacd59 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ use error::Error; use usvg::NodeExt; #[cfg(all(not(target_family = "wasm"), not(debug_assertions),))] +#[cfg(not(all(target_os = "linux", target_arch = "arm")))] #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/wasm/index.d.ts b/wasm/index.d.ts index 4153e038..b6ba08c7 100644 --- a/wasm/index.d.ts +++ b/wasm/index.d.ts @@ -1,4 +1,4 @@ -// Generated by dts-bundle-generator v9.3.1 +// Generated by dts-bundle-generator v9.5.1 declare class BBox { free(): void;