| commit | a9de1b5681027046dffb803a791ea32f90db6d69 | [log] [tgz] |
|---|---|---|
| author | Armando Montanez <amontanez@google.com> | Fri Mar 14 15:10:52 2025 -0700 |
| committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Fri Mar 14 15:10:52 2025 -0700 |
| tree | 4062233526292f1b71bf2956fce32541ec7e7629 | |
| parent | 1d1e40d428166a18fc75bfd250bf8cb048b215ac [diff] |
Fix Windows link issues Fixes a couple Windows link issues: * User32.Lib was missing. * Due to a missing interface library property, libusb would not properly link unless added to dynamic_deps of every cc_binary that used it when --@rules_libusb//:force_dynamic_linkage=True. Also renames the underlying cc_shared_library so the produced artifacts have less-surprising names. Bug: b/347353308 Change-Id: I61a670d7e91836c5b742fe046baa619410de6d06 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/rules_libusb/+/276016 Reviewed-by: Ted Pudlik <tpudlik@google.com> Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com> Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com> Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com> Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
A small wrapper Bazel module that builds libusb from sources. Supports Windows, macOS, and Linux.
At this time, rules_libusb only supports bzlmod projects. Legacy WORKSPACE projects are not explicitly supported.
Add rules_libusb to your MODULE.bazel file:
bazel_dep(name = "rules_libusb", version="0.1.0-rc1")
libusb = use_extension("@rules_libusb//:extensions.bzl", "libusb")
# Versioning constraints are optional.
libusb.source_release(min_version = "1.0.27")
use_repo(libusb, "libusb")
Note: source_release constraints follow bzlmod behavior of minimal version selection.
Then add to the tool that requires libusb:
cc_binary(
name = "my_tool",
srcs = ["main.cpp"],
deps = ["@libusb//:libusb"],
)
The libusb build file offers two targets to help guide link behavior:
//:libusb: The generic cc_library for libusb. Most build targets should just use this.//:libusb_dynamic: The actual libusb dynamic/shared library (e.g. libusb-1.0.so).By default, @libusb//:libusb will always dynamically link. This can be disabled by toggling the flag that controls this:
bazel build //... --@rules_libusb//:force_dynamic_linkage=False
When @rules_libusb//:force_dynamic_linkage is disabled, the link behavior is fully controlled by your build system, and can be controlled on a per-binary basis by specifying dynamic_deps on build targets that require dynamic linkage of libusb:
cc_binary(
name = "my_tool",
srcs = ["main.cpp"],
deps = ["@libusb//:libusb"],
dynamic_deps = ["@libusb//:libusb_dynamic"],
)
To build this repo, run:
bazel build @libusb//:libusb