Skip to content

Commit

Permalink
Fix unnecessary rebuilds due to pyo3 config file modified time change (
Browse files Browse the repository at this point in the history
…#2446)

On some of my computers, maturin build always rebuilds pyo3 and friends,
and looking at the cargo fingerprinting, this is caused by the
py03-config file being written regardless of changes. This only writes
the file if it has changed since last rebuild, which seems to prevent
the problem.

---------

Co-authored-by: messense <[email protected]>
  • Loading branch information
TheZoq2 and messense authored Jan 21, 2025
1 parent feeb8f4 commit 5bcc730
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,17 @@ fn cargo_build_command(
target_triple, interpreter.major, interpreter.minor
));
fs::create_dir_all(&maturin_target_dir)?;
fs::write(&config_file, pyo3_config).with_context(|| {
format!(
"Failed to create pyo3 config file at '{}'",
config_file.display()
)
})?;
// We don't want to rewrite the file every time as that will make cargo
// trigger a rebuild of the project every time
let existing_pyo3_config = fs::read_to_string(&config_file).unwrap_or_default();
if pyo3_config != existing_pyo3_config {
fs::write(&config_file, pyo3_config).with_context(|| {
format!(
"Failed to create pyo3 config file at '{}'",
config_file.display()
)
})?;
}
let abs_config_file = config_file.normalize()?.into_path_buf();
build_command.env("PYO3_CONFIG_FILE", abs_config_file);
}
Expand Down

0 comments on commit 5bcc730

Please sign in to comment.