Skip to content

[vcpkg.cmake] Support VCPKG_BUILD_TYPE triplets with VCPKG_APPLOCAL_DEPS#30059

Closed
rpjohnst wants to merge 3 commits intomicrosoft:masterfrom
rpjohnst:release-triplet-applocal
Closed

[vcpkg.cmake] Support VCPKG_BUILD_TYPE triplets with VCPKG_APPLOCAL_DEPS#30059
rpjohnst wants to merge 3 commits intomicrosoft:masterfrom
rpjohnst:release-triplet-applocal

Conversation

@rpjohnst
Copy link

@rpjohnst rpjohnst commented Mar 7, 2023

A triplet that sets VCPKG_BUILD_TYPE will (ports permitting) only have one set of installed files, rather than one for debug and one for release. The VCPKG_APPLOCAL_DEPS option copies installed libraries into the build directory, but uses a $<CONFIG:Debug> generator expression to decide which set of files to use, which leads to silent failures on these triplets.

(I realized this when GTest test discovery started failing after I switched from x64-windows to x64-windows-release, because it runs the test binary from its position in the build directory, but the gtest DLLs were no longer present. A similar problem, this one outside of vcpkg's control, is that DLL dependencies built in the same CMake build can easily wind up in different build subdirectories...)

Rather than assuming $<CONFIG:Debug> implies a debug/ installed directory, handle this like CMAKE_FIND_ROOT_PATH: Pass both variants of the installed bin directory to applocal.ps1, and let it check both of them in the appropriate order.

@JonLiu1993 JonLiu1993 changed the title Support VCPKG_BUILD_TYPE triplets with VCPKG_APPLOCAL_DEPS [vcpkg.cmake] Support VCPKG_BUILD_TYPE triplets with VCPKG_APPLOCAL_DEPS Mar 7, 2023
@JonLiu1993 JonLiu1993 added the category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly label Mar 7, 2023
@rpjohnst rpjohnst force-pushed the release-triplet-applocal branch 2 times, most recently from c8edd76 to 8dc1276 Compare March 9, 2023 03:45
@rpjohnst
Copy link
Author

rpjohnst commented Mar 9, 2023

Not sure what's going on with the CLA check- it neither finished nor commented here.

@rpjohnst rpjohnst closed this Mar 9, 2023
@rpjohnst rpjohnst reopened this Mar 9, 2023
JonLiu1993
JonLiu1993 previously approved these changes Mar 13, 2023
@JonLiu1993 JonLiu1993 added the info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. label Mar 13, 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the argument remain quoted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaped quotes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this will add , to the list of characters which must not be used in file paths.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworked this to use separate arguments to applocal.ps1 rather than a PowerShell array. This should also resolve the quoting issues, given the use of VERBATIM.

The solution for the X_VCPKG_APPLOCAL_DEPS_INSTALL is a bit less robust, but I'm not really sure how to accomplish this perfectly given the use of install(CODE ...).

@JonLiu1993 JonLiu1993 added requires:author-response and removed info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. labels Mar 13, 2023
@rpjohnst rpjohnst force-pushed the release-triplet-applocal branch 2 times, most recently from 16a12d5 to d26eb07 Compare March 19, 2023 19:22
@rpjohnst rpjohnst force-pushed the release-triplet-applocal branch from d26eb07 to 0a97440 Compare March 21, 2023 00:39
@rpjohnst
Copy link
Author

rpjohnst commented Mar 24, 2023

I'm a bit stuck on this arm64 failure. The error that does exist in the logs that got uploaded makes it look like pkgconf.exe got installed incorrectly in some way, but there is no copy-tool-dependencies-* log file to see what happened, and Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT is not included either. I don't have an ARM64 machine to run this locally.

Does anyone have any suggestions on better ways to debug this?

Edit: Hm, GitHub is showing me that arm64_windows actually passed on commit 0a97440, and the failure started with the merge from master. But I don't see any changes to the failing qca port there, or anything related to applocal other than the new XBox triplets. Maybe I missed something in there?

@JonLiu1993
Copy link
Contributor

I'm a bit stuck on this arm64 failure. The error that does exist in the logs that got uploaded makes it look like pkgconf.exe got installed incorrectly in some way, but there is no copy-tool-dependencies-* log file to see what happened, and Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT is not included either. I don't have an ARM64 machine to run this locally.

Does anyone have any suggestions on better ways to debug this?

Edit: Hm, GitHub is showing me that arm64_windows actually passed on commit 0a97440, and the failure started with the merge from master. But I don't see any changes to the failing qca port there, or anything related to applocal other than the new XBox triplets. Maybe I missed something in there?

@rpjohnst, I can help you test locally, could you please tell me how to test it?

@rpjohnst
Copy link
Author

@JonLiu1993 Sure, thanks! At this point I'm mostly wondering if a local build of qca:arm64-windows (the one that failed in the last CI run) would have any more detailed log output than what is available from Azure Pipelines, and in particular whether and how applocal.ps1 might be related to the pkgconf.exe failure that is visible in the existing logs.

@JonLiu1993
Copy link
Contributor

@JonLiu1993 Sure, thanks! At this point I'm mostly wondering if a local build of qca:arm64-windows (the one that failed in the last CI run) would have any more detailed log output than what is available from Azure Pipelines, and in particular whether and how applocal.ps1 might be related to the pkgconf.exe failure that is visible in the existing logs.

qca:arm64-windows is a CI error, not related to this PR, we will fix it as soon as possible.

Rather than assuming `$<CONFIG:Debug>` implies a `debug/` installed
directory, handle this like `CMAKE_FIND_ROOT_PATH`: applocal.ps1 now
accepts an array of directories to search for dependencies.
@rpjohnst rpjohnst force-pushed the release-triplet-applocal branch from 2bc8fac to ee7ff86 Compare April 1, 2023 19:50
@JonLiu1993 JonLiu1993 added the info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. label Apr 25, 2023
@BillyONeal BillyONeal added category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed and removed info:needs-maintainer-attention Lets the current 'on rotation' vcpkg maintainer know they need to look at this. labels Apr 25, 2023
@BillyONeal BillyONeal added the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Apr 25, 2023
@BillyONeal
Copy link
Member

I'm not convinced that this is the correct behavior:

  • a debug program choosing release dependencies almost always leads to silent ABI mismatch explosions at runtime or pragma detect_mismatch errors at link time, so ever silently falling back to release bits in debug builds or vice versa is bad news
  • this still doesn't actually fix msbuild because you didn't fix how the import libs and such are found
  • this is touching the powershell whose days are numbered entirely post replacing applocal.ps1 with C++ 😍 vcpkg-tool#814

I can see an argument for a "I am a release only triplet please only check release locations for me" but that wouldn't ever introduce 'try one and then the other' behavior.

Tagging vcpkg-team-review for other maintainers to look at...

@JonLiu1993
Copy link
Contributor

I will be converting your PR to draft status. The above suggested changes are only recommendations. If you are willing to adopt them, please click "ready for review" after making the modifications. If you do not wish to make any changes, please click "ready for review" directly. That way, I can be aware that you've responded since you can't modify the tags.

@JonLiu1993 JonLiu1993 marked this pull request as draft May 6, 2023 10:25
@BillyONeal
Copy link
Member

@dan-shaw @ras0219-msft @JavierMatosD @vicroms and I discussed this today. We affirm that this feature makes sense, but that this implementation has problems. In particular, "try one then fallback to the other" is not the correct behavior, at least on Windows.

  • this still doesn't actually fix msbuild because you didn't fix how the import libs and such are found

Don't forget to address this if you decide to pick this back up (the part that tries to add *.lib to the link line).

This might require the user explicitly telling us that they want no-debug behavior. (Which might already happen with:

<PropertyGroup>
  <VcpkgConfiguration>Release</VcpkgConfiguration>
</PropertyGroup>

)

@BillyONeal BillyONeal removed the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Jul 20, 2023
@rpjohnst
Copy link
Author

rpjohnst commented Jul 20, 2023

I probably won't have time to work on this in the near future, but some context on that issue in case anyone wants to pick it up (or for future me):

I went with the fallback approach based on how CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, and CMAKE_FIND_ROOT_PATH work(ed at the time?):

function(z_vcpkg_add_vcpkg_to_cmake_path list suffix)
set(vcpkg_paths
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}${suffix}"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug${suffix}"
)
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
list(REVERSE vcpkg_paths) # Debug build: Put Debug paths before Release paths.
endif()
if(VCPKG_PREFER_SYSTEM_LIBS)
list(APPEND "${list}" "${vcpkg_paths}")
else()
list(INSERT "${list}" "0" "${vcpkg_paths}") # CMake 3.15 is required for list(PREPEND ...).
endif()
set("${list}" "${${list}}" PARENT_SCOPE)
endfunction()
z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_PREFIX_PATH "")
z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_LIBRARY_PATH "/lib/manual-link")
z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_FIND_ROOT_PATH "")
. Specifically, this places the debug or release path first depending on the value of CMAKE_BUILD_TYPE, which supports single-build-type triplets via fallback built into CMake and toolchains.

In normal operation with both a build and release directory however, there actually is not supposed to be any really granular fallback going on, because both directories have the relevant files. So this may already be an issue if, for example, only one of the debug or release directories gets a generated file, and the other build type is supposed to search a different directory or not use it at all. (Probably not a common way to design a library, or this would have come up before.)

The reason I used this to replace the $<CONFIG:Debug> generator expressions is that generator expressions don't have access to VCPKG_BUILD_TYPE. And I seem to remember the further issue that z_vcpkg_add_vcpkg_to_cmake_path does not have access to VCPKG_BUILD_TYPE either, which is probably why it relies on the list ordering trick in the first place. So a "proper" fix for this is probably going to involve some plumbing to let vcpkg.cmake know about VCPKG_BUILD_TYPE somehow?

@JonLiu1993
Copy link
Contributor

Closing this PR since it seems that no progress is being made. Please ping us to reopen if work is still being done.

@JonLiu1993 JonLiu1993 closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants