Skip to content

Commit

Permalink
Add ARM64 builds for Windows
Browse files Browse the repository at this point in the history
Co-authored-by: Adrian Antkowiak <[email protected]>
  • Loading branch information
zanieb and adiantek committed Oct 30, 2024
1 parent e8b031b commit f25385c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
vcvars:
- 'vcvars32.bat'
- 'vcvars64.bat'
- 'vcvarsamd64_arm64.bat'
options:
- 'pgo'

Expand Down
47 changes: 40 additions & 7 deletions cpython-windows/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ def hack_props(
suffix = b"-x64"
elif arch == "win32":
suffix = b""
elif arch == "arm64":
suffix = b"arm64"
else:
raise Exception("unhandled architecture: %s" % arch)

Expand Down Expand Up @@ -917,9 +919,11 @@ def build_openssl_for_arch(
elif arch == "amd64":
configure = "VC-WIN64A"
prefix = "64"
elif arch == "arm64":
configure = "VC-WIN64-ARM"
prefix = "arm64" # TODO check it ???
else:
print("invalid architecture: %s" % arch)
sys.exit(1)
raise Exception("unhandled architecture: %s" % arch)

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

root_32 = td / "x86"
root_64 = td / "x64"
root_arm64 = td / "arm64"

if arch == "x86":
root_32.mkdir()
Expand All @@ -1011,13 +1016,28 @@ def build_openssl(
root_64,
jom_archive=jom_archive,
)
elif arch == "arm64":
root_64.mkdir()
build_openssl_for_arch(
perl_path,
"arm64",
openssl_archive,
nasm_archive,
root_arm64,
profile,
jom_archive=jom_archive,
)
else:
raise ValueError("unhandled arch: %s" % arch)
raise Exception("unhandled architecture: %s" % arch)

install = td / "out"

if arch == "x86":
shutil.copytree(root_32 / "install" / "32", install / "openssl" / "win32")
elif arch == "arm64":
shutil.copytree(
root_arm64 / "install" / "arm64", install / "openssl" / "arm64"
)
else:
shutil.copytree(root_64 / "install" / "64", install / "openssl" / "amd64")

Expand Down Expand Up @@ -1088,9 +1108,14 @@ def build_libffi(
if arch == "x86":
args.append("-x86")
artifacts_path = ffi_source_path / "i686-pc-cygwin"
else:
elif arch == "arm64":
args.append("-arm64")
artifacts_path = ffi_source_path / "aarch64-w64-cygwin"
elif arch == "amd64":
args.append("-x64")
artifacts_path = ffi_source_path / "x86_64-w64-cygwin"
else:
raise Exception("unhandled architecture: %s" % arch)

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

Expand Down Expand Up @@ -1460,8 +1485,11 @@ def build_cpython(
elif arch == "x86":
build_platform = "win32"
build_directory = "win32"
elif arch == "arm64":
build_platform = "arm64"
build_directory = "arm64"
else:
raise ValueError("unhandled arch: %s" % arch)
raise Exception("unhandled architecture: %s" % arch)

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

# We need all the OpenSSL library files in the same directory to appease
# install rules.
openssl_arch = {"amd64": "amd64", "x86": "win32"}[arch]
openssl_arch = {"amd64": "amd64", "x86": "win32", "arm64": "arm64"}[arch]
openssl_root = td / "openssl" / openssl_arch
openssl_bin_path = openssl_root / "bin"
openssl_lib_path = openssl_root / "lib"
Expand Down Expand Up @@ -1930,9 +1958,14 @@ def main() -> None:
if os.environ.get("Platform") == "x86":
target_triple = "i686-pc-windows-msvc"
arch = "x86"
else:
elif os.environ.get("Platform") == "arm64":
target_triple = "aarch64-pc-windows-msvc"
arch = "arm64"
elif os.environ.get("Platform") == "x64":
target_triple = "x86_64-pc-windows-msvc"
arch = "amd64"
else:
raise Exception("unhandled architecture: %s" % os.environ.get("Platform"))

# TODO need better dependency checking.

Expand Down

0 comments on commit f25385c

Please sign in to comment.