Skip to content

Commit

Permalink
Support Android ndk versions r23-beta3 and up
Browse files Browse the repository at this point in the history
Since android ndk version `r23-beta3`, `libgcc` has been replaced with
`libunwind`. This moves the linking of `libgcc`/`libunwind` into the
`unwind` crate where we check if the system compiler can find
`libunwind` and fall back to `libgcc` if needed.
  • Loading branch information
Tilmann Meyer committed Jun 1, 2021
1 parent 971a3f1 commit 965997b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion library/std/src/sys/unix/mod.rs
Expand Up @@ -210,7 +210,6 @@ cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
#[link(name = "dl")]
#[link(name = "log")]
#[link(name = "gcc")]
extern "C" {}
} else if #[cfg(target_os = "freebsd")] {
#[link(name = "execinfo")]
Expand Down
14 changes: 14 additions & 0 deletions library/unwind/build.rs
Expand Up @@ -20,6 +20,20 @@ fn main() {
// linking for Linux is handled in lib.rs
if target.contains("musl") {
llvm_libunwind::compile();
} else if target.contains("android") {
let build = cc::Build::new();

// Since ndk r23 beta 3 `libgcc` was replaced with `libunwind` thus
// check if we have `libunwind` available and if so use it. Otherwise
// fall back to `libgcc` to support older ndk versions.
let has_unwind =
build.is_flag_supported("-lunwind").expect("Unable to invoke compiler");

if has_unwind {
println!("cargo:rustc-link-lib=unwind");
} else {
println!("cargo:rustc-link-lib=gcc");
}
}
} else if target.contains("freebsd") {
println!("cargo:rustc-link-lib=gcc_s");
Expand Down

0 comments on commit 965997b

Please sign in to comment.