Skip to content

The VCPKG_LOAD_VCVARS_ENV option cannot be used to disable vcvars loading #40480

Open
microsoft/vcpkg-tool
#1511
@dpaoliello

Description

Describe the bug
If you set the VCPKG_LOAD_VCVARS_ENV to false, then vcpkg will still launch a VS Command prompt to get the vcvars environment.

Environment

  • OS: Windows

To Reproduce
Steps to reproduce the behavior:

  1. Create a custom triplet with set(VCPKG_LOAD_VCVARS_ENV OFF). For example:
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_LOAD_VCVARS_ENV OFF)
  1. Run a build with no compiler on the PATH, no LIB env var set, etc.

Expected behavior
vcpkg/CMake complains that it can't find a compiler.

Additional context
The bug occurs when vcpkg uses the value load_vcvars_env which is set by VCPKG_LOAD_VCVARS_ENV:

    bool PreBuildInfo::using_vcvars() const
    {
        return (!external_toolchain_file.has_value() || load_vcvars_env) &&
               (cmake_system_name.empty() || cmake_system_name == "WindowsStore");
    }

If there is no external toolchain file (VCPKG_CHAINLOAD_TOOLCHAIN_FILE is not set) then !external_toolchain_file.has_value() is true and so the value of load_vcvars_env is ignored, thus VCPKG_LOAD_VCVARS_ENV cannot be used to disable vcvargs loading.

It could, however, be used to re-enable vcvars loading if VCPKG_CHAINLOAD_TOOLCHAIN_FILE was set - but that's not what the documentation indicates it does: "Determines whether vcpkg will search for and use an instance of Visual Studio as part of the triplet environment."

For anyone who came across this issue looking for a way to disable vcvars loading WITHOUT using a custom toolchain file, the workaround is to add set(VCPKG_CMAKE_SYSTEM_NAME Windows) to your triplet.

It should be noted that changing the behavior now would be a breaking change, which I'm not sure how vcpkg handles.

Metadata

Assignees

Labels

category:vcpkg-bugThe issue is with the vcpkg system (including helper scripts in `scripts/cmake/`)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions