Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dpaoliello opened this issue Aug 15, 2024 · 3 comments · May be fixed by microsoft/vcpkg-tool#1511
Open
Assignees
Labels
category:vcpkg-bug The issue is with the vcpkg system (including helper scripts in `scripts/cmake/`)

Comments

@dpaoliello
Copy link

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.

@MonicaLiu0311 MonicaLiu0311 added the category:vcpkg-bug The issue is with the vcpkg system (including helper scripts in `scripts/cmake/`) label Aug 16, 2024
@jimwang118
Copy link
Contributor

jimwang118 commented Oct 15, 2024

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

@dpaoliello
Copy link
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
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:vcpkg-bug The issue is with the vcpkg system (including helper scripts in `scripts/cmake/`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants