Skip to content

Commit 5bcc730

Browse files
TheZoq2messense
andauthored
Fix unnecessary rebuilds due to pyo3 config file modified time change (#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]>
1 parent feeb8f4 commit 5bcc730

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/compile.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,17 @@ fn cargo_build_command(
441441
target_triple, interpreter.major, interpreter.minor
442442
));
443443
fs::create_dir_all(&maturin_target_dir)?;
444-
fs::write(&config_file, pyo3_config).with_context(|| {
445-
format!(
446-
"Failed to create pyo3 config file at '{}'",
447-
config_file.display()
448-
)
449-
})?;
444+
// We don't want to rewrite the file every time as that will make cargo
445+
// trigger a rebuild of the project every time
446+
let existing_pyo3_config = fs::read_to_string(&config_file).unwrap_or_default();
447+
if pyo3_config != existing_pyo3_config {
448+
fs::write(&config_file, pyo3_config).with_context(|| {
449+
format!(
450+
"Failed to create pyo3 config file at '{}'",
451+
config_file.display()
452+
)
453+
})?;
454+
}
450455
let abs_config_file = config_file.normalize()?.into_path_buf();
451456
build_command.env("PYO3_CONFIG_FILE", abs_config_file);
452457
}

0 commit comments

Comments
 (0)