Skip to content

Commit

Permalink
Merge pull request #1207 from napi-rs/fix-android-build
Browse files Browse the repository at this point in the history
fix: android builds broken by actions default ndk version bump
  • Loading branch information
Brooooooklyn committed Jun 10, 2022
2 parents 548f358 + 18dc3df commit 357e6bf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-armv7.yml
Expand Up @@ -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
6 changes: 1 addition & 5 deletions crates/backend/src/ast.rs
Expand Up @@ -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)
}
}

Expand Down
16 changes: 16 additions & 0 deletions 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)?;
let _ = libgcc.write(b"INPUT(-lunwind)")?;
drop(libgcc);
println!("cargo:rustc-link-search={}", &out_dir);
Ok(())
}
9 changes: 7 additions & 2 deletions 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 android::setup().is_ok() {},
_ => {}
}
}

0 comments on commit 357e6bf

Please sign in to comment.