a1ien / rusb

A safe Rust wrapper for libusb.
Other
401 stars 83 forks source link

Failing to build with regular/default vcpkg on Windows 10 #182

Closed mcclure closed 1 year ago

mcclure commented 1 year ago

I am trying to build on Windows 10 Build 19045 (with Cargo 1.69.0) a Rust project named ecpdap which has rusb as a dependency. On initial build it failed because it could not find vcpkg. Okay, fair enough. I install vpkg via the instructions and then I run vcpkg install libusb¹.

I open a new cmd.exe window and cd to the ecpdap directory. I run set VCPKG_ROOT=/path/to/vkpkg/checkout and then cargo.exe build.

It prints:

error: failed to run custom build command for `libusb1-sys v0.4.4`

Caused by:
  process didn't exit successfully: `C:\Users\Andi\work\f\other\ecpdap\target\debug\build\libusb1-sys-d41f348fb0d0863b\build-script-build` (exit code: 101)
  --- stdout
  Can't find libusb pkg: LibNotFound("package libusb is not installed for vcpkg triplet x64-windows-static-md")

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: NotFound, error: TarError { desc: "failed to create `C:\\Users\\Andi\\work\\f\\other\\ecpdap\\target\\debug\\build\\libusb1-sys-fd75480b6e25ea7c\\out\\source`", io: Custom { kind: NotFound, error: "The system cannot find the file specified. (os error 2) while canonicalizing C:\\Users\\Andi\\work\\f\\other\\ecpdap\\target\\debug\\build\\libusb1-sys-fd75480b6e25ea7c\\out\\source" } } }', C:\Users\Andi\.cargo\registry\src\github.com-1ecc6299db9ec823\libusb1-sys-0.4.4\build.rs:85:37
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I am going to try the "vendored" option for libusb next, but since I did everything by defaults, per the rusb instructions my "expected behavior" is this should work out of the box.


¹ It prints this. I notice the triplet is different from the one you are looking for but I don't know if this is meaningful. If you need me to install/build libusb with a specific vcpkg triplet you should probably document that.

C:\Users\Andi\work\g\other\vcpkg>vcpkg install libusb
warning: In the September 2023 release, the default triplet for vcpkg libraries changed from x86-windows to the detected host triplet (x64-windows). For the old behavior, add --triplet x86-windows . To suppress this message, add --triplet x64-windows .
Computing installation plan...
The following packages are already installed:
    libusb:x64-windows -> 1.0.26.11791#3
libusb:x64-windows is already installed
Total install time: 325 us
libusb provides CMake targets:

    find_package(libusb CONFIG REQUIRED)
    target_include_directories(main PRIVATE ${LIBUSB_INCLUDE_DIRS})
    target_link_libraries(main PRIVATE ${LIBUSB_LIBRARIES})

Thanks

mcclure commented 1 year ago

Wait, it is possible that my build steps here (building via a dependency of ecpdap) is forcing an out-of-date rusb. I will double check that the problem reproduces with current rusb.

mcclure commented 1 year ago

Wait, it is possible that my build steps here (building via a dependency of ecpdap) is forcing an out-of-date rusb. I will double check that the problem reproduces with current rusb.

Double checked with a direct checkout of rusb, most recent release tag (v0.9.3-rusb). Same results (IE same error)

a1ien commented 1 year ago

Can't find libusb pkg: LibNotFound("package libusb is not installed for vcpkg triplet x64-windows-static-md")

Please look how install done in CI https://github.com/a1ien/rusb/blob/master/.github/workflows/github-ci.yml

a1ien commented 1 year ago

You can read more documentation in vcpkg crate https://docs.rs/vcpkg/latest/vcpkg/