Skip to content

[usbipdcpp] New port: A C++ library for creating usbip servers#50973

Open
yunsmall wants to merge 1 commit into
microsoft:masterfrom
yunsmall:add-usbipdcpp
Open

[usbipdcpp] New port: A C++ library for creating usbip servers#50973
yunsmall wants to merge 1 commit into
microsoft:masterfrom
yunsmall:add-usbipdcpp

Conversation

@yunsmall
Copy link
Copy Markdown

@yunsmall yunsmall commented Apr 5, 2026

Summary

This PR adds a new port for usbipdcpp, a C++ library for creating USB/IP servers.

Features

  • USB/IP server implementation via libusb (works on all libusb-compatible platforms)
  • Virtual HID device support (cross-platform, no libusb required)
  • Hot-plug support for automatic device insertion/removal detection
  • Asynchronous architecture using C++20 coroutines and asio
  • Extensible design with abstract interfaces

Features available

  • coroutine: Use C++20 coroutine-based implementation
  • libusb: Build libusb-based server components for physical USB device forwarding

Usage

find_package(usbipdcpp CONFIG REQUIRED)
target_link_libraries(main PRIVATE usbipdcpp::usbipdcpp)

# With libusb support
find_package(usbipdcpp CONFIG REQUIRED COMPONENTS libusb)
target_link_libraries(main PRIVATE usbipdcpp::usbipdcpp usbipdcpp::libusb)

Checklist

- Changes comply with the https://github.com/microsoft/vcpkg-docs/blob/main/vcpkg/contributing/maintainer-guide.md.
- The packaged project shows strong association with the chosen port name.
  - The port name follows the 'GitHubOrg-GitHubRepo' form or equivalent Owner-Project form (github.com/yunsmall/usbipdcpp).
- Optional dependencies of the build are all controlled by the port (libusb is controlled by libusb feature).
- The versioning scheme in vcpkg.json matches what upstream says.
- The license declaration in vcpkg.json matches what upstream says (Apache 2.0).
- The installed as the "copyright" file matches what upstream says.
- The source code of the component installed comes from an authoritative source (GitHub release).
- The generated "usage text" is brief and accurate.
- The version database is fixed by rerunning ./vcpkg x-add-version --all and committing the result.
- Exactly one version is added in each modified versions file.

@yunsmall
Copy link
Copy Markdown
Author

yunsmall commented Apr 5, 2026

@microsoft-github-policy-service agree

@yunsmall yunsmall force-pushed the add-usbipdcpp branch 2 times, most recently from 8b46118 to 1da552a Compare April 6, 2026 18:11
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/yunsmall-usbipdcpp/portfile.cmake
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/usage Outdated
Comment thread ports/usbipdcpp/vcpkg.json Outdated
Comment on lines +20 to +22
"coroutine": {
"description": "Use C++20 coroutine-based implementation"
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this an alternative (see our docs)?

@vicroms vicroms marked this pull request as draft April 6, 2026 20:51
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 3 times, most recently from 9a83e2d to 6ae4cd9 Compare April 7, 2026 14:16
@yunsmall
Copy link
Copy Markdown
Author

yunsmall commented Apr 7, 2026

@vicroms Thank you for the review! I've made the following changes:

  1. ✅ Used vcpkg_check_features instead of manual if/else
  2. ✅ Removed unnecessary environment variable operations
  3. ✅ Simplified vcpkg_cmake_config_fixup
  4. ✅ Simplified the usage file

Regarding whether coroutine is an alternative: It's not a mutually exclusive alternative but an internal implementation detail (similar to bullet3's double/single precision feature), which is transparent to users.

Also added a busywait feature for lower latency mode.

@yunsmall yunsmall requested a review from vicroms April 7, 2026 14:42
@yunsmall yunsmall marked this pull request as ready for review April 7, 2026 14:42
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 2 times, most recently from 6599ac3 to 065535f Compare April 7, 2026 18:46
Copy link
Copy Markdown
Contributor

@dg0yt dg0yt left a comment

Choose a reason for hiding this comment

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

FTR there is PR template for new ports, with a checklist.

Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/portfile.cmake Outdated
Comment thread ports/usbipdcpp/usage Outdated
@vicroms vicroms marked this pull request as draft April 8, 2026 07:31
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 2 times, most recently from 0e6e2ff to b8689d3 Compare April 8, 2026 16:04
@yunsmall yunsmall marked this pull request as ready for review April 8, 2026 16:05
@yunsmall
Copy link
Copy Markdown
Author

yunsmall commented Apr 8, 2026

@dg0yt Thank you for the review! I've applied all the suggested changes:

  1. ✅ Updated to REF "v${VERSION}"
  2. ✅ Fixed FEATURES indentation
  3. ✅ Added quotes for CMake options
  4. ✅ Updated usage file format

Regarding the two targets: usbipdcpp::libusb is an actual artifact (a static library usbipdcpp_libusb), not just a wrapper for
external libusb. It contains the libusb-based server implementation code. Users need to link both targets when using the libusb feature.

@yunsmall yunsmall marked this pull request as draft April 8, 2026 17:45
@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 9, 2026

It contains the libusb-based server implementation code. Users need to link both targets when using the libusb feature.

So the usage file unconditionally recommends a target which is subject to feature control. Users invited to make mistakes.

