From f90d63ccde270357d517a4fe39643807515c8889 Mon Sep 17 00:00:00 2001 From: forehalo Date: Thu, 9 Jun 2022 23:38:43 +0800 Subject: [PATCH 1/2] fix(build): broken android target build caused by ndk upgrade --- .github/workflows/android-armv7.yml | 2 +- crates/build/src/android.rs | 16 ++++++++++++++++ crates/build/src/lib.rs | 9 +++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 crates/build/src/android.rs diff --git a/.github/workflows/android-armv7.yml b/.github/workflows/android-armv7.yml index 32afdc5c..ada64904 100644 --- a/.github/workflows/android-armv7.yml +++ b/.github/workflows/android-armv7.yml @@ -60,5 +60,5 @@ jobs: export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang" yarn build:test:android:armv7 du -sh examples/napi/index.node - ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip examples/napi/index.node + ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip examples/napi/index.node du -sh examples/napi/index.node diff --git a/crates/build/src/android.rs b/crates/build/src/android.rs new file mode 100644 index 00000000..e4bde877 --- /dev/null +++ b/crates/build/src/android.rs @@ -0,0 +1,16 @@ +use std::env; +use std::fs; +use std::io::{Error, Write}; +use std::path; + +// Workaround from https://github.com/rust-lang/rust/pull/85806#issuecomment-1096266946 +pub fn setup() -> Result<(), Error> { + let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); + let mut dist = path::PathBuf::from(&out_dir); + dist.push("libgcc.a"); + let mut libgcc = fs::File::create(&dist)?; + libgcc.write(b"INPUT(-lunwind)")?; + drop(libgcc); + println!("cargo:rustc-link-search={}", &out_dir); + Ok(()) +} diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index dac8ba27..65e19611 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -1,8 +1,13 @@ +mod android; mod macos; pub fn setup() { println!("cargo:rerun-if-env-changed=DEBUG_GENERATED_CODE"); - if let Ok("macos") = std::env::var("CARGO_CFG_TARGET_OS").as_deref() { - macos::setup(); + match std::env::var("CARGO_CFG_TARGET_OS").as_deref() { + Ok("macos") => { + macos::setup(); + } + Ok("android") => if let Ok(_) = android::setup() {}, + _ => {} } } From 18dc3df5bab8c3a9d302d309996dba8717d93fcb Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 10 Jun 2022 15:20:06 +0800 Subject: [PATCH 2/2] style: clippy --- crates/backend/src/ast.rs | 6 +----- crates/build/src/android.rs | 2 +- crates/build/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index 33641687..570f0451 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -40,11 +40,7 @@ pub struct NapiFnArg { impl NapiFnArg { /// if type was overridden with `#[napi(ts_arg_type = "...")]` use that instead pub fn use_overridden_type_or(&self, default: impl FnOnce() -> String) -> String { - self - .ts_arg_type - .as_ref() - .map(|ts| ts.clone()) - .unwrap_or_else(default) + self.ts_arg_type.as_ref().cloned().unwrap_or_else(default) } } diff --git a/crates/build/src/android.rs b/crates/build/src/android.rs index e4bde877..702a3bbd 100644 --- a/crates/build/src/android.rs +++ b/crates/build/src/android.rs @@ -9,7 +9,7 @@ pub fn setup() -> Result<(), Error> { let mut dist = path::PathBuf::from(&out_dir); dist.push("libgcc.a"); let mut libgcc = fs::File::create(&dist)?; - libgcc.write(b"INPUT(-lunwind)")?; + let _ = libgcc.write(b"INPUT(-lunwind)")?; drop(libgcc); println!("cargo:rustc-link-search={}", &out_dir); Ok(()) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 65e19611..3dd6bf16 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -7,7 +7,7 @@ pub fn setup() { Ok("macos") => { macos::setup(); } - Ok("android") => if let Ok(_) = android::setup() {}, + Ok("android") => if android::setup().is_ok() {}, _ => {} } }