File: build.rs

package info (click to toggle)
rust-findshlibs 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download
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
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 = match cc::Build::new().file("src/android-api.c").try_expand() {
        Ok(result) => result,
        Err(e) => {
            println!("cargo:warning=failed to run C compiler: {}", e);
            return;
        }
    };

    let expansion = match std::str::from_utf8(&expansion) {
        Ok(s) => s,
        Err(_) => return,
    };

    let marker = "APIVERSION";
    let i = expansion.find(marker).unwrap_or_default();

    let version = expansion[i + marker.len() + 1..]
        .split_whitespace()
        .next()
        .unwrap_or("");
    let version = version.parse::<u32>().unwrap_or_else(|_| {
        println!("cargo:warning=failed to get android api version.");
        0
    });

    if version >= 21 {
        println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\"");
    }
}