From 3f38ca52269f34582bb088ca34a4818aa9ab5c62 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 15 Sep 2023 18:51:10 -0700 Subject: [PATCH] build: fix missing libatomic on armv7 Linux --- .github/workflows/CI.yml | 2 +- build.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 175f704..f775883 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -77,7 +77,7 @@ jobs: target: armv7-unknown-linux-gnueabihf setup: | sudo apt-get update - sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y + sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libatomic1-armhf-cross -y build: | yarn build --target armv7-unknown-linux-gnueabihf --zig --zig-link-only arm-linux-gnueabihf-strip *.node diff --git a/build.rs b/build.rs index ee07810..6114ef4 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,20 @@ extern crate napi_build; fn main() { napi_build::setup(); let compile_target = std::env::var("TARGET").unwrap(); - if compile_target == "x86_64-unknown-linux-gnu" { - println!("cargo:rustc-link-search=/usr/x86_64-unknown-linux-gnu/lib"); + match compile_target.as_str() { + "x86_64-unknown-linux-gnu" => { + println!("cargo:rustc-link-search=/usr/x86_64-unknown-linux-gnu/lib"); + } + "armv7-unknown-linux-gnueabihf" => { + const CROSS_LIB_PATH: &str = "/usr/lib/gcc-cross/arm-linux-gnueabihf"; + if let Ok(version) = std::process::Command::new("ls") + .arg(CROSS_LIB_PATH) + .output() + .map(|o| String::from_utf8(o.stdout).unwrap().trim().to_string()) + { + println!("cargo:rustc-link-search={CROSS_LIB_PATH}/{version}"); + }; + } + _ => {} } }