Skip to content

Commit 008c1d9

Browse files
authored
Avoid re-building vortex-duckdb twice (#8035)
## Summary Currently, if you build something like `duckdb-bench` cargo will rebuild `vortex-duckdb` once before it'll be satisfied that it doesn't need to rebuild it. The root cause is that cargo's fingerprinting can't accurately track files that are created **during** the build. This change is fine because we still track our own changes, the only external change will be something like a duckdb version upgrade which will change `build.rs` and re-trigger the build as expected. Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 1d5d234 commit 008c1d9

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

vortex-duckdb/build.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::process::Command;
1414
use std::process::exit;
1515

1616
use bindgen::Abi;
17+
use bindgen::callbacks::ParseCallbacks;
1718

1819
const DUCKDB_RELEASES_URL: &str = "https://github.com/duckdb/duckdb/releases/download";
1920
const DUCKDB_SOURCE_RELEASE_URL: &str = "https://github.com/duckdb/duckdb/archive/refs/tags";
@@ -45,6 +46,26 @@ const SOURCE_FILES: [&str; 17] = [
4546
const DOWNLOAD_MAX_RETRIES: i32 = 3;
4647
const DOWNLOAD_TIMEOUT: u64 = 90;
4748

49+
#[derive(Debug)]
50+
struct BindgenCargoCallbacks;
51+
52+
impl ParseCallbacks for BindgenCargoCallbacks {
53+
fn read_env_var(&self, key: &str) {
54+
println!("cargo:rerun-if-env-changed={key}");
55+
}
56+
57+
fn header_file(&self, filename: &str) {
58+
println!("cargo:rerun-if-changed={filename}");
59+
}
60+
61+
fn include_file(&self, _filename: &str) {
62+
// We do not want to let bindgen add DuckDB headers from OUT_DIR to Cargo's fingerprint.
63+
// Those files are extracted during this build script, so their mtimes are newer than
64+
// Cargo's build-script output timestamp and would force one extra
65+
// rebuild after a clean build.
66+
}
67+
}
68+
4869
#[derive(Debug, Clone)]
4970
enum DuckDBVersion {
5071
Release(String), // i.e. X.Y.Z. Download pre-compiled libraries from GitHub releases.
@@ -306,9 +327,7 @@ fn c2rust(crate_dir: &Path, duckdb_include_dir: &Path) {
306327
.clang_arg(format!("-I{}", duckdb_include_dir.display()))
307328
.clang_arg(format!("-I{}", crate_dir.join("cpp/include").display()))
308329
.generate_comments(true)
309-
// Tell cargo to invalidate the built crate whenever any of the
310-
// included header files changed.
311-
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
330+
.parse_callbacks(Box::new(BindgenCargoCallbacks))
312331
.generate();
313332

314333
let bindings = match bindings {
@@ -339,7 +358,6 @@ fn cpp(duckdb_include_dir: &Path) {
339358
.include("cpp/include")
340359
.files(SOURCE_FILES)
341360
.compile("vortex-duckdb-extras");
342-
// bindgen generates rerun-if-changed for .h/.hpp files
343361
for e in SOURCE_FILES {
344362
println!("cargo:rerun-if-changed={e}");
345363
}
@@ -450,6 +468,7 @@ fn main() {
450468
};
451469

452470
let duckdb_include_dir = inner_dir.join("src").join("include");
471+
println!("cargo:rerun-if-changed=cpp/include");
453472
c2rust(&crate_dir, &duckdb_include_dir);
454473
cpp(&duckdb_include_dir);
455474
rust2c(&crate_dir);

0 commit comments

Comments
 (0)