[vcpkg] Fix find_program search path host tools#31033
[vcpkg] Fix find_program search path host tools#31033ekilmer wants to merge 2 commits intomicrosoft:masterfrom
find_program search path host tools#31033Conversation
During port building, the `scripts/buildsystems/vcpkg.cmake` toolchain file needs to know the host triplet in order to correctly set up `CMAKE_PROGRAM_PATH` (to include the host triplet installation prefix) and `CMAKE_FIND_ROOT_PATH_MODE_PROGRAM` (to prevent including `CMAKE_FIND_ROOT_PATH`, which includes the target triplet's installation prefix and always appears first in searching during `find_*` calls) so that `find_program` _only_ looks in the host triplet installation prefix and system path(s). We also remove the addition of the target triplet installation prefix to `CMAKE_PREFIX_PATH` because these paths are _always_ searched first in `find_program` (and other `find_*` commands) and there is no way to selectively turn it off for only `find_program`. Removing this doesn't break things because we already set `CMAKE_FIND_ROOT_PATH`, which is searched first by the `find_*` commands (unless you turn it off like we do for `find_program` during crosscompilation). --------------------------------------------------------------------- The issue this commit solves can be evidenced by inspecting the search paths of the `find_*` calls for CMake projects when host and target triplets differ. The CMake search paths can be inspected by setting `CMAKE_FIND_DEBUG_MODE=ON`. For instance, on Intel x86_64 macOS, if we try to crosscompile `fmt` to arm64, we should first modify `ports/fmt/portfile.cmake` and add `-DCMAKE_FIND_DEBUG_MODE=ON` to `vcpkg_cmake_configure` and install: ```sh ./vcpkg \ --host-triplet=x64-osx-release \ --triplet=arm64-osx-release \ --binarysource=clear \ fmt ``` After it is done building, open the configuration log file (`buildtrees/fmt/config-arm64-osx-release-out.log`) and notice the paths listed after `find_program considered the following locations`. Before this fix, the included paths contained the _target triplet_ installation prefix, which is incorrect. After this commit, only the host triplet and host system paths are included, which is correct. Note: macOS and different architectures aren't _required_ to reproduce the issue, but it makes this fix more compelling and obvious---you don't want to find and run an executable of a different architecture. To reproduce on any system, you only need to specify a different host and target triplets.
|
This may break |
This is like depending on
Do you mean not enough to pass the host triplet? Your PR seems to touch mostly manifest-mode logic, which fixes an additional issue and not everything that this PR fixes (or so I claim), right? This PR is still valid even with your PR?
😬 That looks a bit unfortunate... Thank you for pointing that out! I will investigate more. |
| endif() | ||
| set("${list}" "${${list}}" PARENT_SCOPE) | ||
| endfunction() | ||
| z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_PREFIX_PATH "") |
There was a problem hiding this comment.
Check the blame/history. As far as I remember there was a comment for the empty path.
| vcpkg_list(APPEND arg_OPTIONS | ||
| "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" | ||
| "-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET}" | ||
| "-DVCPKG_HOST_TRIPLET=${HOST_TRIPLET}" |
There was a problem hiding this comment.
I think this file should never be touched again.
|
Pinging @ekilmer for response. Is work still being done for this PR? |
|
@LilyWangLL I have been unable to spend any time on this PR, but I still plan on revisiting when I have some time to sit down and figure out the cause of errors. |
|
Closing this PR since it seems that no progress is being made. Please ping us to reopen if work is still being done. |
|
@LilyWangLL Could you please reopen this (as a draft, until CI passes or not)? I've done more testing, and I think my new solution is better. |
The reopen button is invalid, and the message is: The fix-find-program-search-path-host-tools branch was force-pushed or recreated. |
./vcpkg x-add-version --alland committing the result.Description
During port building, the
scripts/buildsystems/vcpkg.cmaketoolchainfile needs to know the host triplet in order to correctly set up
CMAKE_PROGRAM_PATH(to include the host triplet installation prefix)and
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM(to prevent includingCMAKE_FIND_ROOT_PATH, which includes the target triplet's installationprefix and always appears first in searching during
find_*calls) sothat
find_programonly looks in the host triplet installationprefix and system path(s).
We also remove the addition of the target triplet installation prefix to
CMAKE_PREFIX_PATHbecause these paths are always searched first infind_program(and otherfind_*commands) and there is no way toselectively turn it off for only
find_program. Removing this doesn'tbreak things because we already set
CMAKE_FIND_ROOT_PATH, which issearched first by the
find_*commands (unless you turn it off like wedo for
find_programduring crosscompilation).The issue this commit solves can be evidenced by inspecting the search
paths of the
find_*calls for CMake projects when host and targettriplets differ. The CMake search paths can be inspected by setting
CMAKE_FIND_DEBUG_MODE=ON.For instance, on Intel x86_64 macOS, if we try to crosscompile
fmttoarm64, we should first modify
ports/fmt/portfile.cmakeand add-DCMAKE_FIND_DEBUG_MODE=ONtovcpkg_cmake_configureand install:After it is done building, open the configuration log file
(
buildtrees/fmt/config-arm64-osx-release-out.log) and notice the pathslisted after
find_program considered the following locations. Beforethis fix, the included paths contained the target triplet installation
prefix, which is incorrect. After this commit, only the host triplet and
host system paths are included, which is correct.
Note: macOS and different architectures aren't required to reproduce
the issue, but it makes this fix more compelling and obvious---you don't
want to find and run an executable of a different architecture. To
reproduce on any system, you only need to specify a different host and
target triplets.