@@ -532,7 +532,7 @@ def copy_link_to_lib(p: pathlib.Path):
532
532
'''
533
533
534
534
535
- def hack_props (td : pathlib .Path , pcbuild_path : pathlib .Path ):
535
+ def hack_props (td : pathlib .Path , pcbuild_path : pathlib .Path , arch : str ):
536
536
# TODO can we pass props into msbuild.exe?
537
537
538
538
# Our dependencies are in different directories from what CPython's
@@ -550,7 +550,7 @@ def hack_props(td: pathlib.Path, pcbuild_path: pathlib.Path):
550
550
xz_path = td / ('xz-%s' % xz_version )
551
551
zlib_path = td / ('zlib-%s' % zlib_version )
552
552
553
- openssl_root = td / 'openssl' / 'amd64'
553
+ openssl_root = td / 'openssl' / arch
554
554
openssl_libs_path = openssl_root / 'lib'
555
555
openssl_include_path = openssl_root / 'include'
556
556
@@ -609,12 +609,13 @@ def hack_props(td: pathlib.Path, pcbuild_path: pathlib.Path):
609
609
b'libcrypto_static.lib;libssl_static.lib;' )
610
610
611
611
612
- def hack_project_files (td : pathlib .Path , cpython_source_path : pathlib .Path ):
612
+ def hack_project_files (td : pathlib .Path , cpython_source_path : pathlib .Path ,
613
+ build_directory : str ):
613
614
"""Hacks Visual Studio project files to work with our build."""
614
615
615
616
pcbuild_path = cpython_source_path / 'PCbuild'
616
617
617
- hack_props (td , pcbuild_path )
618
+ hack_props (td , pcbuild_path , build_directory )
618
619
619
620
# Our SQLite directory is named weirdly. This throws off version detection
620
621
# in the project file. Replace the parsing logic with a static string.
@@ -922,15 +923,15 @@ def hack_source_files(source_path: pathlib.Path):
922
923
923
924
924
925
def run_msbuild (msbuild : pathlib .Path , pcbuild_path : pathlib .Path ,
925
- configuration : str ):
926
+ configuration : str , platform : str ):
926
927
python_version = DOWNLOADS ['cpython-3.7' ]['version' ]
927
928
928
929
args = [
929
930
str (msbuild ),
930
931
str (pcbuild_path / 'pcbuild.proj' ),
931
932
'/target:Build' ,
932
933
'/property:Configuration=%s' % configuration ,
933
- '/property:Platform=x64' ,
934
+ '/property:Platform=%s' % platform ,
934
935
'/maxcpucount' ,
935
936
'/nologo' ,
936
937
'/verbosity:normal' ,
@@ -1005,7 +1006,7 @@ def build_openssl_for_arch(perl_path, arch: str, openssl_archive, nasm_archive,
1005
1006
shutil .copyfile (source , dest )
1006
1007
1007
1008
1008
- def build_openssl (perl_path : pathlib .Path ):
1009
+ def build_openssl (perl_path : pathlib .Path , arch : str ):
1009
1010
"""Build OpenSSL from sources using the Perl executable specified."""
1010
1011
1011
1012
# First ensure the dependencies are in place.
@@ -1026,19 +1027,26 @@ def build_openssl(perl_path: pathlib.Path):
1026
1027
# in order for this to work.
1027
1028
fs = []
1028
1029
with concurrent .futures .ThreadPoolExecutor (2 ) as e :
1029
- #fs.append(e.submit(build_openssl_for_arch, perl_path, 'x86',
1030
- # openssl_archive, nasm_archive, root_32))
1031
- fs .append (e .submit (build_openssl_for_arch , perl_path , 'amd64' ,
1032
- openssl_archive , nasm_archive , root_64 ))
1030
+ if arch == 'x86' :
1031
+ fs .append (e .submit (build_openssl_for_arch , perl_path , 'x86' ,
1032
+ openssl_archive , nasm_archive , root_32 ))
1033
+ elif arch == 'amd64' :
1034
+ fs .append (e .submit (build_openssl_for_arch , perl_path , 'amd64' ,
1035
+ openssl_archive , nasm_archive , root_64 ))
1036
+ else :
1037
+ raise ValueError ('unhandled arch: %s' % arch )
1033
1038
1034
1039
for f in fs :
1035
1040
f .result ()
1036
1041
1037
1042
install = td / 'out'
1038
- #shutil.copytree(root_32 / 'install' / '32', install / 'openssl' / 'win32')
1039
- shutil .copytree (root_64 / 'install' / '64' , install / 'openssl' / 'amd64' )
1040
1043
1041
- dest_archive = BUILD / 'openssl-windows.tar'
1044
+ if arch == 'x86' :
1045
+ shutil .copytree (root_32 / 'install' / '32' , install / 'openssl' / 'win32' )
1046
+ else :
1047
+ shutil .copytree (root_64 / 'install' / '64' , install / 'openssl' / 'amd64' )
1048
+
1049
+ dest_archive = BUILD / ('openssl-windows-%s.tar' % arch )
1042
1050
with dest_archive .open ('wb' ) as fh :
1043
1051
create_tar_from_directory (fh , install )
1044
1052
@@ -1254,7 +1262,7 @@ def find_additional_dependencies(project: pathlib.Path):
1254
1262
return res
1255
1263
1256
1264
1257
- def build_cpython (pgo = False ):
1265
+ def build_cpython (arch : str , pgo = False ):
1258
1266
msbuild = find_msbuild ()
1259
1267
log ('found MSBuild at %s' % msbuild )
1260
1268
@@ -1273,7 +1281,18 @@ def build_cpython(pgo=False):
1273
1281
setuptools_archive = download_entry ('setuptools' , BUILD )
1274
1282
pip_archive = download_entry ('pip' , BUILD )
1275
1283
1276
- openssl_bin_archive = BUILD / 'openssl-windows.tar'
1284
+ openssl_bin_archive = BUILD / ('openssl-windows-%s.tar' % arch )
1285
+
1286
+ if arch == 'amd64' :
1287
+ build_platform = 'x64'
1288
+ build_directory = 'amd64'
1289
+ json_arch = 'x86_64'
1290
+ elif arch == 'x86' :
1291
+ build_platform = 'win32'
1292
+ build_directory = 'win32'
1293
+ json_arch = 'x86'
1294
+ else :
1295
+ raise ValueError ('unhandled arch: %s' % arch )
1277
1296
1278
1297
with tempfile .TemporaryDirectory () as td :
1279
1298
td = pathlib .Path (td )
@@ -1304,11 +1323,12 @@ def build_cpython(pgo=False):
1304
1323
1305
1324
builtin_extensions = parse_config_c (config_c )
1306
1325
1307
- hack_project_files (td , cpython_source_path )
1326
+ hack_project_files (td , cpython_source_path , build_directory )
1308
1327
hack_source_files (cpython_source_path )
1309
1328
1310
1329
if pgo :
1311
- run_msbuild (msbuild , pcbuild_path , configuration = 'PGInstrument' )
1330
+ run_msbuild (msbuild , pcbuild_path , configuration = 'PGInstrument' ,
1331
+ platform = build_platform )
1312
1332
1313
1333
exec_and_log ([
1314
1334
str (cpython_source_path / 'python.bat' ), '-m' , 'test' , '--pgo' ],
@@ -1322,17 +1342,19 @@ def build_cpython(pgo=False):
1322
1342
'/target:KillPython' ,
1323
1343
'/verbosity:normal' ,
1324
1344
'/property:Configuration=PGInstrument' ,
1325
- '/property:Platform=x64' ,
1345
+ '/property:Platform=%s' % build_platform ,
1326
1346
'/property:KillPython=true' ,
1327
1347
],
1328
1348
pcbuild_path ,
1329
1349
os .environ )
1330
1350
1331
- run_msbuild (msbuild , pcbuild_path , configuration = 'PGUpdate' )
1351
+ run_msbuild (msbuild , pcbuild_path , configuration = 'PGUpdate' ,
1352
+ platform = build_platform )
1332
1353
artifact_config = 'PGUpdate'
1333
1354
1334
1355
else :
1335
- run_msbuild (msbuild , pcbuild_path , configuration = 'Release' )
1356
+ run_msbuild (msbuild , pcbuild_path , configuration = 'Release' ,
1357
+ platform = build_platform )
1336
1358
artifact_config = 'Release'
1337
1359
1338
1360
install_dir = out_dir / 'python' / 'install'
@@ -1352,7 +1374,7 @@ def build_cpython(pgo=False):
1352
1374
str (cpython_source_path / 'PC' / 'layout' ),
1353
1375
'-vv' ,
1354
1376
'--source' , str (cpython_source_path ),
1355
- '--build' , str (pcbuild_path / 'amd64' ),
1377
+ '--build' , str (pcbuild_path / build_directory ),
1356
1378
'--copy' , str (install_dir ),
1357
1379
'--temp' , str (layout_tmp ),
1358
1380
'--flat-dlls' ,
@@ -1383,7 +1405,7 @@ def build_cpython(pgo=False):
1383
1405
1384
1406
# Now copy the build artifacts into the output directory.
1385
1407
build_info = collect_python_build_artifacts (
1386
- pcbuild_path , out_dir / 'python' , 'amd64' , artifact_config )
1408
+ pcbuild_path , out_dir / 'python' , build_directory , artifact_config )
1387
1409
1388
1410
for ext , init_fn in sorted (builtin_extensions .items ()):
1389
1411
if ext in build_info ['extensions' ]:
@@ -1406,7 +1428,7 @@ def build_cpython(pgo=False):
1406
1428
# Copy OpenSSL libraries as a one-off.
1407
1429
for lib in ('crypto' , 'ssl' ):
1408
1430
name = 'lib%s_static.lib' % lib
1409
- source = td / 'openssl' / 'amd64' / 'lib' / name
1431
+ source = td / 'openssl' / build_directory / 'lib' / name
1410
1432
dest = out_dir / 'python' / 'build' / 'lib' / name
1411
1433
log ('copying %s to %s' % (source , dest ))
1412
1434
shutil .copyfile (source , dest )
@@ -1421,7 +1443,7 @@ def build_cpython(pgo=False):
1421
1443
python_info = {
1422
1444
'version' : '2' ,
1423
1445
'os' : 'windows' ,
1424
- 'arch' : 'x86_64' ,
1446
+ 'arch' : json_arch ,
1425
1447
'python_flavor' : 'cpython' ,
1426
1448
'python_version' : python_version ,
1427
1449
'python_exe' : 'install/python.exe' ,
@@ -1435,7 +1457,7 @@ def build_cpython(pgo=False):
1435
1457
with (out_dir / 'python' / 'PYTHON.json' ).open ('w' , encoding = 'utf8' ) as fh :
1436
1458
json .dump (python_info , fh , sort_keys = True , indent = 4 )
1437
1459
1438
- dest_path = BUILD / 'cpython-windows.tar'
1460
+ dest_path = BUILD / ( 'cpython-windows-%s .tar' % arch )
1439
1461
1440
1462
with dest_path .open ('wb' ) as fh :
1441
1463
create_tar_from_directory (fh , td / 'out' )
@@ -1458,15 +1480,18 @@ def main():
1458
1480
with log_path .open ('wb' ) as log_fh :
1459
1481
LOG_FH [0 ] = log_fh
1460
1482
1483
+ arch = 'x86' if os .environ .get ('Platform' ) == 'x86' else 'amd64'
1484
+
1461
1485
# TODO need better dependency checking.
1462
- openssl_out = BUILD / 'openssl-windows.tar'
1486
+ openssl_out = BUILD / ( 'openssl-windows-%s .tar' % arch )
1463
1487
if not openssl_out .exists ():
1464
1488
perl_path = fetch_strawberry_perl () / 'perl' / 'bin' / 'perl.exe'
1465
1489
LOG_PREFIX [0 ] = 'openssl'
1466
- build_openssl (perl_path )
1490
+ build_openssl (perl_path , arch )
1467
1491
1468
1492
LOG_PREFIX [0 ] = 'cpython'
1469
- build_cpython ()
1493
+ build_cpython (arch )
1494
+
1470
1495
1471
1496
if __name__ == '__main__' :
1472
1497
sys .exit (main ())
0 commit comments