microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.88k stars 6.31k forks source link

VS 2019 triplet silently fails building when both VCPKG_VISUAL_STUDIO_PATH and VCPKG_PLATFORM_TOOLSET are specified #12486

Closed lab2k1 closed 2 years ago

lab2k1 commented 4 years ago

Bug When a triplet specifies both VCPKG_VISUAL_STUDIO_PATH (pointing to VS 2019) and VCPKG_PLATFORM_TOOLSET (= v142, v141 or v140) vcpkg install goes through the motions of checking/preparing the package but then silently skips the build step, without reporting any error.

Environment

To Reproduce The issue is not specific to a particular package, but taking for example the zlib package:

  1. Copy triplets\x64-windows.cmake to triplets\x64-windows-v141.cmake.
  2. Edit triplets\x64-windows-v141.cmake and add the following two lines at the end (replace of course the path with the VS 2019 root path on your machine).
    set(VCPKG_VISUAL_STUDIO_PATH "X:\\bin\\vs2019")
    set(VCPKG_PLATFORM_TOOLSET v141)
  3. Run vcpkg install zlib[core] --triplet x64-windows-v141.
  4. vcpkg drops out after displaying the line Building package zlib[core]:x64-windows-v141... without anything being built.

Expected behavior The command line should have built zlib:x64-windows-v141 with VS 2019 and the v141 toolset.

Failure logs Default vcpkg output:

X:\bin\vcPkg>vcpkg install zlib[core] --triplet x64-windows-v141
Computing installation plan...
The following packages will be built and installed:
    zlib[core]:x64-windows-v141
Starting package 1/1: zlib:x64-windows-v141
Building package zlib[core]:x64-windows-v141...

With --debug:

X:\bin\vcPkg>vcpkg --debug install zlib[core] --triplet x64-windows-v141
[DEBUG] Using vcpkg-root: X:\bin\vcPkg
[DEBUG] Using buildtrees-root: X:\bin\vcPkg\buildtrees
[DEBUG] Using downloads-root: X:\bin\vcPkg\downloads
[DEBUG] Using packages-root: X:\bin\vcPkg\packages
[DEBUG] Using installed-root: X:\bin\vcPkg\installed
[DEBUG] Using scripts-root: X:\bin\vcPkg\scripts
Computing installation plan...
[DEBUG] CreateProcessW("X:\bin\vcPkg\downloads\tools\cmake-3.17.2-windows\cmake-3.17.2-win32-x86\bin\cmake.exe" --version)
[DEBUG] cmd_execute_and_stream_data() returned 0 after   237289 us
[DEBUG] CreateProcessW("X:\bin\vcPkg\downloads\tools\cmake-3.17.2-windows\cmake-3.17.2-win32-x86\bin\cmake.exe" "-DVCPKG_ROOT_DIR=X:/bin/vcPkg" "-DPACKAGES_DIR=X:/bin/vcPkg/packages" "-DBUILDTREES_DIR=X:/bin/vcPkg/buildtrees" "-D_VCPKG_INSTALLED_DIR=X:/bin/vcPkg/installed" "-DDOWNLOADS=X:/bin/vcPkg/downloads" -P "X:/bin/vcPkg/buildtrees/0.vcpkg_tags.cmake")
[DEBUG] cmd_execute_and_stream_data() returned 0 after   180890 us
The following packages will be built and installed:
    zlib[core]:x64-windows-v141
[DEBUG] <abientries>
[DEBUG] portfile.cmake|3480e8cb8c1df66c455820588cf637841a2004a2
[DEBUG] cmake_dont_build_more_than_needed.patch|380b131349bf645f05637612e4a9a04ed8ba6349
[DEBUG] CONTROL|5a745a5fdf7009f92bfadac3b5cfe9685c7e11f7
[DEBUG] usage|b446f7466dead962527355c13bbb617213098938
[DEBUG] LICENSE|e23c6e5f40647ee2f817439d3858531fb0753c9d
[DEBUG] cmake|3.17.2
[DEBUG] powershell|ab1effc926b000a6adc12198a1886514ec203621a53b0cd7ec1cd9a8225dccda7e857feaabcfba4004bea73129b986abaad777c4573f44e0af70411226ce08b0
[DEBUG] vcpkg_fixup_cmake_targets|dac334f3bf50b8262be92623168023aa565aa729
[DEBUG] post_build_checks|2
[DEBUG] triplet|8c6e2d58dee29f4bcf954d73e9807a427ac0ec1d
[DEBUG] features|core
[DEBUG] </abientries>
Starting package 1/1: zlib:x64-windows-v141
Building package zlib[core]:x64-windows-v141...
[DEBUG] CreateProcessW("C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -all -prerelease -legacy -products * -format xml)
[DEBUG] cmd_execute_and_stream_data() returned 0 after   176692 us
[DEBUG] ..\src\vcpkg\vcpkgpaths.cpp(259)    <----------------------------------------- highlighted in RED
[DEBUG] Exiting after 676547 us (676167 us)

Additional context The error line in the --debug run points to Checks::check_exit(VCPKG_LINE_INFO, candidates.size() == 1); in VcpkgPaths::get_toolset (in toolsrc\src\vcpkg\vcpkgpaths.cpp).

Debugging into vcpkg shows that the candidates array has 2 elements at that point, indeed, both identical and both pointing to the same (correct) VS 2019 v141 toolset. But the code requires a unique match in order to proceed, so it considers this to be an error case and abends with an exit_fail.

The same problem exists for the other valid VCPKG_PLATFORM_TOOLSET values v142 and v140. In fact, the problem is even worse for those, because for example every single 14.2x.xx toolset (14.22.27905, 14.26.28801 etc) is counted as v142, so the candidates array has 4 different entries listed twice each, for a total of 8 elements for VCPKG_PLATFORM_TOOLSET v142. And VCPKG_PLATFORM_TOOLSET v140 has 5 different entries, duplicated for a total of 10 (on my machine, this would depend on the history of VS updates on each machine so ymmv).

Summary of what I believe needs to be fixed

Cheney-W commented 2 years ago

This issue has disappeared in the latest vcpkg 2022-05-05-67e17c1782801cf481be9ac0b3765dff3e4bdeb8.