Skip to content

Commit 784ae2e

Browse files
authored
Merge pull request #428 from dtolnay/cargoenvvar
Require cargo promised environment variables to be present
2 parents 593681b + 8ade7da commit 784ae2e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

build.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
// 1.57+.
3636

3737
use std::env;
38-
use std::process::Command;
38+
use std::ffi::OsString;
39+
use std::process::{self, Command};
3940
use std::str;
4041
use std::u32;
4142

@@ -89,7 +90,7 @@ struct RustcVersion {
8990
}
9091

9192
fn rustc_version() -> Option<RustcVersion> {
92-
let rustc = env::var_os("RUSTC")?;
93+
let rustc = cargo_env_var("RUSTC");
9394
let output = Command::new(rustc).arg("--version").output().ok()?;
9495
let version = str::from_utf8(&output.stdout).ok()?;
9596
let nightly = version.contains("nightly") || version.contains("dev");
@@ -131,3 +132,13 @@ fn feature_allowed(feature: &str) -> bool {
131132
// No allow-features= flag, allowed by default.
132133
true
133134
}
135+
136+
fn cargo_env_var(key: &str) -> OsString {
137+
env::var_os(key).unwrap_or_else(|| {
138+
eprintln!(
139+
"Environment variable ${} is not set during execution of build script",
140+
key,
141+
);
142+
process::exit(1);
143+
})
144+
}

0 commit comments

Comments
 (0)