Description
rust_bindgen fails during analysis when its cc_lib supplies a LibraryToLink containing a dynamic_library but no static library.
The current implementation handles static_library and pic_static_library, but does not handle dynamic_library. As a result, it reports that no static libraries were found.
Reproduction steps
MODULE.bazel:
module(name = "repro")
bazel_dep(name = "rules_cc", version = "0.2.22")
bazel_dep(name = "rules_rust", version = "0.73.0")
bazel_dep(name = "rules_rust_bindgen", version = "0.73.0")
register_toolchains("//:bindgen_toolchain")
BUILD.bazel:
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library", "cc_shared_library")
load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen", "rust_bindgen_toolchain")
cc_binary(
name = "fake_bindgen",
srcs = ["fake_bindgen.c"],
)
rust_bindgen_toolchain(
name = "bindgen_toolchain_impl",
bindgen = ":fake_bindgen",
default_rustfmt = False,
)
toolchain(
name = "bindgen_toolchain",
toolchain = ":bindgen_toolchain_impl",
toolchain_type = "@rules_rust_bindgen//:toolchain_type",
)
cc_library(
name = "foo_objects",
srcs = ["foo.c"],
hdrs = ["foo.h"],
)
cc_shared_library(
name = "foo_shared",
deps = [":foo_objects"],
)
cc_import(
name = "foo",
hdrs = ["foo.h"],
shared_library = ":foo_shared",
)
rust_bindgen(
name = "bindings",
cc_lib = ":foo",
header = "foo.h",
)
foo.h:
fake_bindgen.c:
int main(void) {
return 0;
}
foo.c:
#include "foo.h"
int foo(void) {
return 42;
}
Run:
bazel build --nobuild //:bindings
The build fails during analysis with:
Error in fail: No static libraries found in @@//:foo
Impact
This blocks rust_bindgen for C/C++ dependencies that are available only as dynamic libraries. Using a static version of the dependency is a workaround when one is available.
Bazel and rules_rust version
- Bazel: 9.2.0
- rules_rust: 0.73.0
- rules_rust_bindgen: 0.73.0
Description
rust_bindgenfails during analysis when itscc_libsupplies aLibraryToLinkcontaining adynamic_librarybut no static library.The current implementation handles
static_libraryandpic_static_library, but does not handledynamic_library. As a result, it reports that no static libraries were found.Reproduction steps
MODULE.bazel:BUILD.bazel:foo.h:fake_bindgen.c:foo.c:Run:
bazel build --nobuild //:bindingsThe build fails during analysis with:
Impact
This blocks
rust_bindgenfor C/C++ dependencies that are available only as dynamic libraries. Using a static version of the dependency is a workaround when one is available.Bazel and rules_rust version