From 8b71cb9187bfd0e046c526adcdc2924482b70526 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 12 Aug 2023 12:38:34 -0600 Subject: [PATCH 1/2] Enable calling build.rs directly from std/build.rs --- build.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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); From b90a10505fd6158a0679b99a4220d130d7df8929 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 12 Aug 2023 13:12:11 -0600 Subject: [PATCH 2/2] Call buildscript in `as-if-std` buildscript To test that it will work in the `std` buildscript --- crates/as-if-std/Cargo.toml | 4 ++++ crates/as-if-std/build.rs | 8 ++++++++ 2 files changed, 12 insertions(+) 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(); }