Skip to content

Commit b1590b1

Browse files
committed
Require cargo promised environment variables to be present
1 parent 15646f4 commit b1590b1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

build.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![allow(clippy::option_if_let_else)]
22

33
use std::env;
4+
use std::ffi::OsString;
45
use std::path::Path;
5-
use std::process::{Command, ExitStatus, Stdio};
6+
use std::process::{self, Command, ExitStatus, Stdio};
67
use std::str;
78

89
#[cfg(all(feature = "backtrace", not(feature = "std")))]
@@ -66,8 +67,8 @@ fn compile_probe() -> Option<ExitStatus> {
6667
return None;
6768
}
6869

69-
let rustc = env::var_os("RUSTC")?;
70-
let out_dir = env::var_os("OUT_DIR")?;
70+
let rustc = cargo_env_var("RUSTC");
71+
let out_dir = cargo_env_var("OUT_DIR");
7172
let probefile = Path::new("build").join("probe.rs");
7273

7374
// Make sure to pick up Cargo rustc configuration.
@@ -115,3 +116,13 @@ fn rustc_minor_version() -> Option<u32> {
115116
}
116117
pieces.next()?.parse().ok()
117118
}
119+
120+
fn cargo_env_var(key: &str) -> OsString {
121+
env::var_os(key).unwrap_or_else(|| {
122+
eprintln!(
123+
"Environment variable ${} is not set during execution of build script",
124+
key,
125+
);
126+
process::exit(1);
127+
})
128+
}

0 commit comments

Comments
 (0)