Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows arm64 dependency cross-compilation fixes #7559

Merged
merged 2 commits into from Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions winbuild/build_prepare.py
Expand Up @@ -118,6 +118,12 @@ def cmd_msbuild(
"(LEGAL ISSUES\n============\n\n.+?)\n\nREFERENCES\n=========="
".+(libjpeg-turbo Licenses\n======================\n\n.+)$"
),
"patch": {
r"CMakeLists.txt": {
# libjpeg-turbo does not detect MSVC x86_arm64 cross-compiler correctly
'if(MSVC_IDE AND CMAKE_GENERATOR_PLATFORM MATCHES "arm64")': "if({architecture} STREQUAL ARM64)", # noqa: E501
},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change something that could be suggested to https://github.com/libjpeg-turbo/libjpeg-turbo, so that it could one day no longer require patching?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not easily.
CMake does not provide a value for the target CPU architecture, only the host CPU architecture: https://stackoverflow.com/a/12024211/1648883
The {architecture} string here is referring to the Python value from

"architecture": args.architecture,

"build": [
*cmds_cmake(
("jpeg-static", "cjpeg-static", "djpeg-static"),
Expand Down Expand Up @@ -327,6 +333,8 @@ def cmd_msbuild(
"CMakeLists.txt": {
"if(OPENMP_FOUND)": "if(false)",
"install": "#install",
# libimagequant does not detect MSVC x86_arm64 cross-compiler correctly
"if(${{CMAKE_SYSTEM_PROCESSOR}} STREQUAL ARM64)": "if({architecture} STREQUAL ARM64)", # noqa: E501
}
},
"build": [
Expand Down Expand Up @@ -367,12 +375,17 @@ def cmd_msbuild(


# based on distutils._msvccompiler from CPython 3.7.4
def find_msvs() -> dict[str, str] | None:
def find_msvs(architecture: str) -> dict[str, str] | None:
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
if not root:
print("Program Files not found")
return None

if architecture == "ARM64":
tools = "Microsoft.VisualStudio.Component.VC.Tools.ARM64"
else:
tools = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"

try:
vspath = (
subprocess.check_output(
Expand All @@ -383,7 +396,7 @@ def find_msvs() -> dict[str, str] | None:
"-latest",
"-prerelease",
"-requires",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
tools,
"-property",
"installationPath",
"-products",
Expand Down Expand Up @@ -654,7 +667,7 @@ def build_dep_all() -> None:
arch_prefs = ARCHITECTURES[args.architecture]
print("Target architecture:", args.architecture)

msvs = find_msvs()
msvs = find_msvs(args.architecture)
if msvs is None:
msg = "Visual Studio not found. Please install Visual Studio 2017 or newer."
raise RuntimeError(msg)
Expand Down Expand Up @@ -689,6 +702,11 @@ def build_dep_all() -> None:
disabled += ["libimagequant"]
if args.no_fribidi:
disabled += ["fribidi"]
elif args.architecture == "ARM64" and platform.machine() != "ARM64":
import warnings

warnings.warn("Cross-compiling FriBiDi is currently not supported, disabling")
disabled += ["fribidi"]

prefs = {
"architecture": args.architecture,
Expand Down