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

Enable calling build.rs externally v2 #568

Merged
merged 1 commit into from
Oct 5, 2023
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
31 changes: 20 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,40 @@ pub fn main() {
}
}

// Used to detect the value of the `__ANDROID_API__`
// builtin #define
const MARKER: &str = "BACKTRACE_RS_ANDROID_APIVERSION";
const ANDROID_API_C: &str = "
BACKTRACE_RS_ANDROID_APIVERSION __ANDROID_API__
";

fn build_android() {
// Resolve `src/android-api.c` relative to this file.
// Create `android-api.c` on demand.
// 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() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let android_api_c = Path::new(&out_dir).join("android-api.c");
std::fs::write(&android_api_c, ANDROID_API_C).unwrap();

let expansion = match cc::Build::new().file(&android_api_c).try_expand() {
Ok(result) => result,
Err(e) => {
println!("failed to run C compiler: {}", e);
eprintln!(
"warning: android version detection failed while running 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) {
eprintln!("expanded android version detection:\n{}", expansion);
let i = match expansion.find(MARKER) {
Some(i) => i,
None => return,
};
let version = match expansion[i + marker.len() + 1..].split_whitespace().next() {
let version = match expansion[i + MARKER.len() + 1..].split_whitespace().next() {
Some(s) => s,
None => return,
};
Expand Down
4 changes: 0 additions & 4 deletions src/android-api.c

This file was deleted.

Loading