-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Recently I noticed that "cargo::rerun-if-changed" has stopped working properly. To be specific, in the past, when the files marked with "cargo::rerun-if-changed" didn't change, then the build.rs script wouldn't run. But recently I updated to Rust 1.88.0 and noticed that build.rs keeps getting run on every "cargo build" or "cargo check", and only the target compilation seems to be skipped. I haven't seen anything related to this in the documentation. Is this a regression?
Code
I tried this code:
Cargo.toml
[package]
name = "test-build"
version = "0.1.0"
edition = "2021"
[lib]
path = "lib.rs"
lib.rs
// Test library
pub fn hello() -> &'static str {
"Hello from test-build!"
}
build.rs
fn main() {
println!("cargo::warning=BUILD SCRIPT RUNNING - {}", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs());
println!("cargo::rerun-if-changed=build.rs");
}
I expected to see this happen:
When I run "cargo build", I expect build.rs to run and print "BUILD SCRIPT RUNNING" and then the lib.rs file to be compiled.
When I run "cargo build" a second time, given that I've made no changes at all, I'm expecting build.rs not to run and no "BUILD SCRIPT RUNNING" being printed, and the compilation to be skipped.
Instead, this happened: explanation
When I run "cargo build", I expect build.rs to run and print "BUILD SCRIPT RUNNING" and then the lib.rs file to be compiled.
When I run "cargo build" a second time, build.rs IS being run and showing "BUILD SCRIPT RUNNING" , and the compilation is skipped afterwards.
Version it worked on
It most recently worked on: (Not 100% sure) 1.86?
Version with regression
rustc --version --verbose
:
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-pc-windows-msvc
release: 1.88.0
LLVM version: 20.1.5