Skip to content

Commit 2350279

Browse files
zaniebadiantek
andcommitted
Add ARM64 builds for Windows
Co-authored-by: Adrian Antkowiak <adiantek@gmail.com>
1 parent 50e3f68 commit 2350279

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

ci-runners.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ windows-latest:
3535
arch: x86_64
3636
platform: windows
3737
free: true
38+
39+
windows-11-arm:
40+
arch: aarch64
41+
platform: windows
42+
free: false

ci-targets.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,20 @@ windows:
384384
- options:
385385
- freethreaded+pgo
386386
minimum-python-version: "3.13"
387+
388+
aarch64-pc-windows-msvc:
389+
arch: aarch64
390+
vcvars: vcvarsamd64_arm64.bat
391+
python_versions:
392+
- "3.9"
393+
- "3.10"
394+
- "3.11"
395+
- "3.12"
396+
- "3.13"
397+
- "3.14"
398+
build_options:
399+
- pgo
400+
build_options_conditional:
401+
- options:
402+
- freethreaded+pgo
403+
minimum-python-version: "3.13"

cpython-windows/build.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ def hack_props(
444444
suffix = b"-x64"
445445
elif arch == "win32":
446446
suffix = b""
447+
elif arch == "arm64":
448+
suffix = b""
447449
else:
448450
raise Exception("unhandled architecture: %s" % arch)
449451

@@ -708,9 +710,11 @@ def build_openssl_for_arch(
708710
elif arch == "amd64":
709711
configure = "VC-WIN64A"
710712
prefix = "64"
713+
elif arch == "arm64":
714+
configure = "VC-WIN64-ARM"
715+
prefix = "arm64"
711716
else:
712-
print("invalid architecture: %s" % arch)
713-
sys.exit(1)
717+
raise Exception("unhandled architecture: %s" % arch)
714718

715719
# The official CPython OpenSSL builds hack ms/uplink.c to change the
716720
# ``GetModuleHandle(NULL)`` invocation to load things from _ssl.pyd
@@ -758,6 +762,12 @@ def build_openssl_for_arch(
758762
log("copying %s to %s" % (source, dest))
759763
shutil.copyfile(source, dest)
760764

765+
# Copy `applink.c` to the include directory.
766+
source_applink = source_root / "ms" / "applink.c"
767+
dest_applink = install_root / "include" / "openssl" / "applink.c"
768+
log("copying %s to %s" % (source_applink, dest_applink))
769+
shutil.copyfile(source_applink, dest_applink)
770+
761771

762772
def build_openssl(
763773
entry: str,
@@ -779,6 +789,7 @@ def build_openssl(
779789

780790
root_32 = td / "x86"
781791
root_64 = td / "x64"
792+
root_arm64 = td / "arm64"
782793

783794
if arch == "x86":
784795
root_32.mkdir()
@@ -802,13 +813,28 @@ def build_openssl(
802813
root_64,
803814
jom_archive=jom_archive,
804815
)
816+
elif arch == "arm64":
817+
root_arm64.mkdir()
818+
build_openssl_for_arch(
819+
perl_path,
820+
"arm64",
821+
openssl_archive,
822+
openssl_version,
823+
nasm_archive,
824+
root_arm64,
825+
jom_archive=jom_archive,
826+
)
805827
else:
806-
raise ValueError("unhandled arch: %s" % arch)
828+
raise Exception("unhandled architecture: %s" % arch)
807829

808830
install = td / "out"
809831

810832
if arch == "x86":
811833
shutil.copytree(root_32 / "install" / "32", install / "openssl" / "win32")
834+
elif arch == "arm64":
835+
shutil.copytree(
836+
root_arm64 / "install" / "arm64", install / "openssl" / "arm64"
837+
)
812838
else:
813839
shutil.copytree(root_64 / "install" / "64", install / "openssl" / "amd64")
814840

@@ -879,9 +905,14 @@ def build_libffi(
879905
if arch == "x86":
880906
args.append("-x86")
881907
artifacts_path = ffi_source_path / "i686-pc-cygwin"
882-
else:
908+
elif arch == "arm64":
909+
args.append("-arm64")
910+
artifacts_path = ffi_source_path / "aarch64-w64-cygwin"
911+
elif arch == "amd64":
883912
args.append("-x64")
884913
artifacts_path = ffi_source_path / "x86_64-w64-cygwin"
914+
else:
915+
raise Exception("unhandled architecture: %s" % arch)
885916

886917
subprocess.run(args, env=env, check=True)
887918

@@ -1259,8 +1290,11 @@ def build_cpython(
12591290
elif arch == "x86":
12601291
build_platform = "win32"
12611292
build_directory = "win32"
1293+
elif arch == "arm64":
1294+
build_platform = "arm64"
1295+
build_directory = "arm64"
12621296
else:
1263-
raise ValueError("unhandled arch: %s" % arch)
1297+
raise Exception("unhandled architecture: %s" % arch)
12641298

12651299
tempdir_opts = (
12661300
{"ignore_cleanup_errors": True} if sys.version_info >= (3, 12) else {}
@@ -1293,7 +1327,7 @@ def build_cpython(
12931327

12941328
# We need all the OpenSSL library files in the same directory to appease
12951329
# install rules.
1296-
openssl_arch = {"amd64": "amd64", "x86": "win32"}[arch]
1330+
openssl_arch = {"amd64": "amd64", "x86": "win32", "arm64": "arm64"}[arch]
12971331
openssl_root = td / "openssl" / openssl_arch
12981332
openssl_bin_path = openssl_root / "bin"
12991333
openssl_lib_path = openssl_root / "lib"
@@ -1749,9 +1783,14 @@ def main() -> None:
17491783
if os.environ.get("Platform") == "x86":
17501784
target_triple = "i686-pc-windows-msvc"
17511785
arch = "x86"
1752-
else:
1786+
elif os.environ.get("Platform") == "arm64":
1787+
target_triple = "aarch64-pc-windows-msvc"
1788+
arch = "arm64"
1789+
elif os.environ.get("Platform") == "x64":
17531790
target_triple = "x86_64-pc-windows-msvc"
17541791
arch = "amd64"
1792+
else:
1793+
raise Exception("unhandled architecture: %s" % os.environ.get("Platform"))
17551794

17561795
# TODO need better dependency checking.
17571796

0 commit comments

Comments
 (0)