microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22k stars 6.12k forks source link

[libusb] build failure #38200

Closed GregDomzalski closed 1 week ago

GregDomzalski commented 1 month ago

Operating system

Windows Server 2022 10.0.20348

Compiler

MSVC

Steps to reproduce the behavior

`vcpkg.json`:

{
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
  "dependencies": [
    "libusb"
  ]
}
cmake_minimum_required(VERSION 3.10)

project(Vcpkg.Repro VERSION 1.0.0)

# This is how libusb package requests that it be consumed
find_package(PkgConfig REQUIRED)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)

add_library(Vcpkg.Repro SHARED test.c)

target_include_directories(Vcpkg.Repro PRIVATE ${LIBUSB_INCLUDE_DIRS})
target_link_libraries(Vcpkg.Repro PRIVATE PkgConfig::libusb)
cmake -S . -B build_out -A arm64 -DCMAKE_TOOLCHAIN="C:/Users/Greg/Source/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=arm64-windows-static

Failure logs

cmake -S . -B build_out/cmake/win-x86 -A Win32 -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x86-windows-static -DRID=win-x86

-- Building for: Visual Studio 17 2022
-- Running vcpkg install
Detecting compiler hash for triplet x64-windows...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
Detecting compiler hash for triplet x86-windows-static...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x86/cl.exe
Dependency graph submission enabled.
Dependency graph submission successful.
The following packages will be built and installed:
    libusb:x86-windows-static@1.0.27#1
    openssl:x86-windows-static@3.2.1#2
  * pkgconf:x64-windows@2.2.0
  * vcpkg-cmake:x64-windows@2023-05-04
  * vcpkg-cmake-config:x64-windows@2022-02-06#1
  * vcpkg-cmake-get-vars:x64-windows@2023-12-31
  * vcpkg-msbuild:x64-windows@2023-08-08
  * vcpkg-pkgconfig-get-modules:x64-windows@2023-09-06
  * vcpkg-tool-meson:x64-windows@1.3.2#2
Additional packages (*) will be modified to complete this operation.
A suitable version of 7zip was not found (required v23.1.0) Downloading portable 7zip 23.1.0...
Downloading 7zip...
https://github.com/ip7z/7zip/releases/download/23.01/7z2301-extra.7z->C:\vcpkg\downloads\7z2301-extra.7z
Downloading https://github.com/ip7z/7zip/releases/download/23.01/7z2301-extra.7z
Extracting 7zip...
Restored 9 package(s) from GitHub Actions Cache in 2.9 s. Use --debug to see more details.
Installing 1/9 vcpkg-tool-meson:x64-windows@1.3.2#2...
Elapsed time to handle vcpkg-tool-meson:x64-windows: 9.2 ms
vcpkg-tool-meson:x64-windows package ABI: fa5e70dc3fc0c533a5d9c82bf826d758a1fef97008c700e1225ba4a533f5f482
Installing 2/9 pkgconf:x64-windows@2.2.0...
Elapsed time to handle pkgconf:x64-windows: 16.3 ms
pkgconf:x64-windows package ABI: 41f8c0146014f8e6ca5fe8bd682b70f8e7177cb8fb04106a4fad0bbc5a7864f6
Installing 3/9 vcpkg-pkgconfig-get-modules:x64-windows@2023-09-06...
Elapsed time to handle vcpkg-pkgconfig-get-modules:x64-windows: 5.72 ms
vcpkg-pkgconfig-get-modules:x64-windows package ABI: ed8d6c73313dbac6184bde12c91401d6508c119550cf21509602fa412197ac19
Installing 4/9 vcpkg-cmake:x64-windows@2023-05-04...
Elapsed time to handle vcpkg-cmake:x64-windows: 6.52 ms
vcpkg-cmake:x64-windows package ABI: 607244cc01ecd625888f51c73597d07ddc78430c6e095d32913262629f12977f
Installing 5/9 vcpkg-cmake-get-vars:x64-windows@2023-12-31...
Elapsed time to handle vcpkg-cmake-get-vars:x64-windows: 6.07 ms
vcpkg-cmake-get-vars:x64-windows package ABI: 378de37f355a54af3646ea894ee2c0c8097cbcf6a4936bdb45f1a97f365609ad
Installing 6/9 vcpkg-msbuild:x64-windows@2023-08-08...
Elapsed time to handle vcpkg-msbuild:x64-windows: 6.91 ms
vcpkg-msbuild:x64-windows package ABI: abb9d49dc7f22755c7d0960f[287](https://github.com/Yubico/Yubico.Production.SDK/actions/runs/8650419105/job/23719589706#step:4:288)547fc172246d09a0abfdaf26ae0e07fe01129
Installing 7/9 libusb:x86-windows-static@1.0.27#1...
Elapsed time to handle libusb:x86-windows-static: 9.52 ms
libusb:x86-windows-static package ABI: aff1ffe144d9e7531205abcbea7ef79267b6aa1c1a8167965d5f029d4a2bf18e
Installing 8/9 vcpkg-cmake-config:x64-windows@2022-02-06#1...
Elapsed time to handle vcpkg-cmake-config:x64-windows: 5.65 ms
vcpkg-cmake-config:x64-windows package ABI: aa12c9294b62ae4a12dbf0c6f849413edfa9faa492ebb3039d54cc949413523b
Installing 9/9 openssl:x86-windows-static@3.2.1#2...
Elapsed time to handle openssl:x86-windows-static: 74.4 ms
openssl:x86-windows-static package ABI: fe62e[293](https://github.com/Yubico/Yubico.Production.SDK/actions/runs/8650419105/job/23719589706#step:4:294)1a1e9ea1b485acbf5057def0c93f8fee2a15d0264be8661a9d17f2a9
Total install time: 140 ms
libusb can be imported via CMake FindPkgConfig module:
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)

    target_link_libraries(main PRIVATE PkgConfig::libusb)

The package openssl is compatible with built-in CMake targets:

    find_package(OpenSSL REQUIRED)
    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)

