@@ -845,6 +845,7 @@ def run_msbuild(
845
845
platform : str ,
846
846
python_version : str ,
847
847
windows_sdk_version : str ,
848
+ freethreaded : bool ,
848
849
):
849
850
args = [
850
851
str (msbuild ),
@@ -867,6 +868,9 @@ def run_msbuild(
867
868
f"/property:DefaultWindowsSDKVersion={ windows_sdk_version } " ,
868
869
]
869
870
871
+ if freethreaded :
872
+ args .append ("/property:DisableGil=true" )
873
+
870
874
exec_and_log (args , str (pcbuild_path ), os .environ )
871
875
872
876
@@ -1118,6 +1122,7 @@ def collect_python_build_artifacts(
1118
1122
arch : str ,
1119
1123
config : str ,
1120
1124
openssl_entry : str ,
1125
+ freethreaded : bool ,
1121
1126
):
1122
1127
"""Collect build artifacts from Python.
1123
1128
@@ -1243,6 +1248,20 @@ def find_additional_dependencies(project: pathlib.Path):
1243
1248
1244
1249
return set ()
1245
1250
1251
+ if arch == "amd64" :
1252
+ abi_platform = "win_amd64"
1253
+ elif arch == "win32" :
1254
+ abi_platform = "win32"
1255
+ else :
1256
+ raise ValueError ("unhandled arch: %s" % arch )
1257
+
1258
+ if freethreaded :
1259
+ abi_tag = ".cp%st-%s" % (python_majmin , abi_platform )
1260
+ lib_suffix = "t"
1261
+ else :
1262
+ abi_tag = ""
1263
+ lib_suffix = ""
1264
+
1246
1265
# Copy object files for core sources into their own directory.
1247
1266
core_dir = out_dir / "build" / "core"
1248
1267
core_dir .mkdir (parents = True )
@@ -1263,12 +1282,12 @@ def find_additional_dependencies(project: pathlib.Path):
1263
1282
exts = ("lib" , "exp" )
1264
1283
1265
1284
for ext in exts :
1266
- source = outputs_path / ("python%s.%s" % (python_majmin , ext ))
1267
- dest = core_dir / ("python%s.%s" % (python_majmin , ext ))
1285
+ source = outputs_path / ("python%s%s .%s" % (python_majmin , lib_suffix , ext ))
1286
+ dest = core_dir / ("python%s%s .%s" % (python_majmin , lib_suffix , ext ))
1268
1287
log ("copying %s" % source )
1269
1288
shutil .copyfile (source , dest )
1270
1289
1271
- res ["core" ]["shared_lib" ] = "install/python%s.dll" % python_majmin
1290
+ res ["core" ]["shared_lib" ] = "install/python%s%s .dll" % ( python_majmin , lib_suffix )
1272
1291
1273
1292
# We hack up pythoncore.vcxproj and the list in it when this function
1274
1293
# runs isn't totally accurate. We hardcode the list from the CPython
@@ -1354,12 +1373,15 @@ def find_additional_dependencies(project: pathlib.Path):
1354
1373
res ["extensions" ][ext ] = [entry ]
1355
1374
1356
1375
# Copy the extension static library.
1357
- ext_static = outputs_path / ("%s.lib" % ext )
1358
- dest = dest_dir / ("%s.lib" % ext )
1376
+ ext_static = outputs_path / ("%s%s .lib" % ( ext , abi_tag ) )
1377
+ dest = dest_dir / ("%s%s .lib" % ( ext , abi_tag ) )
1359
1378
log ("copying static extension %s" % ext_static )
1360
1379
shutil .copyfile (ext_static , dest )
1361
1380
1362
- res ["extensions" ][ext ][0 ]["shared_lib" ] = "install/DLLs/%s.pyd" % ext
1381
+ res ["extensions" ][ext ][0 ]["shared_lib" ] = "install/DLLs/%s%s.pyd" % (
1382
+ ext ,
1383
+ abi_tag ,
1384
+ )
1363
1385
1364
1386
lib_dir = out_dir / "build" / "lib"
1365
1387
lib_dir .mkdir ()
@@ -1394,6 +1416,7 @@ def build_cpython(
1394
1416
) -> pathlib .Path :
1395
1417
parsed_build_options = set (build_options .split ("+" ))
1396
1418
pgo = "pgo" in parsed_build_options
1419
+ freethreaded = "freethreaded" in parsed_build_options
1397
1420
1398
1421
msbuild = find_msbuild (msvc_version )
1399
1422
log ("found MSBuild at %s" % msbuild )
@@ -1425,6 +1448,12 @@ def build_cpython(
1425
1448
# as we do for Unix builds.
1426
1449
mpdecimal_archive = None
1427
1450
1451
+ if freethreaded :
1452
+ (major , minor , _ ) = python_version .split ("." )
1453
+ python_exe = f"python{ major } .{ minor } t.exe"
1454
+ else :
1455
+ python_exe = "python.exe"
1456
+
1428
1457
if arch == "amd64" :
1429
1458
build_platform = "x64"
1430
1459
build_directory = "amd64"
@@ -1507,6 +1536,7 @@ def build_cpython(
1507
1536
platform = build_platform ,
1508
1537
python_version = python_version ,
1509
1538
windows_sdk_version = windows_sdk_version ,
1539
+ freethreaded = freethreaded ,
1510
1540
)
1511
1541
1512
1542
# build-windows.py sets some environment variables which cause the
@@ -1526,7 +1556,7 @@ def build_cpython(
1526
1556
# test execution. We work around this by invoking the test harness
1527
1557
# separately for each test.
1528
1558
instrumented_python = (
1529
- pcbuild_path / build_directory / "instrumented" / "python.exe"
1559
+ pcbuild_path / build_directory / "instrumented" / python_exe
1530
1560
)
1531
1561
1532
1562
tests = subprocess .run (
@@ -1572,6 +1602,7 @@ def build_cpython(
1572
1602
platform = build_platform ,
1573
1603
python_version = python_version ,
1574
1604
windows_sdk_version = windows_sdk_version ,
1605
+ freethreaded = freethreaded ,
1575
1606
)
1576
1607
artifact_config = "PGUpdate"
1577
1608
@@ -1583,6 +1614,7 @@ def build_cpython(
1583
1614
platform = build_platform ,
1584
1615
python_version = python_version ,
1585
1616
windows_sdk_version = windows_sdk_version ,
1617
+ freethreaded = freethreaded ,
1586
1618
)
1587
1619
artifact_config = "Release"
1588
1620
@@ -1615,6 +1647,9 @@ def build_cpython(
1615
1647
"--include-venv" ,
1616
1648
]
1617
1649
1650
+ if freethreaded :
1651
+ args .append ("--include-freethreaded" )
1652
+
1618
1653
# CPython 3.12 removed distutils.
1619
1654
if not meets_python_minimum_version (python_version , "3.12" ):
1620
1655
args .append ("--include-distutils" )
@@ -1639,7 +1674,7 @@ def build_cpython(
1639
1674
# Install pip and setuptools.
1640
1675
exec_and_log (
1641
1676
[
1642
- str (install_dir / "python.exe" ),
1677
+ str (install_dir / python_exe ),
1643
1678
"-m" ,
1644
1679
"pip" ,
1645
1680
"install" ,
@@ -1656,7 +1691,7 @@ def build_cpython(
1656
1691
if meets_python_maximum_version (python_version , "3.11" ):
1657
1692
exec_and_log (
1658
1693
[
1659
- str (install_dir / "python.exe" ),
1694
+ str (install_dir / python_exe ),
1660
1695
"-m" ,
1661
1696
"pip" ,
1662
1697
"install" ,
@@ -1691,6 +1726,7 @@ def build_cpython(
1691
1726
build_directory ,
1692
1727
artifact_config ,
1693
1728
openssl_entry = openssl_entry ,
1729
+ freethreaded = freethreaded ,
1694
1730
)
1695
1731
1696
1732
for ext , init_fn in sorted (builtin_extensions .items ()):
@@ -1775,7 +1811,7 @@ def build_cpython(
1775
1811
}
1776
1812
1777
1813
# Collect information from running Python script.
1778
- python_exe = out_dir / "python" / "install" / "python.exe"
1814
+ python_exe = out_dir / "python" / "install" / python_exe
1779
1815
metadata_path = td / "metadata.json"
1780
1816
env = dict (os .environ )
1781
1817
env ["ROOT" ] = str (out_dir / "python" )
0 commit comments