Skip to content

Fix a couple of build caching issues - #76

Merged
msakrejda merged 1 commit into
mainfrom
improve-build-caching
Mar 18, 2026
Merged

Fix a couple of build caching issues#76
msakrejda merged 1 commit into
mainfrom
improve-build-caching

Conversation

@msakrejda

Copy link
Copy Markdown
Contributor
  • Avoid overwriting src/protobuf.rs if it has not changed
  • Avoid unconditionally copying some libpg_query files to outdir

Both of these inadvertently break build caching.

Note on AI use: Claude tracked down the problem and drafted the fix with some guidance.

 - Avoid overwriting src/protobuf.rs if it has not changed
 - Avoid unconditionally copying some libpg_query files to outdir

Both of these inadvertently break build caching.
@msakrejda
msakrejda requested a review from a team March 18, 2026 06:28
Comment thread build.rs
Comment on lines 23 to +37
@@ -28,9 +32,15 @@
build_path.join("vendor"),
];

let copy_options = CopyOptions { overwrite: true, ..CopyOptions::default() };
let hash_file = out_dir.join(".source_hash");
let current_hash = hash_source_paths(&source_paths);
let cached_hash = std::fs::read_to_string(&hash_file).unwrap_or_default();

@msakrejda msakrejda Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this approach, but to fix the build caching issues, we need some way to avoid overwriting the files if they have not changed. Although, I'm not sure why it's necessary: these files are just going to outdir. I'm not sure why Cargo cares that they're newer than expected.

Comment thread build.rs
if path.is_file() {
if let Ok(contents) = std::fs::read(path) {
hasher.write(path.to_string_lossy().as_bytes());
hasher.write(&contents);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How slow is this? If it's slow it may be acceptable to just hash the file name + last modified timestamp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but that could cause issues with switching branches. The whole hashing step takes 20-25ms here, so I don't think we need to worry about it.

Comment thread build.rs
let out_protobuf_path = out_dir.join("protobuf");
let target = env::var("TARGET").unwrap();

println!("cargo:rerun-if-changed=libpg_query");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible this could include the submodule's git files, so any git operation inside the submodule might invalidate the cache. It doesn't have to be part of this PR, but it might make sense to make this call use source_paths as an input (calling it once for each path).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, most git operations would also result in changes to the actual input files, no? No objections to doing that, but I think the changes here should greatly improve caching in the common case.

@msakrejda
msakrejda merged commit 7e189a9 into main Mar 18, 2026
7 checks passed
@msakrejda
msakrejda deleted the improve-build-caching branch March 18, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants