Skip to content

Commit e81d71c

Browse files
committed
Fix constant rebuilds
1 parent a1e9d6f commit e81d71c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/compile.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,23 @@ 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 rewrite = if config_file.exists() {
447+
std::fs::read_to_string(&config_file)
448+
.map(|previous| previous != pyo3_config)
449+
.unwrap_or(false)
450+
} else {
451+
true
452+
};
453+
if rewrite {
454+
fs::write(&config_file, pyo3_config).with_context(|| {
455+
format!(
456+
"Failed to create pyo3 config file at '{}'",
457+
config_file.display()
458+
)
459+
})?;
460+
}
450461
let abs_config_file = config_file.normalize()?.into_path_buf();
451462
build_command.env("PYO3_CONFIG_FILE", abs_config_file);
452463
}

0 commit comments

Comments
 (0)