diff --git a/Cargo.lock b/Cargo.lock index e21e11d9d..8d8f9d4b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,6 @@ name = "as-if-std" version = "0.1.0" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", @@ -36,7 +35,6 @@ name = "backtrace" version = "0.3.73" dependencies = [ "addr2line", - "cc", "cfg-if", "cpp_demangle", "dylib-dep", diff --git a/Cargo.toml b/Cargo.toml index f456d2696..54e6b74ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ name = "backtrace" version = "0.3.73" authors = ["The Rust Project Developers"] -build = "build.rs" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rust-lang/backtrace-rs" @@ -49,11 +48,6 @@ version = "0.36.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] -[build-dependencies] -# Only needed for Android, but cannot be target dependent -# https://github.com/rust-lang/cargo/issues/4932 -cc = "1.0.97" - [dev-dependencies] dylib-dep = { path = "crates/dylib-dep" } libloading = "0.7" diff --git a/build.rs b/build.rs deleted file mode 100644 index 2a3da849f..000000000 --- a/build.rs +++ /dev/null @@ -1,55 +0,0 @@ -extern crate cc; - -use std::env; -use std::path::Path; - -// Must be public so the build script of `std` can call it. -pub fn main() { - match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() { - "android" => build_android(), - _ => {} - } -} - -// Used to detect the value of the `__ANDROID_API__` -// builtin #define -const MARKER: &str = "BACKTRACE_RS_ANDROID_APIVERSION"; -const ANDROID_API_C: &str = " -BACKTRACE_RS_ANDROID_APIVERSION __ANDROID_API__ -"; - -fn build_android() { - // Create `android-api.c` on demand. - // Required to support calling this from the `std` build script. - let out_dir = env::var_os("OUT_DIR").unwrap(); - let android_api_c = Path::new(&out_dir).join("android-api.c"); - std::fs::write(&android_api_c, ANDROID_API_C).unwrap(); - - let expansion = match cc::Build::new().file(&android_api_c).try_expand() { - Ok(result) => result, - Err(e) => { - eprintln!("warning: android version detection failed while running C compiler: {e}"); - return; - } - }; - let expansion = match std::str::from_utf8(&expansion) { - Ok(s) => s, - Err(_) => return, - }; - eprintln!("expanded android version detection:\n{expansion}"); - let i = match expansion.find(MARKER) { - Some(i) => i, - None => return, - }; - let version = match expansion[i + MARKER.len() + 1..].split_whitespace().next() { - Some(s) => s, - None => return, - }; - let version = match version.parse::() { - Ok(n) => n, - Err(_) => return, - }; - if version >= 21 { - println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\""); - } -} diff --git a/ci/android-ndk.sh b/ci/android-ndk.sh index 38521daf1..4072a46c9 100755 --- a/ci/android-ndk.sh +++ b/ci/android-ndk.sh @@ -1,7 +1,7 @@ set -ex ANDROID_NDK_URL=https://dl.google.com/android/repository -ANDROID_NDK_ARCHIVE=android-ndk-r25b-linux.zip +ANDROID_NDK_ARCHIVE=android-ndk-r26d-linux.zip mkdir /android-toolchain cd /android-toolchain diff --git a/ci/docker/arm-linux-androideabi/Dockerfile b/ci/docker/arm-linux-androideabi/Dockerfile index 7471dcb73..313236fd2 100644 --- a/ci/docker/arm-linux-androideabi/Dockerfile +++ b/ci/docker/arm-linux-androideabi/Dockerfile @@ -14,5 +14,5 @@ RUN /android-ndk.sh ENV PATH=$PATH:/android-toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin # TODO: run tests in an emulator eventually -ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi19-clang \ +ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang \ CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER=echo diff --git a/ci/docker/armv7-linux-androideabi/Dockerfile b/ci/docker/armv7-linux-androideabi/Dockerfile index 543fcd243..89e64ac27 100644 --- a/ci/docker/armv7-linux-androideabi/Dockerfile +++ b/ci/docker/armv7-linux-androideabi/Dockerfile @@ -14,5 +14,5 @@ RUN /android-ndk.sh ENV PATH=$PATH:/android-toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin # TODO: run tests in an emulator eventually -ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi19-clang \ +ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang \ CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER=echo diff --git a/ci/docker/i686-linux-android/Dockerfile b/ci/docker/i686-linux-android/Dockerfile index 61cb9d075..7810b39ee 100644 --- a/ci/docker/i686-linux-android/Dockerfile +++ b/ci/docker/i686-linux-android/Dockerfile @@ -14,5 +14,5 @@ RUN /android-ndk.sh ENV PATH=$PATH:/android-toolchain/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin # TODO: run tests in an emulator eventually -ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android19-clang \ +ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android21-clang \ CARGO_TARGET_I686_LINUX_ANDROID_RUNNER=echo diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index 71001666c..1c39fc1de 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -28,7 +28,6 @@ features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] [build-dependencies] # Dependency of the `backtrace` crate -cc = "1.0.97" windows-bindgen = "0.56" [features] diff --git a/crates/as-if-std/build.rs b/crates/as-if-std/build.rs index 7669f555d..7018b1017 100644 --- a/crates/as-if-std/build.rs +++ b/crates/as-if-std/build.rs @@ -1,11 +1,3 @@ -// backtrace-rs requires a feature check on Android targets, so -// we need to run its build.rs as well. -#[allow(unused_extern_crates)] -#[path = "../../build.rs"] -mod backtrace_build_rs; - fn main() { println!("cargo:rustc-cfg=backtrace_in_libstd"); - - backtrace_build_rs::main(); } diff --git a/src/symbolize/gimli.rs b/src/symbolize/gimli.rs index 7465f755c..684705e2a 100644 --- a/src/symbolize/gimli.rs +++ b/src/symbolize/gimli.rs @@ -100,7 +100,7 @@ impl Mapping { // only borrow `map` and `stash` and we're preserving them below. cx: unsafe { core::mem::transmute::, Context<'static>>(cx) }, _map: data, - stash: stash, + stash, }) } } @@ -122,13 +122,11 @@ impl<'data> Context<'data> { if cfg!(not(target_os = "aix")) { let data = object.section(stash, id.name()).unwrap_or(&[]); Ok(EndianSlice::new(data, Endian)) + } else if let Some(name) = id.xcoff_name() { + let data = object.section(stash, name).unwrap_or(&[]); + Ok(EndianSlice::new(data, Endian)) } else { - if let Some(name) = id.xcoff_name() { - let data = object.section(stash, name).unwrap_or(&[]); - Ok(EndianSlice::new(data, Endian)) - } else { - Ok(EndianSlice::new(&[], Endian)) - } + Ok(EndianSlice::new(&[], Endian)) } }) .ok()?; @@ -226,7 +224,7 @@ cfg_if::cfg_if! { target_os = "hurd", target_os = "openbsd", target_os = "netbsd", - all(target_os = "android", feature = "dl_iterate_phdr"), + target_os = "android", ), not(target_env = "uclibc"), ))] {