Skip to content

Commit 965997b

Browse files
author
Tilmann Meyer
committed
Support Android ndk versions r23-beta3 and up
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.
1 parent 971a3f1 commit 965997b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

library/std/src/sys/unix/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ cfg_if::cfg_if! {
210210
if #[cfg(target_os = "android")] {
211211
#[link(name = "dl")]
212212
#[link(name = "log")]
213-
#[link(name = "gcc")]
214213
extern "C" {}
215214
} else if #[cfg(target_os = "freebsd")] {
216215
#[link(name = "execinfo")]

library/unwind/build.rs

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ fn main() {
2020
// linking for Linux is handled in lib.rs
2121
if target.contains("musl") {
2222
llvm_libunwind::compile();
23+
} else if target.contains("android") {
24+
let build = cc::Build::new();
25+
26+
// Since ndk r23 beta 3 `libgcc` was replaced with `libunwind` thus
27+
// check if we have `libunwind` available and if so use it. Otherwise
28+
// fall back to `libgcc` to support older ndk versions.
29+
let has_unwind =
30+
build.is_flag_supported("-lunwind").expect("Unable to invoke compiler");
31+
32+
if has_unwind {
33+
println!("cargo:rustc-link-lib=unwind");
34+
} else {
35+
println!("cargo:rustc-link-lib=gcc");
36+
}
2337
}
2438
} else if target.contains("freebsd") {
2539
println!("cargo:rustc-link-lib=gcc_s");

0 commit comments

Comments
 (0)