Skip to content

Commit 8753625

Browse files
authored
Rollup merge of rust-lang#99421 - Bryanskiy:android-crt-static, r=petrochenkov
add crt-static for android
2 parents bb13209 + 05850bd commit 8753625

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
#![cfg_attr(bootstrap, feature(let_chains))]
247247
#![feature(let_else)]
248248
#![feature(linkage)]
249+
#![feature(link_cfg)]
249250
#![feature(min_specialization)]
250251
#![feature(must_not_suspend)]
251252
#![feature(needs_panic_runtime)]

std/src/sys/unix/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ pub fn abort_internal() -> ! {
295295

296296
cfg_if::cfg_if! {
297297
if #[cfg(target_os = "android")] {
298-
#[link(name = "dl")]
299-
#[link(name = "log")]
298+
#[link(name = "dl", kind = "static", modifiers = "-bundle",
299+
cfg(target_feature = "crt-static"))]
300+
#[link(name = "dl", cfg(not(target_feature = "crt-static")))]
301+
#[link(name = "log", cfg(not(target_feature = "crt-static")))]
300302
extern "C" {}
301303
} else if #[cfg(target_os = "freebsd")] {
302304
#[link(name = "execinfo")]

unwind/build.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ fn main() {
1313
let has_unwind = build.is_flag_supported("-lunwind").expect("Unable to invoke compiler");
1414

1515
if has_unwind {
16-
println!("cargo:rustc-link-lib=unwind");
17-
} else {
18-
println!("cargo:rustc-link-lib=gcc");
16+
println!("cargo:rustc-cfg=feature=\"system-llvm-libunwind\"");
1917
}
20-
21-
// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
22-
println!("cargo:rustc-link-lib=dl");
2318
} else if target.contains("freebsd") {
2419
println!("cargo:rustc-link-lib=gcc_s");
2520
} else if target.contains("netbsd") {

unwind/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ cfg_if::cfg_if! {
5555
}
5656
}
5757

58+
#[cfg(target_os = "android")]
59+
cfg_if::cfg_if! {
60+
if #[cfg(feature = "llvm-libunwind")] {
61+
compile_error!("`llvm-libunwind` is not supported for Android targets");
62+
} else if #[cfg(feature = "system-llvm-libunwind")] {
63+
#[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
64+
#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
65+
extern "C" {}
66+
} else {
67+
#[link(name = "gcc", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
68+
#[link(name = "gcc", cfg(not(target_feature = "crt-static")))]
69+
extern "C" {}
70+
}
71+
}
72+
// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
73+
#[cfg(target_os = "android")]
74+
#[link(name = "dl", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
75+
#[link(name = "dl", cfg(not(target_feature = "crt-static")))]
76+
extern "C" {}
77+
5878
// When building with crt-static, we get `gcc_eh` from the `libc` crate, since
5979
// glibc needs it, and needs it listed later on the linker command line. We
6080
// don't want to duplicate it here.

0 commit comments

Comments
 (0)