Skip to content

Commit 49b6f84

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

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

.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

cpython-windows/build.py

+41-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"
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
@@ -936,6 +940,7 @@ def build_openssl_for_arch(
936940
str(perl_path),
937941
"Configure",
938942
configure,
943+
"enable-applink",
939944
"no-idea",
940945
"no-mdc2",
941946
"no-tests",
@@ -988,6 +993,7 @@ def build_openssl(
988993

989994
root_32 = td / "x86"
990995
root_64 = td / "x64"
996+
root_arm64 = td / "arm64"
991997

992998
if arch == "x86":
993999
root_32.mkdir()
@@ -1011,13 +1017,28 @@ def build_openssl(
10111017
root_64,
10121018
jom_archive=jom_archive,
10131019
)
1020+
elif arch == "arm64":
1021+
root_arm64.mkdir()
1022+
build_openssl_for_arch(
1023+
perl_path,
1024+
"arm64",
1025+
openssl_archive,
1026+
openssl_version,
1027+
nasm_archive,
1028+
root_arm64,
1029+
jom_archive=jom_archive,
1030+
)
10141031
else:
1015-
raise ValueError("unhandled arch: %s" % arch)
1032+
raise Exception("unhandled architecture: %s" % arch)
10161033

10171034
install = td / "out"
10181035

10191036
if arch == "x86":
10201037
shutil.copytree(root_32 / "install" / "32", install / "openssl" / "win32")
1038+
elif arch == "arm64":
1039+
shutil.copytree(
1040+
root_arm64 / "install" / "arm64", install / "openssl" / "arm64"
1041+
)
10211042
else:
10221043
shutil.copytree(root_64 / "install" / "64", install / "openssl" / "amd64")
10231044

@@ -1088,9 +1109,14 @@ def build_libffi(
10881109
if arch == "x86":
10891110
args.append("-x86")
10901111
artifacts_path = ffi_source_path / "i686-pc-cygwin"
1091-
else:
1112+
elif arch == "arm64":
1113+
args.append("-arm64")
1114+
artifacts_path = ffi_source_path / "aarch64-w64-cygwin"
1115+
elif arch == "amd64":
10921116
args.append("-x64")
10931117
artifacts_path = ffi_source_path / "x86_64-w64-cygwin"
1118+
else:
1119+
raise Exception("unhandled architecture: %s" % arch)
10941120

10951121
subprocess.run(args, env=env, check=True)
10961122

@@ -1460,8 +1486,11 @@ def build_cpython(
14601486
elif arch == "x86":
14611487
build_platform = "win32"
14621488
build_directory = "win32"
1489+
elif arch == "arm64":
1490+
build_platform = "arm64"
1491+
build_directory = "arm64"
14631492
else:
1464-
raise ValueError("unhandled arch: %s" % arch)
1493+
raise Exception("unhandled architecture: %s" % arch)
14651494

14661495
with tempfile.TemporaryDirectory(prefix="python-build-") as td:
14671496
td = pathlib.Path(td)
@@ -1491,7 +1520,7 @@ def build_cpython(
14911520

14921521
# We need all the OpenSSL library files in the same directory to appease
14931522
# install rules.
1494-
openssl_arch = {"amd64": "amd64", "x86": "win32"}[arch]
1523+
openssl_arch = {"amd64": "amd64", "x86": "win32", "arm64": "arm64"}[arch]
14951524
openssl_root = td / "openssl" / openssl_arch
14961525
openssl_bin_path = openssl_root / "bin"
14971526
openssl_lib_path = openssl_root / "lib"
@@ -1930,9 +1959,14 @@ def main() -> None:
19301959
if os.environ.get("Platform") == "x86":
19311960
target_triple = "i686-pc-windows-msvc"
19321961
arch = "x86"
1933-
else:
1962+
elif os.environ.get("Platform") == "arm64":
1963+
target_triple = "aarch64-pc-windows-msvc"
1964+
arch = "arm64"
1965+
elif os.environ.get("Platform") == "x64":
19341966
target_triple = "x86_64-pc-windows-msvc"
19351967
arch = "amd64"
1968+
else:
1969+
raise Exception("unhandled architecture: %s" % os.environ.get("Platform"))
19361970

19371971
# TODO need better dependency checking.
19381972

0 commit comments

Comments
 (0)