aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs38
1 files changed, 28 insertions, 10 deletions
diff --git a/build.rs b/build.rs
index cd79927..3800683 100644
--- a/build.rs
+++ b/build.rs
@@ -15,15 +15,17 @@ compile_error! {
// type. If the current toolchain is able to compile it, we go ahead and use
// backtrace in anyhow.
const PROBE: &str = r#"
- #![feature(backtrace)]
- #![allow(dead_code)]
+ #![feature(error_generic_member_access, provide_any)]
+ use std::any::{Demand, Provider};
use std::backtrace::{Backtrace, BacktraceStatus};
use std::error::Error;
use std::fmt::{self, Display};
#[derive(Debug)]
- struct E;
+ struct E {
+ backtrace: Backtrace,
+ }
impl Display for E {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -32,14 +34,26 @@ const PROBE: &str = r#"
}
impl Error for E {
- fn backtrace(&self) -> Option<&Backtrace> {
- let backtrace = Backtrace::capture();
- match backtrace.status() {
- BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {}
- }
- unimplemented!()
+ fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
+ demand.provide_ref(&self.backtrace);
}
}
+
+ struct P;
+
+ impl Provider for P {
+ fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {}
+ }
+
+ const _: fn() = || {
+ let backtrace: Backtrace = Backtrace::capture();
+ let status: BacktraceStatus = backtrace.status();
+ match status {
+ BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {}
+ }
+ };
+
+ const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>();
"#;
fn main() {
@@ -71,7 +85,7 @@ fn compile_probe() -> Option<ExitStatus> {
fs::write(&probefile, PROBE).ok()?;
// Make sure to pick up Cargo rustc configuration.
- let mut cmd = if let Some(wrapper) = env::var_os("CARGO_RUSTC_WRAPPER") {
+ let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") {
let mut cmd = Command::new(wrapper);
// The wrapper's first argument is supposed to be the path to rustc.
cmd.arg(rustc);
@@ -89,6 +103,10 @@ fn compile_probe() -> Option<ExitStatus> {
.arg(out_dir)
.arg(probefile);
+ if let Some(target) = env::var_os("TARGET") {
+ cmd.arg("--target").arg(target);
+ }
+
// If Cargo wants to set RUSTFLAGS, use that.
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {