Skip to content

Conversation

@Thomas1664
Copy link
Contributor

@Thomas1664 Thomas1664 commented Sep 9, 2025

I noticed that the path /msys64/ slips through when checking if the CMake binary is from msys.

Related issues: https://github.com/microsoft/vcpkg/issues?q=is%3Aissue%20state%3Aopen%20%22Command%20failed%3A%20C%3A%2Fmsys64%22

Closes microsoft/vcpkg#47171
Closes microsoft/vcpkg#46391
Closes microsoft/vcpkg#46188
Closes microsoft/vcpkg#44155
Closes microsoft/vcpkg#44154
Closes microsoft/vcpkg#47135

@Thomas1664 Thomas1664 changed the title Add msys64/ucrt64/bin to msys detection for cmake tool on Windows Add /msys64/ to msys detection for cmake tool on Windows Sep 9, 2025
@dg0yt
Copy link
Contributor

dg0yt commented Sep 9, 2025

The original code is a very precise heuristics to detect MSYS/Cygwin environment cmake (i.e. the one which only understands POSIX paths and doesn't offer VS generators, https://packages.msys2.org/base/cmake).

What you try to detect/prevent now is cmake from the windows environment offered by msys2 (i.e. probably offering VS generators but somewhat broken around invoking RC for the Ninja generator,
https://packages.msys2.org/base/mingw-w64-cmake). This is a different problem, and the heuristics isn't significant at all, for positives and for negatives.

Not fixed by the /msys2/ heuristics:
microsoft/vcpkg#47171: Windows cmake, C:/msys64/ucrt64/bin/cmake.exe
microsoft/vcpkg#46391: Windows cmake, C:/msys64/clang64/bin/cmake.exe
microsoft/vcpkg#46188: Windows cmake, C:/msys64/ucrt64/bin/cmake.exe
microsoft/vcpkg#44155,
microsoft/vcpkg#44154: Windows cmake, C:/msys64/mingw64/bin/cmake.exe
microsoft/vcpkg#47135: Windows cmake, F:/msys64/ucrt64/bin/cmake.exe

The real common thing is that paths end in <mingw-env>/bin,
https://www.msys2.org/docs/environments/

@Thomas1664
Copy link
Contributor Author

Not fixed by the /msys2/ heuristics:

Given that the title mentions /msys64/ and the paths also contain that string, you could have just pointed out that I had a typo in my code...

I think it's more efficient to search for /msys64/ because that requires only one comparison in contrast to 5 if I only considered the end of the path (the function is called cheap_is_acceptable after all). Furthermore, I'd consider it very likely that a cmake executable under the path /msys64/ belongs in fact to msys2.

What you try to detect/prevent now is cmake from the windows environment offered by msys2 (i.e. probably offering VS generators but somewhat broken around invoking RC for the Ninja generator,
https://packages.msys2.org/base/mingw-w64-cmake).

Judging by the comment on line 400, it's also intended to avoid using msys2's cmake.

@dg0yt
Copy link
Contributor

dg0yt commented Sep 10, 2025

Judging by the comment on line 400, it's also intended to avoid using msys2's cmake.

The comment says "version can't handle 'C:' in paths", but this is true only for /usr/bin/cmake.exe and /cygwin/bin/cmake.exe.
The windows environment cmakes (/ucrt64/bin/cmake.exe, /clang64/bin/cmake.exe, /mingw64/bin/cmake.exe) do handle C:.

I think it's more efficient to search for /msys64/ because that requires only one comparison in contrast to 5 if I only considered the end of the path (the function is called cheap_is_acceptable after all).

I think it is still extremely cheap to explicitly check the small set of known short strings at the end of the path.
At least in contrast to invoking the executable.

@dg0yt
Copy link
Contributor

dg0yt commented Sep 10, 2025

.. and path.find is a search operation, path.ends_with is a trivial comparison.

@BillyONeal
Copy link
Member

Is there anything that distinguishes the problematic CMakes in the --version output, since we're running that to check the version already anyway.

@dg0yt
Copy link
Contributor

dg0yt commented Oct 2, 2025

Is there anything that distinguishes the problematic CMakes in the --version output, since we're running that to check the version already anyway.

Quick check:

Not sure if the msvc suffix is robust enough:
official (windows): cmake version 3.31.6-msvc
msys2 (ucrt64): cmake version 4.1.0

Alternatively, I can point at the generator list from cmake -G, in particular the default generator marked by *:
official (windows): * Visual Studio 17 2022 ...
msys2 (ucrt64): * Ninja ...
(msys2 (msys runtime): No Visual Studio generators!)

There is also cmake --system-information but it is slow on Windows

@BillyONeal
Copy link
Member

Not sure if the msvc suffix is robust enough:
official (windows): cmake version 3.31.6-msvc
msys2 (ucrt64): cmake version 4.1.0

Unfortunately not:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise>where cmake
C:\Program Files\CMake\bin\cmake.exe
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe

C:\Program Files\Microsoft Visual Studio\2022\Enterprise>cmake --version
cmake version 4.1.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

C:\Program Files\Microsoft Visual Studio\2022\Enterprise>

@dg0yt
Copy link
Contributor

dg0yt commented Oct 3, 2025

IMO it is sufficient and cheap to determine the parent dir of bin/cmake.exe, and to match it against the fairly stable list of msys environments (usr,mingw32,mingw64,ucrt64,clang64,clangarm64).

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

Labels

None yet

Projects

None yet

3 participants