Skip to content

Commit

Permalink
Rerun cbindgen on changes to src (#7708)
Browse files Browse the repository at this point in the history
Currently, if you only modify a signature in src, and don't otherwise
happen to modify native.py, we won't rerun cbindgen, and you'll get an
error that the Python and Rust code had different expectations.
  • Loading branch information
illicitonion authored May 13, 2019
1 parent fac27b8 commit 55529b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ crate-type = ["cdylib"]
build_utils = { path = "build_utils" }
cbindgen = "0.6.7"
cc = "1.0"
walkdir = "2"

[workspace]
# These are the packages which are built/tested when the --all flag is passed to cargo.
Expand Down
24 changes: 17 additions & 7 deletions src/rust/engine/src/cffi_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fn main() -> Result<(), CffiBuildError> {
// Generate the scheduler.h bindings from the rust code in this crate.
let bindings_config_path = Path::new("cbindgen.toml");
mark_for_change_detection(&bindings_config_path);
mark_for_change_detection(Path::new("src"));

let scheduler_file_path = Path::new("src/cffi/scheduler.h");
let crate_dir = env::var("CARGO_MANIFEST_DIR")?;
Expand All @@ -134,13 +135,7 @@ fn main() -> Result<(), CffiBuildError> {
// changed and avoid rebuilding the engine crate if we are just iterating on the implementations.
mark_for_change_detection(&build_root.join("src/python/pants/engine/native.py"));

// N.B. The filename of this source code - at generation time - must line up 1:1 with the
// python import name, as python keys the initialization function name off of the import name.
let cffi_dir = Path::new("src/cffi");
let c_path = cffi_dir.join("native_engine.c");
mark_for_change_detection(&c_path);
let env_script_path = cffi_dir.join("native_engine.cflags");
mark_for_change_detection(&env_script_path);

let result = Command::new(&cffi_bootstrapper)
.arg(cffi_dir)
Expand All @@ -155,6 +150,13 @@ fn main() -> Result<(), CffiBuildError> {
exit(exit_code.unwrap_or(1));
}

// N.B. The filename of this source code - at generation time - must line up 1:1 with the
// python import name, as python keys the initialization function name off of the import name.
let c_path = cffi_dir.join("native_engine.c");
mark_for_change_detection(&c_path);
let env_script_path = cffi_dir.join("native_engine.cflags");
mark_for_change_detection(&env_script_path);

// Now compile the cffi c sources.
let mut config = cc::Build::new();

Expand All @@ -175,7 +177,15 @@ fn main() -> Result<(), CffiBuildError> {
fn mark_for_change_detection(path: &Path) {
// Restrict re-compilation check to just our input files.
// See: http://doc.crates.io/build-script.html#outputs-of-the-build-script
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
if !path.exists() {
panic!(
"Cannot mark non-existing path for change detection: {}",
path.display()
);
}
for file in walkdir::WalkDir::new(path) {
println!("cargo:rerun-if-changed={}", file.unwrap().path().display());
}
}

fn make_flags(env_script_path: &Path) -> Result<Vec<String>, io::Error> {
Expand Down

0 comments on commit 55529b0

Please sign in to comment.