summaryrefslogtreecommitdiffstats
path: root/vendor/backtrace/build.rs
blob: 9bd3abd165bc04b750f8c34bd9876d655a0abd28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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(),
        _ => {}
    }
}

fn build_android() {
    // Resolve `src/android-api.c` relative to this file.
    // Required to support calling this from the `std` build script.
    let android_api_c = Path::new(file!())
        .parent()
        .unwrap()
        .join("src/android-api.c");
    let expansion = match cc::Build::new().file(android_api_c).try_expand() {
        Ok(result) => result,
        Err(e) => {
            println!("failed to run C compiler: {}", e);
            return;
        }
    };
    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\"");
    }
}