Skip to content

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

@dpaoliello

Description

@dpaoliello

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.

Activity

added
category:vcpkg-bugThe issue is with the vcpkg system (including helper scripts in `scripts/cmake/`)
on Aug 16, 2024
jimwang118

jimwang118 commented on Oct 15, 2024

@jimwang118
Contributor

Following the steps you provided, I was unable to reproduce this issue.
Image

dpaoliello

dpaoliello commented on Oct 15, 2024

@dpaoliello
Author

I think you did reproduce the issue: with VCPKG_LOAD_VCVARS_ENV set to off, your build was still finding the MSVC compiler - it shouldn't be able to do that.

jimwang118

jimwang118 commented on Oct 16, 2024

@jimwang118
Contributor

I think you did reproduce the issue: with VCPKG_LOAD_VCVARS_ENV set to off, your build was still finding the MSVC compiler - it shouldn't be able to do that.

I understand what you mean. When I only use load_vcvars_env to determine whether to use vcvars, it prompts that the cxx compiler cannot be found.

github-actions

github-actions commented on Apr 14, 2025

@github-actions

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

dpaoliello

dpaoliello commented on Apr 21, 2025

@dpaoliello
Author

This is a new comment to stop the bot from closing this, since it isn't smart enough to see that there is an open PR to fix the issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

    Participants

    @dpaoliello@MonicaLiu0311@jimwang118

    Issue actions

      The `VCPKG_LOAD_VCVARS_ENV` option cannot be used to disable vcvars loading · Issue #40480 · microsoft/vcpkg