From 986c2119e64229839c05932d269fe5d8211579c1 Mon Sep 17 00:00:00 2001 From: Arc-blroth <45273859+Arc-blroth@users.noreply.github.com> Date: Thu, 28 Jul 2022 17:06:45 -0700 Subject: [PATCH 1/2] Invoke `backtrace-rs`' buildscript in `std`'s buildscript --- library/std/build.rs | 16 ++++++++++++++++ library/std/src/android-api.c | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 library/std/src/android-api.c diff --git a/library/std/build.rs b/library/std/build.rs index 8b1a06ee750fb..718fe79fcf409 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -1,5 +1,19 @@ use std::env; +// backtrace-rs requires a feature check on Android targets, so +// we need to run its build.rs as well. Note that we use an +// include! rather than #[path = ""] because backtrace-rs's main +// function is private. +#[allow(unused_extern_crates)] +mod backtrace_rs_build_rs { + include!("../backtrace/build.rs"); + + #[inline] + pub fn call_main() { + main(); + } +} + fn main() { println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").expect("TARGET was not set"); @@ -49,4 +63,6 @@ fn main() { } println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); println!("cargo:rustc-cfg=backtrace_in_libstd"); + + backtrace_rs_build_rs::call_main(); } diff --git a/library/std/src/android-api.c b/library/std/src/android-api.c new file mode 100644 index 0000000000000..4e9f91395aabc --- /dev/null +++ b/library/std/src/android-api.c @@ -0,0 +1,4 @@ +// Used from backtrace-rs' build script to detect the value of the `__ANDROID_API__` +// builtin #define + +APIVERSION __ANDROID_API__ From 5e8e7f40b18abd6f36455c5bbaf3b79f49c4f34c Mon Sep 17 00:00:00 2001 From: Arc-blroth <45273859+Arc-blroth@users.noreply.github.com> Date: Thu, 28 Jul 2022 18:51:32 -0700 Subject: [PATCH 2/2] add cc build dependency for backtrace support in std (i forgot to git add this whoops) --- Cargo.lock | 1 + library/std/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 2325d0f3bf263..0ac4ddcd85ee7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5042,6 +5042,7 @@ version = "0.0.0" dependencies = [ "addr2line 0.16.0", "alloc", + "cc", "cfg-if 0.1.10", "compiler_builtins", "core", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 229e546e08549..89a0816a1a7ac 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -35,6 +35,10 @@ features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] [dev-dependencies] rand = "0.7" +[build-dependencies] +# Dependency of the `backtrace` crate +cc = "1.0.67" + [target.'cfg(any(all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies] dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }