Skip to content

Commit

Permalink
rust bindings: Do not unnecessarily re-run build.rs (microsoft#17018)
Browse files Browse the repository at this point in the history
### Description

Remove unnecessary cargo:rerun-if-changed declaration.

### Motivation and Context

'cargo:rerun-if-changed' declarations tell Cargo when to re-run the
build script. The intention is that if the build script depends on other
files, then Cargo knows to re-run if those files change. It stores the
output and checks it before each build. The intention is that one emits
the declarations for _inputs_ of the build.

This rerun-if-changed declaration is a declaration on the _output_ of
the build, and stores the absolute path of the output. This is not a
useful declaration because the output path is unique to the build script
- there is no way for anything else to change it.

However, this does generate unnecessary rebuilds in some cases, for
example if the dependent repository is moved in the filesystem. This
causes me some issues when using https://crane.dev, as due to some
implementation details, if a crate being moved triggers a rebuild, by
default the build is broken.

To summarise:
- declaration is redundant
- causes issues in niche cases.
  • Loading branch information
j-baker authored and kleiti committed Mar 22, 2024
1 parent 3b76993 commit 6b75cd3
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion rust/onnxruntime-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ fn generate_bindings(include_dir: &Path) {
.expect("Unable to generate bindings");

let generated_file = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
println!("cargo:rerun-if-changed={:?}", generated_file);
bindings
.write_to_file(&generated_file)
.expect("Couldn't write bindings!");
Expand Down

0 comments on commit 6b75cd3

Please sign in to comment.