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

Set the Windows SDK version selected by vcvarsall.bat to VCPKG_CMAKE_SYSTEM_VERSION. #1532

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ namespace vcpkg
}

#if defined(_WIN32)
static ZStringView to_vcvarsall_target(StringView cmake_system_name)
static ZStringView to_vcvarsall_target(StringView cmake_system_name, StringView cmake_system_version)
{
if (cmake_system_name.empty()) return "";
if (cmake_system_name == "Windows") return "";
if (cmake_system_name.empty()) return {cmake_system_version.data(), cmake_system_version.size()};
if (cmake_system_name == "Windows") return {cmake_system_version.data(), cmake_system_version.size()};
if (cmake_system_name == "WindowsStore") return "store";
Comment on lines +316 to 318
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not analyzed everything this code is doing, but returning "store" in one path and returning a version number in another path is almost certainly wrong.

Moreover, this does not meet the ZStringView requirements because it's returning a pointer that it claims is null terminated with inputs that are not null terminated.


Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgUnsupportedSystemName, msg::system_name = cmake_system_name);
Expand Down Expand Up @@ -597,7 +597,7 @@ namespace vcpkg
}

const auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture, toolset, pre_build_info.triplet);
const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name);
const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name, pre_build_info.cmake_system_version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want this to select the Windows SDK, I believe you need something like this instead?

auto vcvarsall_options = toolset.vcvarsall_options;
if (!pre_build_info.cmake_system_version.empty()) {
    vcvarsall_options.push_back(fmt::format("-winsdk={}", pre_build_info.cmake_system_version));
}

based on

vcvarsall help text

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "vcvarsall.bat" is enough. And I have test it locally.
Using Visual Studio 2022:
image
Using Visual Studio 2019:
image
I believe on the old or new version of visual studio, "vcvarsall.bat" can achieve the same function.
Your suggestion about using "Toolset::vcvarsall_options" is more reasonable.


return vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c").raw_arg(
fmt::format(R"("{}" {} {} {} {} 2>&1 <NUL)",
Expand Down
Loading