bazelbuild / bazelbuild/rules_rust

`rust_bindgen` rejects `CcInfo` dependencies with only a dynamic library

Open
#4,233 1 comment 0 reactions 1 assignee Claimed by @krasimirgg View on GitHub
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

**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`:

```starlark
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`:

```starlark
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`:

```c
int foo(void);
```

`fake_bindgen.c`:

```c
int main(void) {
return 0;
}
```

`foo.c`:

```c
#include "foo.h"

int foo(void) {
return 42;
}
```

Run:

```console
bazel build --nobuild //:bindings
```

The build fails during analysis with:

```text
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.