diff --git a/build.rs b/build.rs index 812fbb1fe..9bd3abd16 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,10 @@ extern crate cc; use std::env; +use std::path::Path; -fn main() { +// 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(), _ => {} @@ -10,7 +12,13 @@ fn main() { } fn build_android() { - let expansion = match cc::Build::new().file("src/android-api.c").try_expand() { + // 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); diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index 012e60f8f..59eedc506 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -24,6 +24,10 @@ default-features = false optional = true features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] +[build-dependencies] +# Dependency of the `backtrace` crate +cc = "1.0.67" + [features] default = ['backtrace'] backtrace = ['addr2line', 'object'] diff --git a/crates/as-if-std/build.rs b/crates/as-if-std/build.rs index 7018b1017..7669f555d 100644 --- a/crates/as-if-std/build.rs +++ b/crates/as-if-std/build.rs @@ -1,3 +1,11 @@ +// backtrace-rs requires a feature check on Android targets, so +// we need to run its build.rs as well. +#[allow(unused_extern_crates)] +#[path = "../../build.rs"] +mod backtrace_build_rs; + fn main() { println!("cargo:rustc-cfg=backtrace_in_libstd"); + + backtrace_build_rs::main(); }