Skip to content

Commit b75d868

Browse files
committed
wip: Android support in gimli
1 parent c6e5bff commit b75d868

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "backtrace"
33
version = "0.3.56"
44
authors = ["The Rust Project Developers"]
5+
build = "build.rs"
56
license = "MIT/Apache-2.0"
67
readme = "README.md"
78
repository = "https://github.com/rust-lang/backtrace-rs"
@@ -22,7 +23,7 @@ exclude = ['crates/without_debuginfo', 'crates/macos_frames_test', 'crates/line-
2223
cfg-if = "1.0"
2324
rustc-demangle = "0.1.4"
2425
backtrace-sys = { path = "crates/backtrace-sys", version = "0.1.35", optional = true, default_features = false }
25-
libc = { version = "0.2.87", default-features = false }
26+
libc = { git = "https://github.com/kjvalencik/libc", default-features = false }
2627

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

50+
[build-dependencies]
51+
# Only needed for Android, but cannot be target dependent
52+
# https://github.com/rust-lang/cargo/issues/4932
53+
cc = "1.0.67"
54+
4955
[dev-dependencies]
5056
dylib-dep = { path = "crates/dylib-dep" }
5157
libloading = "0.6"

build.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
extern crate cc;
2+
3+
use std::env;
4+
5+
fn main() {
6+
match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() {
7+
"android" => build_android(),
8+
_ => {}
9+
}
10+
}
11+
12+
fn build_android() {
13+
let expansion = cc::Build::new().file("src/android-api.c").expand();
14+
let expansion = match std::str::from_utf8(&expansion) {
15+
Ok(s) => s,
16+
Err(_) => return,
17+
};
18+
println!("expanded android version detection:\n{}", expansion);
19+
let marker = "APIVERSION";
20+
let i = match expansion.find(marker) {
21+
Some(i) => i,
22+
None => return,
23+
};
24+
let version = match expansion[i + marker.len() + 1..].split_whitespace().next() {
25+
Some(s) => s,
26+
None => return,
27+
};
28+
let version = match version.parse::<u32>() {
29+
Ok(n) => n,
30+
Err(_) => return,
31+
};
32+
if version >= 21 {
33+
println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\"");
34+
}
35+
}

src/android-api.c

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Used from the build script to detect the value of the `__ANDROID_API__`
2+
// builtin #define
3+
4+
APIVERSION __ANDROID_API__

src/symbolize/gimli.rs

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ cfg_if::cfg_if! {
364364
target_os = "linux",
365365
target_os = "fuchsia",
366366
target_os = "freebsd",
367+
all(target_os = "android", feature = "dl_iterate_phdr"),
367368
),
368369
not(target_env = "uclibc"),
369370
))] {

0 commit comments

Comments
 (0)