bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
656 stars 419 forks source link

rust_bindgen should not require a static library #2704

Open neilisaac opened 3 months ago

neilisaac commented 3 months ago

rust_bindgen currently asserts that the cc_lib has an associated static library to link: https://github.com/bazelbuild/rules_rust/blob/main/bindgen/private/bindgen.bzl#L140. This is problematic for use cases where this cannot be satisfied.

Example use cases:

Ideally rust_bindgen should just be a code generator that does not impose any additional requirements not needed by bindgen itself, or a separate un-opinionated interoperable code generation rule should be provided.

neilisaac commented 3 months ago

I worked around this by generating an empty .cc file and creating a dummy cc_library target that depends on it + the headers, which is passed to cc_lib, then I wrap rust_bindgen with a rust_library that adds the real shared object to deps.