Skip to content

Say which cc_library attributes propagate to dependents - #57

Open
anakanemison wants to merge 1 commit into
mschaller/d4-long-commandsfrom
mschaller/d5-transitive-defines
Open

anakanemison wants to merge 1 commit into
mschaller/d4-long-commandsfrom
mschaller/d5-transitive-defines

Conversation

@anakanemison

@anakanemison anakanemison commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

CMake scopes a definition or include directory with PRIVATE or PUBLIC; in Bazel the attribute decides. "Create initial BUILD.bazel files" now lists defines, includes and linkopts as propagating, and copts, local_defines, local_includes and implementation_deps as private, so a private define such as <target>_EXPORTS goes in local_defines. local_includes needs rules_cc 0.2.19 or later; the text gives the copts fallback.

The per-TU diff cannot see the mistake: a private define written as defines converges and changes how every consumer compiles. No any2bazel-lab run has been seen making it; a lensfun agent avoided it unprompted, and again with an earlier one-sentence version of this change.

Stacked on #56 (tracking issue: #35). pytest tests/: 186 passed (132 on main). Lab proposal: P7.

🤖 Generated with Claude Code

Comment thread SKILL.md Outdated
grouping-agnostic), but keep **executable** names aligned or add a `target_map`
entry. Write `MODULE.bazel` as needed — before picking rulesets or pinning
`cc_binary` with `srcs`, `hdrs`, `copts`, `defines`, `includes`, `deps`. Bazel's
`defines` propagate to every dependent; a define the reference keeps private to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should cover more of these:

defines, includes, quote_includes, and linkopts all do. copts, local_defines, local_includes do not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now says defines/includes/linkopts propagate, local_defines/local_includes/copts don’t, and implementation_deps is for private headers.

I left out quote_includes, which isn’t a cc_library attribute, as far as I can tell. Appears to be a field in CcInfo's compilation context?

CMake scopes a compile definition or include directory to a target
(PRIVATE) or its consumers (PUBLIC/INTERFACE). In Bazel the attribute
decides: `defines`, `includes` and `linkopts` propagate to every
dependent, while `copts`, `local_defines` and `local_includes` stay with
the target, and `implementation_deps` keeps a dependency's headers private.
The per-TU diff only checks that each TU gets what CMake gave it, so a
PRIVATE define written as `defines` converges while changing how every
consumer compiles (a visibility macro such as <target>_EXPORTS turning on
export-side behavior in consumers is the classic case). The only signal
would be a WARN-level extra define on each consumer's TUs.

"Create initial BUILD.bazel files" now lists both groups and says where
private defines and include directories go. `local_includes` arrived in
rules_cc 0.2.19 (June 2026), so the text gives the `copts` -I fallback for
older versions. The scopes are as Bazel's cc_library documentation states
them.

Observed in any2bazel-lab: a lensfun migration avoided this unprompted,
putting its visibility and <target>_EXPORTS defines in local_defines for
exactly this reason. No run has yet been seen getting it wrong. In the
lab's later lensfun run with an earlier version of this change (one
sentence, on defines only), the agent again kept those defines in
local_defines.

Lab-Proposal: P7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anakanemison
anakanemison removed this pull request from stack #59 November 2, 2026 17:49
@anakanemison
anakanemison force-pushed the mschaller/d5-transitive-defines branch from 9456ead to c20829e Compare November 2, 2026 17:51
@anakanemison anakanemison changed the title Warn that Bazel's defines are transitive (for discussion) Say which cc_library attributes propagate to dependents Nov 2, 2026
@anakanemison
anakanemison added this pull request to stack #63 November 2, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants