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

Conversation

thegoodtgg
Copy link

According to VCPKG_CMAKE_SYSTEM_VERSION not work. #41723, pass value of VCPKG_CMAKE_SYSTEM_VERSION as target to "vcvarsall.bat"

@BillyONeal
Copy link
Member

The documentation for VCPKG_CMAKE_SYSTEM_VERSION is that we pass it to CMake as CMAKE_SYSTEM_VERSION. Can you explain the relationship between CMAKE_SYSTEM_VERSION and vcvarsall.bat that suggests this is the correct outcome?

Thanks for your contribution!

@thegoodtgg
Copy link
Author

Yes. I see the desc about VCPKG_CMAKE_SYSTEM_VERSION from documentation.
When using with "ninja" generator, AFAIK,CMAKE_SYSTEM_VERSION make no sense. People who want using a different "Windows SDK Version", have to specify a target explicitly to vcvarsall.bat.
And when using CMake with "Visual Studio" generator, specify CMAKE_SYSTEM_VERSION would definitely change the "Windows SDK Version" the proj using.
To make vcpkg build packages using a different version of "Windows SDK", VCPKG_CMAKE_SYSTEM_VERSION maybe a choice.

Comment on lines +316 to 318
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";
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.

@@ -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.

@BillyONeal BillyONeal changed the title fix: repest to VCPKG_CMAKE_SYSTEM_VERSION. Set the Windows SDK version selected by vcvarsall.bat to VCPKG_CMAKE_SYSTEM_VERSION. Oct 28, 2024
Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

This 'request changes' is for the ZStringView out of contract use. I'm going to confirm with other maintainers if the overall change seems correct but it seems reasonable to me given the documentation page you mentioned.

@thegoodtgg
Copy link
Author

Windows SDK Version doesn't belong to msvc toolset. And as positional arguments, "winsdk_version" should be placed after "platform_type". So using ”vcvarsall_options“ maybe not be a good choice.

        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);
        // New function
        const auto winsdk = to_vcvarsall_winsdk(pre_build_info.cmake_system_version);

        return vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c").raw_arg(
            fmt::format(R"("{}" {} {} {} {} {} 2>&1 <NUL)",
                        toolset.vcvarsall,
                        Strings::join(" ", toolset.vcvarsall_options),
                        arch,
                        target,
                        winsdk,
                        tonull));

@BillyONeal
Copy link
Member

BillyONeal commented Oct 29, 2024

Windows SDK Version doesn't belong to msvc toolset.

Getting it into the environment does belong to vcvarsall.bat though.

And as positional arguments, "winsdk_version" should be placed after "platform_type".

Sure, I apologize for being unclear. I was posting that as a 'for example', the main point being that this needs to go into a -winsdk={} parameter instead of listed as a plain version number on vcvarsall.bat's command line.

There does not appear to be a positional parameter that sets the Windows SDK version.

// New function
const auto winsdk = to_vcvarsall_winsdk(pre_build_info.cmake_system_version);

Sure, separating into a separate function could be fine. I don't think it's required though.

@thegoodtgg
Copy link
Author

If we don't check the specified version of windows sdk installed, we could use

const auto winsdk = pre_build_info.cmake_system_version;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants