Skip to content

Commit beaff3f

Browse files
committed
build: Use rerun-if-env-changed instruction for variables we use
We make use of several environment variables, e.g. `CC`, `CXXSTDLIB`, `LLVM_PREFIX`. However, changing these variables was not triggering a re-run of the build script. Fix that by using `rerun-if-env-changed`.
1 parent 7862791 commit beaff3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ macro_rules! write_bytes {
3737
};
3838
}
3939

40+
const CXXSTDLIB: &str = "CXXSTDLIB";
41+
4042
enum Cxxstdlibs<'a> {
4143
EnvVar(OsString),
4244
Single(&'static [u8]),
@@ -46,7 +48,7 @@ enum Cxxstdlibs<'a> {
4648
impl Cxxstdlibs<'_> {
4749
/// Detects which standard C++ library to link.
4850
fn new() -> Self {
49-
match env::var_os("CXXSTDLIB") {
51+
match env::var_os(CXXSTDLIB) {
5052
Some(cxxstdlib) => Self::EnvVar(cxxstdlib),
5153
None => {
5254
if cfg!(target_os = "linux") {
@@ -144,6 +146,7 @@ fn emit_search_path_if_defined(
144146
stdout: &mut io::StdoutLock<'_>,
145147
env_var: &str,
146148
) -> anyhow::Result<bool> {
149+
writeln!(stdout, "cargo:rerun-if-env-changed={env_var}")?;
147150
match env::var_os(env_var) {
148151
Some(path) => {
149152
write_bytes!(
@@ -243,6 +246,7 @@ fn link_llvm_static(stdout: &mut io::StdoutLock<'_>, llvm_lib_dir: &Path) -> any
243246
}
244247
}
245248

249+
writeln!(stdout, "cargo:rerun-if-env-changed={CXXSTDLIB}")?;
246250
let cxxstdlibs = Cxxstdlibs::new();
247251

248252
// Find directories with static libraries we're interested in:
@@ -265,6 +269,8 @@ fn link_llvm_static(stdout: &mut io::StdoutLock<'_>, llvm_lib_dir: &Path) -> any
265269
// `-print-search-dirs` option.
266270
const CC: &str = "CC";
267271
const RUSTC_LINKER: &str = "RUSTC_LINKER";
272+
writeln!(stdout, "cargo:rerun-if-env-changed={CC}")?;
273+
writeln!(stdout, "cargo:rerun-if-env-changed={RUSTC_LINKER}")?;
268274
/// Executes `maybe_cc` with `-print-search-dirs` argument. On success,
269275
/// returns the output.
270276
fn print_search_dirs<'a>(
@@ -532,6 +538,8 @@ fn main() -> anyhow::Result<()> {
532538
// lives.
533539
const LLVM_PREFIX: &str = "LLVM_PREFIX";
534540
const PATH: &str = "PATH";
541+
writeln!(stdout, "cargo:rerun-if-env-changed={LLVM_PREFIX}")?;
542+
writeln!(stdout, "cargo:rerun-if-env-changed={PATH}")?;
535543
let (var_name, paths_os) = env::var_os(LLVM_PREFIX)
536544
.map(|mut p| {
537545
p.push("/bin");

0 commit comments

Comments
 (0)