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 Android support to gimli #415

Merged
merged 1 commit into from
Apr 26, 2021
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
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "backtrace"
version = "0.3.57"
authors = ["The Rust Project Developers"]
build = "build.rs"
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang/backtrace-rs"
Expand All @@ -22,7 +23,7 @@ exclude = ['crates/without_debuginfo', 'crates/macos_frames_test', 'crates/line-
cfg-if = "1.0"
rustc-demangle = "0.1.4"
backtrace-sys = { path = "crates/backtrace-sys", version = "0.1.35", optional = true, default_features = false }
libc = { version = "0.2.87", default-features = false }
libc = { version = "0.2.94", default-features = false }

# Optionally enable the ability to serialize a `Backtrace`, controlled through
# the `serialize-*` features below.
Expand All @@ -46,6 +47,11 @@ features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.3", optional = true }

[build-dependencies]
# Only needed for Android, but cannot be target dependent
# https://github.com/rust-lang/cargo/issues/4932
cc = "1.0.67"

[dev-dependencies]
dylib-dep = { path = "crates/dylib-dep" }
libloading = "0.6"
Expand Down
35 changes: 35 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate cc;

use std::env;

fn main() {
match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() {
"android" => build_android(),
_ => {}
}
}

fn build_android() {
let expansion = cc::Build::new().file("src/android-api.c").expand();
let expansion = match std::str::from_utf8(&expansion) {
Ok(s) => s,
Err(_) => return,
};
println!("expanded android version detection:\n{}", expansion);
let marker = "APIVERSION";
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::<u32>() {
Ok(n) => n,
Err(_) => return,
};
if version >= 21 {
println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\"");
}
}
4 changes: 4 additions & 0 deletions src/android-api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Used from the build script to detect the value of the `__ANDROID_API__`
// builtin #define

APIVERSION __ANDROID_API__
1 change: 1 addition & 0 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ cfg_if::cfg_if! {
target_os = "linux",
target_os = "fuchsia",
target_os = "freebsd",
all(target_os = "android", feature = "dl_iterate_phdr"),
),
not(target_env = "uclibc"),
))] {
Expand Down