Skip to content

Commit

Permalink
Improve error messages for missing MSVC for ARM64
Browse files Browse the repository at this point in the history
This is a follow up commit to my previous commit [1], which made
build_qt.py compatible with ARM64 host and/or target (google#1121)

One remaining pitfall is that ARM64 C++ compiler needs to be explicitly
selected when installing Visual Studio on the x64 environment.

With this commit at least you can see a clear message that the compiler
is missing when you try to build Qt for ARM64 without installing the
required optional component.

 [1]: a0fed62
  • Loading branch information
yukawa committed Nov 19, 2024
1 parent d4c4adb commit 6c89385
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/build_tools/vs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
from typing import Union


def get_vcvarsall(path_hint: Union[str, None] = None) -> pathlib.Path:
def get_vcvarsall(
arch: str,
path_hint: Union[str, None] = None
) -> pathlib.Path:
"""Returns the path of 'vcvarsall.bat'.
Args:
arch: host/target architecture
path_hint: optional path to vcvarsall.bat
Returns:
Expand Down Expand Up @@ -78,12 +82,17 @@ def get_vcvarsall(path_hint: Union[str, None] = None) -> pathlib.Path:
'Microsoft.VisualStudio.Product.Professional',
'Microsoft.VisualStudio.Product.Community',
'Microsoft.VisualStudio.Product.BuildTools',
'-requires',
'Microsoft.VisualStudio.Component.VC.Redist.14.Latest',
'-find',
'VC/Auxiliary/Build/vcvarsall.bat',
'-utf8',
]
cmd += [
'-requires',
'Microsoft.VisualStudio.Component.VC.Redist.14.Latest',
]
if arch.endswith('arm64'):
cmd += ['Microsoft.VisualStudio.Component.VC.Tools.ARM64']

process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
Expand All @@ -103,11 +112,18 @@ def get_vcvarsall(path_hint: Union[str, None] = None) -> pathlib.Path:

vcvarsall = pathlib.Path(stdout.splitlines()[0])
if not vcvarsall.exists():
raise FileNotFoundError(
'Could not find vcvarsall.bat.'
'Consider using --vcvarsall_path option e.g.\n'
msg = 'Could not find vcvarsall.bat.'
if arch.endswith('arm64'):
msg += (
' Make sure Microsoft.VisualStudio.Component.VC.Tools.ARM64 is'
' installed.'
)
else:
msg += (
' Consider using --vcvarsall_path option e.g.\n'
r' --vcvarsall_path=C:\VS\VC\Auxiliary\Build\vcvarsall.bat'
)
)
raise FileNotFoundError(msg)

return vcvarsall

Expand Down Expand Up @@ -151,7 +167,7 @@ def get_vs_env_vars(
ChildProcessError: When 'vcvarsall.bat' cannot be executed.
FileNotFoundError: When 'vcvarsall.bat' cannot be found.
"""
vcvarsall = get_vcvarsall(vcvarsall_path_hint)
vcvarsall = get_vcvarsall(arch, vcvarsall_path_hint)

pycmd = (r'import json;'
r'import os;'
Expand Down

0 comments on commit 6c89385

Please sign in to comment.