Skip to content

Commit 6737549

Browse files
authored
Rollup merge of #99421 - Bryanskiy:android-crt-static, r=petrochenkov
add crt-static for android
2 parents 9606408 + 874ee5b commit 6737549

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2142,9 +2142,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
21422142

21432143
[[package]]
21442144
name = "libc"
2145-
version = "0.2.126"
2145+
version = "0.2.129"
21462146
source = "registry+https://github.com/rust-lang/crates.io-index"
2147-
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
2147+
checksum = "64de3cc433455c14174d42e554d4027ee631c4d046d43e3ecc6efc4636cdc7a7"
21482148
dependencies = [
21492149
"rustc-std-workspace-core",
21502150
]

compiler/rustc_target/src/spec/android_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ pub fn opts() -> TargetOptions {
1010
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
1111
// was to always emit `uwtable`).
1212
base.default_uwtable = true;
13-
base.crt_static_respected = false;
13+
base.crt_static_respected = true;
1414
base
1515
}

library/std/src/lib.rs

+1
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)]

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

+4-2
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")]

library/unwind/build.rs

+1-6
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") {

library/unwind/src/lib.rs

+20
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)