Could you just drop the usage file? vcpkg tool's heuristical output will list the targets which are actually installed.

The file also lacks a newline at the end.

@yunsmall
Copy link
Copy Markdown
Author

yunsmall commented Apr 9, 2026

@dg0yt Done. I've removed the usage file and added MAYBE_UNUSED_VARIABLES for PKG_CONFIG_EXECUTABLE to fix the warning. Thank you for the review!

@yunsmall yunsmall force-pushed the add-usbipdcpp branch 2 times, most recently from 056d83a to 5f38519 Compare April 9, 2026 12:52
@yunsmall yunsmall marked this pull request as ready for review April 9, 2026 12:52
@yunsmall yunsmall requested a review from dg0yt April 9, 2026 12:56
@yunsmall yunsmall marked this pull request as draft April 9, 2026 15:17
@yunsmall yunsmall marked this pull request as ready for review April 9, 2026 16:25
@yunsmall yunsmall marked this pull request as draft April 9, 2026 17:30
@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 9, 2026

This still needs vcpkg x-add-version usbipdcpp, and adding the new versions/u-/usbipdcpp.json to git.

@yunsmall yunsmall marked this pull request as ready for review April 22, 2026 16:09
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

  • The port name follows the 'GitHubOrg-GitHubRepo' form or equivalent Owner-Project form (github.com/yunsmall/usbipdcpp).

This would mean the name should be yunsmall-usbipdcpp not just usbipdcpp

  • The version database is fixed by rerunning ./vcpkg x-add-version --all and committing the result.
  • Exactly one version is added in each modified versions file.

If this had been done, your builds would be green.

Comment thread ports/yunsmall-usbipdcpp/portfile.cmake Outdated
Comment thread ports/yunsmall-usbipdcpp/vcpkg.json Outdated
],
"features": {
"busywait": {
"description": "Enable busy-wait mode for lower latency"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this an alternative? Is there any reason we should not just always do this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

busywait is a latency optimization feature that trades CPU efficiency for lower latency. It's not default behavior — only useful in specific low-latency scenarios. Most users don't need it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The way you describe it sounds like an alternative, not a feature. In particular, it sounds like a user could want to require that the feature is off which is not a thing features do. I think the port should pick one and this feature should not be added as a result.

"libusb"
]
},
"virtual-device": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we have this feature or just always do this? Just because the upstream build system has a thing does not mean we should expose them as features.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The virtual device component adds build overhead and is only needed when creating software-emulated USB devices. Users who only forward physical devices via libusb don't need this. Upstream default is ON because examples depend on it, but for vcpkg users it should be opt-in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure I agree; consider that package managers like apt et al. effectively only have one feature setting and people are fine with it. If it's not a substantial build time increase we may as well follow upstream's default. But in this case I'll defer to someone who clearly wants to actually use the library.

Comment thread ports/yunsmall-usbipdcpp/vcpkg.json Outdated
Comment thread ports/yunsmall-usbipdcpp/portfile.cmake Outdated
@BillyONeal BillyONeal marked this pull request as draft April 23, 2026 00:03
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 5 times, most recently from b9237e0 to a0d0d32 Compare May 5, 2026 14:53
@yunsmall yunsmall marked this pull request as ready for review May 5, 2026 15:23
@yunsmall yunsmall requested a review from BillyONeal May 5, 2026 15:54
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 3 times, most recently from 15028de to b668a03 Compare May 5, 2026 17:38
Copy link
Copy Markdown
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

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

"Request changes" over the "busywait" feature looking like an alternative and the version database being broken.

Comment thread ports/yunsmall-usbipdcpp/vcpkg.json Outdated
],
"features": {
"busywait": {
"description": "Enable busy-wait mode for lower latency"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The way you describe it sounds like an alternative, not a feature. In particular, it sounds like a user could want to require that the feature is off which is not a thing features do. I think the port should pick one and this feature should not be added as a result.

"libusb"
]
},
"virtual-device": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure I agree; consider that package managers like apt et al. effectively only have one feature setting and people are fine with it. If it's not a substantial build time increase we may as well follow upstream's default. But in this case I'll defer to someone who clearly wants to actually use the library.

Comment thread versions/y-/yunsmall-usbipdcpp.json
@BillyONeal BillyONeal marked this pull request as draft May 5, 2026 23:20
@yunsmall yunsmall force-pushed the add-usbipdcpp branch 5 times, most recently from e0899c3 to 1134fc9 Compare May 31, 2026 17:40
@yunsmall yunsmall marked this pull request as ready for review May 31, 2026 17:42
@yunsmall
Copy link
Copy Markdown
Author

@BillyONeal Thanks for the review. Here's what I've addressed:

  1. busywait — Removed entirely. The busy-wait code path has been deleted upstream, so there's no corresponding CMake
    option anymore.
  2. Version database — Fixed. Only one version entry (1.0.4) remains.
  3. virtual-device — Kept as a feature. The virtual device code is a substantial separate component; it's not relevant for users who only want to forward physical USB devices, and
    embedded targets (ESP32) may want to skip it to reduce binary size. That said, I'm open to making it always-on if you feel strongly about it.

Let me know if there's anything else.

@yunsmall yunsmall requested a review from BillyONeal May 31, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants