Skip to content

Commit 13c9751

Browse files
committed
Prevent object file collisions in parallel extension builds
Parallel builds of extensions that share source files may write to the same object file paths under a common build directory, resulting in race conditions and non-deterministic build outputs. Use a per-extension build directory to isolate object files and ensure deterministic, parallel-safe builds. Bug: #3942
1 parent d198e86 commit 13c9751

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

newsfragments/3942.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed non-deterministic parallel builds of extensions that share source files.

setuptools/_distutils/command/build_ext.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,12 @@ def build_extension(self, ext) -> None:
562562
for undef in ext.undef_macros:
563563
macros.append((undef,))
564564

565+
# Per-extension build dir to avoid conflicts in parallel builds.
566+
ext_build_temp = os.path.join(self.build_temp, ext.name)
567+
565568
objects = self.compiler.compile(
566569
sources,
567-
output_dir=self.build_temp,
570+
output_dir=ext_build_temp,
568571
macros=macros,
569572
include_dirs=ext.include_dirs,
570573
debug=self.debug,
@@ -595,7 +598,7 @@ def build_extension(self, ext) -> None:
595598
extra_postargs=extra_args,
596599
export_symbols=self.get_export_symbols(ext),
597600
debug=self.debug,
598-
build_temp=self.build_temp,
601+
build_temp=ext_build_temp,
599602
target_lang=language,
600603
)
601604

0 commit comments

Comments
 (0)