Skip to content

Commit bb7bc6e

Browse files
zaniebadiantek
andcommitted
Add ARM64 builds for Windows
Co-authored-by: Adrian Antkowiak <[email protected]>
1 parent 522f6b3 commit bb7bc6e

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Diff for: .github/workflows/windows.yml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
vcvars:
5151
- 'vcvars32.bat'
5252
- 'vcvars64.bat'
53+
- 'vcvarsamd64_arm64.bat'
5354
options:
5455
- 'pgo'
5556

Diff for: cpython-windows/build.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ def hack_props(
438438
suffix = b"-x64"
439439
elif arch == "win32":
440440
suffix = b""
441+
elif arch == "arm64":
442+
suffix = b""
441443
else:
442444
raise Exception("unhandled architecture: %s" % arch)
443445

@@ -917,9 +919,11 @@ def build_openssl_for_arch(
917919
elif arch == "amd64":
918920
configure = "VC-WIN64A"
919921
prefix = "64"
922+
elif arch == "arm64":
923+
configure = "VC-WIN64-ARM"
924+
prefix = "arm64" # TODO check it ???
920925
else:
921-
print("invalid architecture: %s" % arch)
922-
sys.exit(1)
926+
raise Exception("unhandled architecture: %s" % arch)
923927

924928
# The official CPython OpenSSL builds hack ms/uplink.c to change the
925929
# ``GetModuleHandle(NULL)`` invocation to load things from _ssl.pyd
@@ -988,6 +992,7 @@ def build_openssl(
988992

989993
root_32 = td / "x86"
990994
root_64 = td / "x64"
995+
root_arm64 = td / "arm64"
991996

992997
if arch == "x86":
993998
root_32.mkdir()
@@ -1011,13 +1016,28 @@ def build_openssl(
10111016
root_64,
10121017
jom_archive=jom_archive,
10131018
)
1019+
elif arch == "arm64":
1020+
root_64.mkdir()
1021+
build_openssl_for_arch(
1022+
perl_path,
1023+
"arm64",
1024+
openssl_archive,
1025+
openssl_version,
1026+
nasm_archive,
1027+
root_arm64,
1028+
jom_archive=jom_archive,
1029+
)
10141030
else:
1015-
raise ValueError("unhandled arch: %s" % arch)
1031+
raise Exception("unhandled architecture: %s" % arch)
10161032

10171033
install = td / "out"
10181034

10191035
if arch == "x86":
10201036
shutil.copytree(root_32 / "install" / "32", install / "openssl" / "win32")
1037+
elif arch == "arm64":
1038+
shutil.copytree(
1039+
root_arm64 / "install" / "arm64", install / "openssl" / "arm64"
1040+
)
10211041
else:
10221042
shutil.copytree(root_64 / "install" / "64", install / "openssl" / "amd64")
10231043

@@ -1088,9 +1108,14 @@ def build_libffi(
10881108
if arch == "x86":
10891109
args.append("-x86")
10901110
artifacts_path = ffi_source_path / "i686-pc-cygwin"
1091-
else:
1111+
elif arch == "arm64":
1112+
args.append("-arm64")
1113+
artifacts_path = ffi_source_path / "aarch64-w64-cygwin"
1114+
elif arch == "amd64":
10921115
args.append("-x64")
10931116
artifacts_path = ffi_source_path / "x86_64-w64-cygwin"
1117+
else:
1118+
raise Exception("unhandled architecture: %s" % arch)
10941119

10951120
subprocess.run(args, env=env, check=True)
10961121

@@ -1460,8 +1485,11 @@ def build_cpython(
14601485
elif arch == "x86":
14611486
build_platform = "win32"
14621487
build_directory = "win32"
1488+
elif arch == "arm64":
1489+
build_platform = "arm64"
1490+
build_directory = "arm64"
14631491
else:
1464-
raise ValueError("unhandled arch: %s" % arch)
1492+
raise Exception("unhandled architecture: %s" % arch)
14651493

14661494
with tempfile.TemporaryDirectory(prefix="python-build-") as td:
14671495
td = pathlib.Path(td)
@@ -1491,7 +1519,7 @@ def build_cpython(
14911519

14921520
# We need all the OpenSSL library files in the same directory to appease
14931521
# install rules.
1494-
openssl_arch = {"amd64": "amd64", "x86": "win32"}[arch]
1522+
openssl_arch = {"amd64": "amd64", "x86": "win32", "arm64": "arm64"}[arch]
14951523
openssl_root = td / "openssl" / openssl_arch
14961524
openssl_bin_path = openssl_root / "bin"
14971525
openssl_lib_path = openssl_root / "lib"
@@ -1930,9 +1958,14 @@ def main() -> None:
19301958
if os.environ.get("Platform") == "x86":
19311959
target_triple = "i686-pc-windows-msvc"
19321960
arch = "x86"
1933-
else:
1961+
elif os.environ.get("Platform") == "arm64":
1962+
target_triple = "aarch64-pc-windows-msvc"
1963+
arch = "arm64"
1964+
elif os.environ.get("Platform") == "x64":
19341965
target_triple = "x86_64-pc-windows-msvc"
19351966
arch = "amd64"
1967+
else:
1968+
raise Exception("unhandled architecture: %s" % os.environ.get("Platform"))
19361969

19371970
# TODO need better dependency checking.
19381971

0 commit comments

Comments
 (0)