Skip to content

meson needs to choose MSVC toolset on the basis of target #11435

@mcdurdin

Description

@mcdurdin

When meson is attempting to locate MSVC using vswhere.exe, it has the opportunity to select the appropriate toolset for the target architecture. vsdevcmd.bat gives the following options in VS2019:

Syntax: vsdevcmd.bat [options]
[options] :
    -arch=architecture : Architecture for compiled binaries/libraries
           ** x86 [default]
           ** amd64
           ** arm
           ** arm64
    -host_arch=architecture : Architecture of compiler binaries
           ** x86 [default]
           ** amd64

vsdevcmd.bat was introduced in VS2017 under Common7/Tools and replaces VC/Auxiliary/Build/vcvarsall.bat. I have been told that vcvarsall.bat is gone in VS2022 (not verified).

At present, the target architecture is hard-coded to either amd64 or ARM, making it impossible, for example, to build a Windows x86 executable:

if windows_detect_native_arch() == 'arm64':
bat_path = bat_root / 'VC/Auxiliary/Build/vcvarsarm64.bat'
if not bat_path.exists():
bat_path = bat_root / 'VC/Auxiliary/Build/vcvarsx86_arm64.bat'
else:
bat_path = bat_root / 'VC/Auxiliary/Build/vcvars64.bat'
# if VS is not found try VS Express
if not bat_path.exists():
bat_path = bat_root / 'VC/Auxiliary/Build/vcvarsx86_amd64.bat'

The current workaround is of course to run vsdevcmd -arch=x86 before running meson setup, but this is troublesome when integrating with other shells (for example as noted in #2622 (comment)).

We encountered this issue when trying to simplify our meson builds at keymanapp/keyman#8279; I would submit a patch for meson but really not sure the right way to address this within meson 😄. Our desired approach would be for meson to figure out which toolchain architecture is needed for the target and use that to call vsdevcmd.bat/vcvarsall.bat with the -arch parameter.

The host architecture may be important for very large projects -- given it is either x86 or amd64, this should be easy enough to ascertain with the existing native architecture check?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions