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

vcpkg adds target rather than host paths to CMAKE_PROGRAM_PATH #30220

Closed
craigscott-crascit opened this issue Mar 15, 2023 · 8 comments
Closed
Assignees
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed Stale

Comments

@craigscott-crascit
Copy link

Describe the bug
Calls to find_program() are generally going to want to find executables that can run on the host, not on the target architecture. At the moment, vcpkg adds the tools directory of the target triplet install area to CMAKE_PROGRAM_PATH, but not the tools directory of the host triplet's install area. When adding a host dependency that provides a tool (in my case the motivating example are things like ccache and sccache, which we are experimenting with providing via a private vcpkg registry), those tools are not able to be found due to CMAKE_PROGRAM_PATH not including the subdirectories under the host triplet's tools area.

I think adding the target triplet's tools subdirectories to CMAKE_PROGRAM_PATH is questionable, but not adding the host triplet's tools subdirectories definitely looks like a bug to me. It is currently breaking some of our projects that want to provide command line tools when using a custom target triplet.

Don't focus on the ccache and sccache part of this, I only use those as examples. There are other problems we are uncovering with trying to have those as host dependencies, but we will follow that up in separate issues and discussions. The bug report here is focused on incorrect population of the CMAKE_PROGRAM_PATH variable.

Environment

  • OS: all
  • Compiler: all

To Reproduce

Steps to reproduce the behavior:

  1. Create a manifest file that lists at least one host dependency that provides a command line tool.
  2. In the project, add a find_program() call for that command line tool.
  3. Run CMake generation with the host triplet being different to the target triplet. In our case, we use a custom target triplet and the default triplet for the host.

Observe that the tool will not be found, even though vcpkg provides it in the host triplet's install area.

Expected behavior

Calls to find_program() should succeed when a host dependency provides the requested tool.

@craigscott-crascit
Copy link
Author

craigscott-crascit commented Mar 15, 2023

It would appear that this bug only occurs if you let vcpkg determine the host triplet. If you explicitly set VCPKG_HOST_TRIPLET, then vcpkg (correctly) adds the host triplet's tools subdirectories to CMAKE_PROGRAM_PATH instead of those from the target triplet.

@craigscott-crascit
Copy link
Author

The relevant logic appears to be

option(VCPKG_SETUP_CMAKE_PROGRAM_PATH "Enable the setup of CMAKE_PROGRAM_PATH to vcpkg paths" ON)
set(VCPKG_CAN_USE_HOST_TOOLS OFF)
if(DEFINED VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL "")
set(VCPKG_CAN_USE_HOST_TOOLS ON)
endif()
cmake_dependent_option(VCPKG_USE_HOST_TOOLS "Setup CMAKE_PROGRAM_PATH to use host tools" ON "VCPKG_CAN_USE_HOST_TOOLS" OFF)
unset(VCPKG_CAN_USE_HOST_TOOLS)
if(VCPKG_SETUP_CMAKE_PROGRAM_PATH)
set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools")
if(VCPKG_USE_HOST_TOOLS)
set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}/tools")
endif()
which was added by #23322. The logic before that change was still wrong though (looks like previously the host tools were never being added to CMAKE_PROGRAM_PATH).

CC: @Neumann-A

@dg0yt
Copy link
Contributor

dg0yt commented Mar 16, 2023

Related: #25529

@Neumann-A
Copy link
Contributor

It would appear that this bug only occurs if you let vcpkg determine the host triplet.

So I assume it works ;)
Not defining a host triplet just assumes old behavior.

In the end it comes down to CMake itself being ambiguous what find_program really means and vcpkg being undecided about it. There was also somewhere a long discussion about it but i am currently unable to find it.

@FrankXie05 FrankXie05 added category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed and removed category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly labels Mar 16, 2023
@github-actions
Copy link

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

@github-actions github-actions bot added the Stale label Sep 13, 2023
@craigscott-crascit
Copy link
Author

Eh, why auto-stale an open, unresolved issue?

@autoantwort
Copy link
Contributor

So a solution would be to rebuilt the host triplet selection in vcpkg.cmake or call vcpkg z-print-config to get the host triplet?

@github-actions github-actions bot removed the Stale label Sep 14, 2023
Copy link

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

@github-actions github-actions bot added the Stale label Mar 28, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed Stale
Projects
None yet
Development

No branches or pull requests

5 participants