From 8085405d564995a212399e94f06014dc8ec70be9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 19 Dec 2025 12:21:23 +0000 Subject: [PATCH] Handle free-threaded builds in build_ext.get_libraries This updates build_ext.get_libraries to handle free-threaded builds of Python when using non-MSVC compilers. --- distutils/command/build_ext.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index ec45b440..6d9e85bd 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -770,13 +770,14 @@ def get_libraries(self, ext: Extension) -> list[str]: # noqa: C901 from .._msvccompiler import MSVCCompiler if not isinstance(self.compiler, MSVCCompiler): - template = "python%d%d" - if self.debug: - template = template + '_d' - pythonlib = template % ( + pythonlib = "python%d%d" % ( sys.hexversion >> 24, (sys.hexversion >> 16) & 0xFF, ) + if is_freethreaded(): + pythonlib += 't' + if self.debug: + pythonlib += '_d' # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib]