aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-12-29 20:32:39 -0800
committerHaibo Huang <hhb@google.com>2020-12-29 20:32:39 -0800
commitfb10bbc2d3d81849996d1e93c30a161a29eac663 (patch)
tree1309b4d74cfbc28a49e77d3e8f41d3d991335d6f /build.rs
parent508dd7d7ef2aa2311a399ac13484ed84aa62c81b (diff)
downloadanyhow-fb10bbc2d3d81849996d1e93c30a161a29eac663.tar.gz
Upgrade rust/crates/anyhow to 1.0.37
Test: make Change-Id: Ibc6ae300f243375e5d9c9f6874f87e32c817c943
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs30
1 files changed, 25 insertions, 5 deletions
diff --git a/build.rs b/build.rs
index d20b072..a7dc8f2 100644
--- a/build.rs
+++ b/build.rs
@@ -2,6 +2,7 @@ use std::env;
use std::fs;
use std::path::Path;
use std::process::{Command, ExitStatus, Stdio};
+use std::str;
// This code exercises the surface area that we expect of the std Backtrace
// type. If the current toolchain is able to compile it, we go ahead and use
@@ -35,12 +36,20 @@ const PROBE: &str = r#"
"#;
fn main() {
- if !cfg!(feature = "std") {
- return;
+ if cfg!(feature = "std") {
+ match compile_probe() {
+ Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),
+ _ => {}
+ }
}
- match compile_probe() {
- Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),
- _ => {}
+
+ let rustc = match rustc_minor_version() {
+ Some(rustc) => rustc,
+ None => return,
+ };
+
+ if rustc < 38 {
+ println!("cargo:rustc-cfg=anyhow_no_macro_reexport");
}
}
@@ -61,3 +70,14 @@ fn compile_probe() -> Option<ExitStatus> {
.status()
.ok()
}
+
+fn rustc_minor_version() -> Option<u32> {
+ let rustc = env::var_os("RUSTC")?;
+ let output = Command::new(rustc).arg("--version").output().ok()?;
+ let version = str::from_utf8(&output.stdout).ok()?;
+ let mut pieces = version.split('.');
+ if pieces.next() != Some("rustc 1") {
+ return None;
+ }
+ pieces.next()?.parse().ok()
+}