Skip to content

Commit af83f67

Browse files
committed
windows arm64 build fixes
1 parent da0b826 commit af83f67

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

winbuild/build_prepare.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ def cmd_msbuild(
118118
"(LEGAL ISSUES\n============\n\n.+?)\n\nREFERENCES\n=========="
119119
".+(libjpeg-turbo Licenses\n======================\n\n.+)$"
120120
),
121+
"patch": {
122+
r"CMakeLists.txt": {
123+
# libjpeg-turbo does not detect MSVC x86_arm64 cross-compiler correctly
124+
'if(MSVC_IDE AND CMAKE_GENERATOR_PLATFORM MATCHES "arm64")': "if({architecture} STREQUAL ARM64)", # noqa: E501
125+
},
126+
},
121127
"build": [
122128
*cmds_cmake(
123129
("jpeg-static", "cjpeg-static", "djpeg-static"),
@@ -327,6 +333,8 @@ def cmd_msbuild(
327333
"CMakeLists.txt": {
328334
"if(OPENMP_FOUND)": "if(false)",
329335
"install": "#install",
336+
# libimagequant does not detect MSVC x86_arm64 cross-compiler correctly
337+
"if(${{CMAKE_SYSTEM_PROCESSOR}} STREQUAL ARM64)": "if({architecture} STREQUAL ARM64)", # noqa: E501
330338
}
331339
},
332340
"build": [
@@ -367,12 +375,17 @@ def cmd_msbuild(
367375

368376

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

384+
if architecture == "ARM64":
385+
tools = "Microsoft.VisualStudio.Component.VC.Tools.ARM64"
386+
else:
387+
tools = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
388+
376389
try:
377390
vspath = (
378391
subprocess.check_output(
@@ -383,7 +396,7 @@ def find_msvs() -> dict[str, str] | None:
383396
"-latest",
384397
"-prerelease",
385398
"-requires",
386-
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
399+
tools,
387400
"-property",
388401
"installationPath",
389402
"-products",
@@ -654,7 +667,7 @@ def build_dep_all() -> None:
654667
arch_prefs = ARCHITECTURES[args.architecture]
655668
print("Target architecture:", args.architecture)
656669

657-
msvs = find_msvs()
670+
msvs = find_msvs(args.architecture)
658671
if msvs is None:
659672
msg = "Visual Studio not found. Please install Visual Studio 2017 or newer."
660673
raise RuntimeError(msg)
@@ -689,6 +702,11 @@ def build_dep_all() -> None:
689702
disabled += ["libimagequant"]
690703
if args.no_fribidi:
691704
disabled += ["fribidi"]
705+
elif args.architecture == "ARM64" and platform.machine() != "ARM64":
706+
import warnings
707+
708+
warnings.warn("Cross-compiling FriBiDi is currently not supported, disabling")
709+
disabled += ["fribidi"]
692710

693711
prefs = {
694712
"architecture": args.architecture,

0 commit comments

Comments
 (0)