Skip to content

Commit

Permalink
hotfix: fix minion and chuffed always rebuilding
Browse files Browse the repository at this point in the history
We were using the .parse_callbacks(Box::new(bindgen::CargoCallbacks))
option of bindgen to invalidate the build based on included files.

We always re-run ./configure in build.sh - this was invalidating the
build because the configure script updates the last modified timestamps
of generated headerfiles, even if the file contents themselves have not
changed.

We already rebuild on C++ changes as both chuffed and minion have
rerun-if-changed=vendor, rerun-if-changed=wrapper.h added manually.
Therefore, the bindgen functionality that does this is not needed. We
can assume if vendor/ has changed, then the configure generated headers
have changed - we do not need to track these directly.
  • Loading branch information
niklasdewally committed Nov 28, 2023
1 parent a3df7f4 commit 73877ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
3 changes: 0 additions & 3 deletions solvers/chuffed/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ fn bind() {
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Must manually give allow list to stop bindgen accidentally binding something complicated
// in C++ stdlib that will make it crash.
.allowlist_function("createVars")
Expand Down
9 changes: 3 additions & 6 deletions solvers/minion/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use std::process::Command;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();

println!("cargo:rustc-link-search=all={}/build", out_dir);
println!("cargo:rustc-link-lib=static=minion");
println!("cargo:rerun-if-changed=vendor");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=build.sh");

println!("cargo:rustc-link-search=all={}/build", out_dir);
println!("cargo:rustc-link-lib=static=minion");
build();

// also need to (dynamically) link to c++ stdlib
// https://flames-of-code.netlify.app/blog/rust-and-cmake-cplusplus/
Expand All @@ -31,7 +32,6 @@ fn main() {
unimplemented!();
}

build();
bind();
}

Expand Down Expand Up @@ -63,9 +63,6 @@ fn bind() {
// The input header we would like to generate
// bindings for.
.header("vendor/minion/libwrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Make all templates opaque as reccomended by bindgen
.opaque_type("std::.*")
// Manually allow C++ functions to stop bindgen getting confused.
Expand Down

0 comments on commit 73877ea

Please sign in to comment.