bazelbuild / bazelbuild/bazel

CcInfo.compilation_context does not contain data from `implementation_deps`

Open
#19,663 10 comments 4 reactions 1 assignee Claimed by @buildbreaker2021 View on GitHub
P2 team-Rules-CPP team-Rules-ObjC type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

Implementation_deps doc: https://bazel.build/reference/be/c-cpp#cc_library.implementation_deps

If I understand correctly, if a target `libB` depends directly on `libA` via `implementation_deps` it should have access to `A`'s includes, defines etc. Only the target that would depend on B (and transitively on A) would have them hidden. Unfortunately, from the perspective of CcInfo.compilation_context, the targets which are `implementation_deps` are just ignored.

### Which category does this issue belong to?

C++/Objective-C Rules

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

```py
File: libA/BUILD
cc_library(
name = "libA",
srcs = ["lib.cpp"],
defines = ["FOO=1"],
visibility = ["//visibility:public"],
)
```
```py
File: libB/BUILD
cc_library(
name = "libB",
srcs = ["lib.cpp"],
defines = ["BAR=0"],
implementation_deps = ["//libA"],
visibility = ["//visibility:public"],
)
```

Command:
```
bazel cquery //libB --output=starlark --starlark:expr="providers(target)['CcInfo'].compilation_context.defines"
```

Observed:
```
depset(["BAR=0"]
```

Expected:
```
depset(["BAR=0", "foo=1"])
```
EDIT: this also applies to other fields, like `includes`

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

Fedora aarch64

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

release 6.3.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 master; 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

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.