bazelbuild / bazelbuild/rules_rust
rust_binary linking broken when a cc_library output name collides with another library
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
### **Summary**
rust_binary fails to link when a cc_library produces an artifact named `libX` that collides with a library `libX`.
cc_binary linking the same cc_library succeeds.
### **Minimal repro**
1. Create a cc_library that builds a local library named `lib` that depends both on a library named `log` and references symbols provided by `liblog` (e.g. __android_log_print).
2. Create a rust_binary that depends on that cc_library (`lib`) and build for android_aarch64
3. Observe undefined references to the `__android_log_print`; **a cc_binary depending on the same cc_library links fine**. Also, when I make `lib` not depending on my `log` library it links well to __android_log_print.
### **Where I reproduced it**
I reproduced this in the rules_rust examples:
https://github.com/bazelbuild/rules_rust/tree/main/examples/nix_cross_compiling
This was my modified `examples/nix_cross_compiling/cc_library/BUILD.bazel`:
```
load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "cc_library",
srcs = ["cc_library.cc"],
linkopts = ["-llog"],
linkstatic = True,
tags = ["platform_missing"],
deps = [":log"],
)
cc_library(
name = "log",
srcs = ["log.cpp"],
hdrs = ["log.hpp"],
)
```
### **Original real-world repro**
I originally hit this when building a binary that used `protbuf` and `abseil`. The undefined symbols in that case were Abseil symbols — I suspect this may be related to `abseil` exposing a cc_library named `log` which could collide with a system `liblog`.
Contributor guide
Assessment
This issue has not been assessed yet.