Skip to content

Commit

Permalink
Add Android support to gimli (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Apr 26, 2021
1 parent 21c9b47 commit 6b13969
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
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

0 comments on commit 6b13969

Please sign in to comment.