Skip to content

Certain build configurations are "less efficient" #76516

@tannergooding

Description

@tannergooding

Issue

The repo has two main places where vcvarsall.bat is called and therefore where the C++ environment is setup. These are:

To summarize, vcvarsall.bat allows a parameter in the form of host_target and therefore x86_x64 is host=x86, target=x64.

Examples

In the case of init-vs-env it defaults to assuming that the host (that is the machine we are building on) is always x86 and therefore restricts us to using the 32-bit x86 versions of the compilers and related tools.

In the case of build-runtime it has some complex handling that ultimately defaults to host=x64, target=x64 and otherwise uses host=x86, target=* where typically target=%__HostArch%. __HostArch itself defaults to __TargetArch unless the user passes in -hostarch *. __TargetArch matches the default -arch command line passed in.

Solution - init-vs-env

For init-vs-env we should check %PROCESSOR_ARCHITECTURE% and default back to x86 if unrecognized. This winds up with the most portability but also the least amount of emulation on platforms like Arm/Arm64. It likewise means we can make full advantage of modern build machines.

if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
    if /i "%~1" == "x86"   (set __VCBuildArch=x64_x86)
    if /i "%~1" == "x64"   (set __VCBuildArch=x64)
    if /i "%~1" == "arm"   (set __VCBuildArch=x64_arm)
    if /i "%~1" == "arm64" (set __VCBuildArch=x64_arm64)
    if /i "%~1" == "wasm"  (set __VCBuildArch=x64)
) else if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
    if /i "%~1" == "x86"   (set __VCBuildArch=arm64_x86)
    if /i "%~1" == "x64"   (set __VCBuildArch=arm64_x64)
    if /i "%~1" == "arm"   (set __VCBuildArch=arm64_arm)
    if /i "%~1" == "arm64" (set __VCBuildArch=arm64)
    if /i "%~1" == "wasm"  (set __VCBuildArch=arm64_x64)
) else if /i "%PROCESSOR_ARCHITECTURE%"=="ARM" (
    if /i "%~1" == "x86"   (set __VCBuildArch=arm_x86)
    if /i "%~1" == "x64"   (set __VCBuildArch=arm_x64)
    if /i "%~1" == "arm"   (set __VCBuildArch=arm)
    if /i "%~1" == "arm64" (set __VCBuildArch=arm_arm64)
    if /i "%~1" == "wasm"  (set __VCBuildArch=arm_x64)
) else (
    if /i "%~1" == "x86"   (set __VCBuildArch=x86)
    if /i "%~1" == "x64"   (set __VCBuildArch=x86_x64)
    if /i "%~1" == "arm"   (set __VCBuildArch=x86_arm)
    if /i "%~1" == "arm64" (set __VCBuildArch=x86_arm64)
    if /i "%~1" == "wasm"  (set __VCBuildArch=x86_x64)
)

Solution - build-runtime

For build-runtime the fix should ultimately be similar. I don't think we need __HostArch at all and instead should just detect it implicitly, requiring users to run the batch script from the correct command line environment.

If we wanted to keep __HostArch, it should correctly default to matching PROCESSOR_ARCHITECTURE if otherwise unspecified. It should likewise be used for the host portion of host_target. __TargetArch should then be used for the target portion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions