From 3906e9a4ffa36611e70c6c2825322b4c5ff4c38e Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Sat, 12 Aug 2023 13:00:05 -0600
Subject: [PATCH] Invoke `backtrace-rs` buildscript in `std` buildscript
Based on #99883 by @Arc-blroth
Depends on rust-lang/backtrace-rs#556 and rust-lang/cc-rs#705
---
Cargo.lock | 1 +
library/std/Cargo.toml | 4 ++++
library/std/build.rs | 8 ++++++++
3 files changed, 13 insertions(+)
diff --git a/Cargo.lock b/Cargo.lock
index de6258502a3c2..cb6d4811c8ea3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4862,6 +4862,7 @@ version = "0.0.0"
dependencies = [
"addr2line",
"alloc",
+ "cc",
"cfg-if",
"compiler_builtins",
"core",
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
index 5b213555394d8..5057d51eb3715 100644
--- a/library/std/Cargo.toml
+++ b/library/std/Cargo.toml
@@ -36,6 +36,10 @@ object = { version = "0.31.1", default-features = false, optional = true, featur
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
rand_xorshift = "0.3.0"
+[build-dependencies]
+# Dependency of the `backtrace` crate
+cc = "1.0.67"
+
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
diff --git a/library/std/build.rs b/library/std/build.rs
index ddf6e84d8d035..7bd17f42277a4 100644
--- a/library/std/build.rs
+++ b/library/std/build.rs
@@ -1,5 +1,11 @@
use std::env;
+// backtrace-rs requires a feature check on Android targets, so
+// we need to run its build.rs as well.
+#[allow(unused_extern_crates)]
+#[path = "../backtrace/build.rs"]
+mod backtrace_build_rs;
+
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let target = env::var("TARGET").expect("TARGET was not set");
@@ -56,4 +62,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_build_rs::main();
}