@@ -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
@@ -944,7 +948,8 @@ def build_openssl_for_arch(
944948 source_root ,
945949 {
946950 ** env ,
947- "CFLAGS" : env .get ("CFLAGS" , "" ) + " /FS" ,
951+ # We set `OPENSSL_USE_APPLINK` to force inclusion on arm64
952+ "CFLAGS" : env .get ("CFLAGS" , "" ) + " /FS /DOPENSSL_USE_APPLINK" ,
948953 },
949954 )
950955
@@ -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