Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add crt-static for android #99421

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2139,9 +2139,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.126"
version = "0.2.129"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
checksum = "64de3cc433455c14174d42e554d4027ee631c4d046d43e3ecc6efc4636cdc7a7"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/android_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub fn opts() -> TargetOptions {
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
// was to always emit `uwtable`).
base.default_uwtable = true;
base.crt_static_respected = false;
base.crt_static_respected = true;
base
}
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
#![cfg_attr(bootstrap, feature(let_chains))]
#![feature(let_else)]
#![feature(linkage)]
#![feature(link_cfg)]
#![feature(min_specialization)]
#![feature(must_not_suspend)]
#![feature(needs_panic_runtime)]
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ pub fn abort_internal() -> ! {

cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
#[link(name = "dl")]
#[link(name = "log")]
#[link(name = "dl", kind = "static", modifiers = "-bundle",
cfg(target_feature = "crt-static"))]
#[link(name = "dl", cfg(not(target_feature = "crt-static")))]
#[link(name = "log", cfg(not(target_feature = "crt-static")))]
extern "C" {}
} else if #[cfg(target_os = "freebsd")] {
#[link(name = "execinfo")]
Expand Down
7 changes: 1 addition & 6 deletions library/unwind/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ fn main() {
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");
println!("cargo:rustc-cfg=feature=\"system-llvm-libunwind\"");
}

// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
Bryanskiy marked this conversation as resolved.
Show resolved Hide resolved
println!("cargo:rustc-link-lib=dl");
} else if target.contains("freebsd") {
println!("cargo:rustc-link-lib=gcc_s");
} else if target.contains("netbsd") {
Expand Down
20 changes: 20 additions & 0 deletions library/unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ cfg_if::cfg_if! {
}
}

#[cfg(target_os = "android")]
cfg_if::cfg_if! {
if #[cfg(feature = "llvm-libunwind")] {
compile_error!("`llvm-libunwind` is not supported for Android targets");
} else if #[cfg(feature = "system-llvm-libunwind")] {
#[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
#[link(name = "unwind", cfg(not(target_feature = "crt-static")))]
extern "C" {}
} else {
#[link(name = "gcc", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
#[link(name = "gcc", cfg(not(target_feature = "crt-static")))]
extern "C" {}
}
}
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
// Android's unwinding library depends on dl_iterate_phdr in `libdl`.
#[cfg(target_os = "android")]
#[link(name = "dl", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
#[link(name = "dl", cfg(not(target_feature = "crt-static")))]
extern "C" {}

// When building with crt-static, we get `gcc_eh` from the `libc` crate, since
// glibc needs it, and needs it listed later on the linker command line. We
// don't want to duplicate it here.
Expand Down