bazelbuild / bazelbuild/bazel

Transitive `cc_shared_library` doesn't work with inline functions

Open
#21,819 21 comments 1 reaction 0 assignees View on GitHub
P3 team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

`cc_shared_library` and `dynamic_deps` deliberately link the shared libraries for only direct dependencies, while excluding the corresponding static libraries transitively. If any of the direct dependencies have inline functions which use transitive dependencies, this can result in linking failures. This is common with C++ code, it's less common but I think it's still possible with C.

Having to specify all the transitive dependencies in `dynamic_deps` is not good. It's even worse because sometimes with some compilers and some optimization settings it's necessary, and other times it's not (it depends on what gets inlined where).

Linking all of the transitive shared libraries seems low-cost. They're going to be needed at runtime anyways. Would that be an acceptable change?

### Which category does this issue belong to?

C++ Rules

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

https://github.com/brians-neptune/bazel-cc_shared_library-transitive-deps has a `main_dynamic` target which fails to link, but I think it should. `main_static` is the same thing without `dynamic_deps`, which does link.

### Which operating system are you running Bazel on?

Ubuntu 22.04

### What is the output of `bazel info release`?

release 7.0.2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the linked cc_shared_library-transitive-deps reproduction and compare the main_dynamic and main_static targets. Then trace Bazel's cc_shared_library and dynamic_deps handling for direct versus transitive dependencies. Done means the dynamic target links without explicitly listing every transitive dependency, with the intended behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.