Repository navigation
[vcpkg.cmake] Add VCPKG_PREFER_HOST_TOOLS, on by default - #54781
Billy O'Neal (BillyONeal) merged 1 commit into
Conversation
VCPKG_USE_HOST_TOOLS puts only the host triplet's tools in CMAKE_PROGRAM_PATH. That breaks build tools that come with a target port and are not available as host tools, such as wxrc from wxwidgets. Add VCPKG_PREFER_HOST_TOOLS, which searches the host triplet's tools first and then the target triplet's. It is on by default when VCPKG_HOST_TRIPLET is set, in place of VCPKG_USE_HOST_TOOLS, which is now off by default and still takes precedence when set. Unless it is already set, CMAKE_FIND_ROOT_PATH_MODE_PROGRAM becomes NEVER for cross builds, so find_program() does not find a target tool first because it is under the find root. Tools found for the target triplet, such as wxrc, may not run on the build machine when cross compiling. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Rafael Kitover <rkitover@gmail.com>
|
If this is merged, I have a doc update as well: |
There was a problem hiding this comment.
🔵 Needs a closer look
Changes to default tool discovery and global find_program root handling require cross-platform CMake validation of host/target precedence and chainloaded-toolchain interactions unavailable in this review environment.
No open issues 🎉
What changed in this PR
Updates vcpkg’s CMake integration to prefer host tools while allowing fallback to target-triplet tools, such as wxwidgets’ wxrc.
Changes:
- Adds
VCPKG_PREFER_HOST_TOOLS, enabled by default when a host triplet is available. - Makes
VCPKG_USE_HOST_TOOLSopt-in while preserving its precedence and host-only behavior. - Defaults program root-path searching to
NEVERwhen preferring tools across different triplets, unless explicitly configured.
| File | Description |
|---|---|
scripts/buildsystems/vcpkg.cmake |
Adds host-first tool discovery with target fallback and adjusts program search defaults. |
Review effort: Balanced
Billy O'Neal (BillyONeal)
left a comment
There was a problem hiding this comment.
Thank you! Can you submit that to the docs repo?
|
Do we really want to make searching both paths the default when vcpkg didn't do it in the past? Needing target triplet tools in cross builds might be an indication of a port bug in most cases. It can be opt-in for cases where it is really needed. (I'm skeptical about it being needed for Also, searching the host path first (which is right), which is the scenario where there is no host wxrc being found before the target wxrc? |
|
I would assume we want to use host tools for all builds, not just cross builds. This is currently not happening automatically without , which I pinged you guys on. Ideally we want host tools to be available for all build tools. But sometimes that is not the case, for example for In the case of So in this particular case, as things stand now, defining I'm guessing there are other build tools in this situation and there will be because ports are often imperfect. So the overall intent here, once these parts are done, is that in a normal non-cross-build host tools like |
I'm notified anyways, but I'm only a community member, and I am not willing to be the first human to review AI assisted PRs. Microsoft must have a look. Back to this PR. Correct me if I am wrong:
|
It would be better to search only the host one, but I assumed that would be too backcompat breaking.
I was under the impression that it did but I didn't verify. :/
I'm not sure I understand; in a non-cross build, host and target tools are the same. |
Correct,
Correct,
Right.
The target tools are already in Even if that were the case, I would expect the user's preference to be for vcpkg tools for their ports rather than something from |
It would in-fact be more correct. The issue is the situations where there is no host tool but there is a target tool, such as The change being default handles this situation at a slight cost of correctness with zero configuration, once all of the pieces are in place.
Suppose you are building for |
If it's not a backcompat issue I'm happy to tell people who have created those situations that they need to fix it in their portfile.cmake rather than globally. |
It is also a backcompat issue, because once |
|
The doc PR is here: |
|
FTR I'm not opposed to eventually moving to correct use of the host tools path (even if it is disruptive). I'm opposed to a partial behavioral change now and another partial behavioral change when proper host triplet passing landed. |
VCPKG_USE_HOST_TOOLS puts only the host triplet's tools in CMAKE_PROGRAM_PATH. That breaks build tools that come with a target port and are not available as host tools, such as wxrc from wxwidgets.
Add VCPKG_PREFER_HOST_TOOLS, which searches the host triplet's tools first and then the target triplet's. It is on by default when VCPKG_HOST_TRIPLET is set, in place of VCPKG_USE_HOST_TOOLS, which is now off by default and still takes precedence when set. Unless it is already set, CMAKE_FIND_ROOT_PATH_MODE_PROGRAM becomes NEVER for cross builds, so find_program() does not find a target tool first because it is under the find root.
Tools found for the target triplet, such as wxrc, may not run on the build machine when cross compiling.
Assisted-By: Claude Opus 5.5 noreply@anthropic.com