-- Running vcpkg install - done
-- The C compiler identification is MSVC 19.38.33135.0
-- The CXX compiler identification is MSVC 19.38.33135.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.38.33130/bin/HostX64/x86/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.38.3[313](https://github.com/Yubico/Yubico.Production.SDK/actions/runs/8650419105/job/23719589706#step:4:314)0/bin/HostX64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.29/Modules/FindPkgConfig.cmake:114 (find_package_handle_standard_args)
  C:/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!

Additional context

This is failing for me both locally and in the latest GitHub Actions (windows-latest) runner. Last successful build used the 20240403 image. Builds began failing in the next update 20240407.

I've tried:

I have compared the logs from our internal builds - it seems that in the older build there is an extra line mentioning Strawberry Perl being present and it finding PkgConfig via that. That line is missing in the failure logs.

-- Found PkgConfig: C:/Strawberry/perl/bin/pkg-config.bat (found version "0.26")
dg0yt commented 1 month ago
  • Adding PkgConfig as an explicit dependency.

  • Installing PkgConfig using vcpkg install.

  • Confirming PkgConfig exe is in the vcpkg build tree (it is).

It is not clear what you mean by "PkgConfig" here. The only port which provides a suitable implementation is called pkgconf. If you want to use it, remember to request it with "host": true.

last successful build used the 20240403 image. Builds began failing in the next update 20240407.

Note that 20240407 comes with CMake 3.29.1. This version builds many ports incorrectly, #37968.

GregDomzalski commented 1 month ago

Apologies - your interpretation is correct, I misspoke and meant to say that I had tried to use pkgconf in case that could aid in resolving the issue.

I did not know about the "host": true. I may try that.

However it does seem very plausible that this is simply another manifestation of #37968. Thank you for alerting me to that issue.

It looks like the next GitHub actions runner image in the release queue updates to CMake 3.29.2. I can see if manually updating to 3.29.2 (or downgrading to 3.28.x) will resolve this. If so, I will close this issue out.

Thank you for your quick reply.

GregDomzalski commented 1 month ago

I've tried both actions mentioned in the other thread for updating to CMake 3.29.2. Both seem to successfully update, but neither have addressed the issue I'm facing.

I should also note that building x64-osx, arm64-osx works just fine. It's only the windows triplets that are giving me trouble.

dg0yt commented 1 month ago

CMake was only a side note, to avoid the next trouble.

jimwang118 commented 1 month ago

The triplet compiled by your test program is arm64-windows-static, but the libusb you installed is x86-windows-static. You need to install libusb:arm64-windows-static.

dg0yt commented 1 month ago

The triplet compiled by your test program is arm64-windows-static, but the libusb you installed is x86-windows-static. You need to install libusb:arm64-windows-static.

Well, the request is for arm64, but not for static. The first cmake command line is for arm64, the second one and the output are not.

And now I see that the host (x64-windows) pkgconf is already installed as a dependency...

GregDomzalski commented 1 month ago

The triplet compiled by your test program is arm64-windows-static, but the libusb you installed is x86-windows-static. You need to install libusb:arm64-windows-static.

Right. Sorry - I pulled logs from a private repo that cross builds x64 and arm64. The arm64 host is my local development machine, the x64 host is the GitHub CI runner. Both hosts will build both target triplets. Both hosts fail with the same error above, so I thought I could just grab either of the logs.

To avoid anymore confusion, I think what I will do is create a minimal repro in a public repository and use that from now on. That way anyone can try it out.

I really appreciate you all looking, and I apologize if I've wasted any of your time by trying to save a few minutes of mine. :disappointed: I'll post back once I have the public repo/repro available.

GregDomzalski commented 1 month ago

OK. I have created a repro repository here: https://github.com/GregDomzalski/vcpkg-github-repro-20240407

A failed build run is here: https://github.com/GregDomzalski/vcpkg-github-repro-20240407/actions/runs/8710631351/job/23892943452

It looks to be specific to the *-windows-static triplets. I was unable to reproduce it with just x64-windows, for example - as seen here: https://github.com/GregDomzalski/vcpkg-github-repro-20240407/actions/runs/8709845222/job/23890424011

Both runs are on the new 20240414 GitHub Actions runner image with CMake 3.29.2...

GregDomzalski commented 1 month ago

The log diffs look pretty much identical except for the timings and hashes on certain lines.

failed.txt success.txt

Let me know if there are any additional files or logs that would be helpful.

jimwang118 commented 1 month ago

You need to set PKG_CONFIG_EXECUTABLE in cmakelists.txt, for example: set(PKG_CONFIG_EXECUTABLE "${VCPKG_INSTALLED_DIR}/x64-windows/tools/pkgconf/pkgconf.exe")

dg0yt commented 1 month ago

If port pkgconf is properly installed via vcpkg, then the vcpkg.cmake toolchain should already make it discoverable to find_package(PkgConfig) by its settings to CMAKE_PROGRAM_PATH.

https://github.com/microsoft/vcpkg/blob/501cb01e517ee5689577bb01ba8bd1b4c1041a53/scripts/buildsystems/vcpkg.cmake#L557-L582

GregDomzalski commented 1 month ago

@dg0yt is right. This tool is automatically discovered for other triplets. The *-static triplets also previously worked like this but now do not. @jimwang118 this does seem like a regression somewhere. Not saying that it's necessarily the libusb port itself. But something has recently changed where this used to work and now it does not.

dg0yt commented 1 month ago

I don't think it is very much related to particular triplets. However, the default triplet is x64-windows. x64-windows-static is a (vcpkg) cross build when building ports.

But the toolchain is stupid. It doesn't treat x64-windows-static as a cross build (and enable VCPKG_CAN_USE_HOST_TOOLS) when building the user project unless the user sets VCPKG_HOST_TRIPLET.

Couldn't the toolchain be a little bit smarter? Wait... somebody tried with https://github.com/microsoft/vcpkg/pull/25529.

github-actions[bot] commented 3 weeks ago

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