Skip to content

Util lib: use libraries directly instead of header forwarding lib - #30930

Closed
hzeller wants to merge 1 commit into
bazelbuild:masterfrom
hzeller:feature-20260831-utl
Closed

Util lib: use libraries directly instead of header forwarding lib#30930
hzeller wants to merge 1 commit into
bazelbuild:masterfrom
hzeller:feature-20260831-utl

Conversation

@hzeller

@hzeller hzeller commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Using a public library just to make headers visible is a bazel anti-pattern.

Operations:

# Remove all headers and dependcies on the forwarding library so that it is
# not considered a good candidate for bant dwyu.
buildozer 'remove hdrs' //src/main/cpp/util
buildozer 'remove deps' //src/main/cpp/util

# Add necessary visibility to the libraries to directly depend on
buildozer 'add visibility //src/test/cpp/util:__pkg__' //src/main/cpp/util:numbers
buildozer 'add visibility //src/test/cpp/util:__pkg__' //src/main/cpp/util:port

buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:filesystem
buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:md5
buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:numbers

# Fix all dependencies, but narrow to affected targtes with cpp/util in their path)
. <(bant dwyu ... -g cpp/util)

# Now, we can remove the dependency on the old util library.
buildozer 'remove deps //src/main/cpp/util' $(bant list-targets ... -g cc_ -c3)

# Now that it is not referenced anymore, it can be removed.
buildozer delete //src/main/cpp/util

@github-actions github-actions Bot added team-Rules-Java Issues for Java rules team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Aug 31, 2026
@hzeller
hzeller force-pushed the feature-20260831-utl branch 2 times, most recently from 0529843 to 41103dd Compare August 31, 2026 12:17
@meisterT meisterT added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Aug 31, 2026
@hzeller
hzeller force-pushed the feature-20260831-utl branch from 41103dd to 425925e Compare August 31, 2026 19:28
@hzeller

hzeller commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Alright, had to rebase as some BUILD files changed in the meantime.

Using a public library just to make headers visible is a bazel anti-pattern.

Operations:

```bash
 # Remove all headers and dependcies on the forwarding library so that it is
 # not considered a good candidate for bant dwyu.
buildozer 'remove hdrs' //src/main/cpp/util
buildozer 'remove deps' //src/main/cpp/util

 # Add necessary visibility to the libraries to directly depend on
buildozer 'add visibility //src/test/cpp/util:__pkg__' //src/main/cpp/util:numbers
buildozer 'add visibility //src/test/cpp/util:__pkg__' //src/main/cpp/util:port

buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:filesystem
buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:md5
buildozer 'add visibility //src/main/cpp:__subpackages__' //src/main/cpp/util:numbers

 # Fix all dependencies, but narrow to affected targtes with cpp/util in their path)
. <(bant dwyu ... -g cpp/util)

 # Now, we can remove the dependency on the old util library.
buildozer 'remove deps //src/main/cpp/util' $(bant list-targets ... -g cc_ -c3)

 # Now that it is not referenced anymore, it can be removed.
buildozer delete //src/main/cpp/util
```
@hzeller
hzeller force-pushed the feature-20260831-utl branch from 425925e to cdf73e4 Compare September 1, 2026 15:33
@hzeller

hzeller commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

what is the status here, anything else needed ?

@meteorcloudy meteorcloudy added the copybara:import Trigger copybara to import the PR label Sep 1, 2026
@hzeller

hzeller commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

mmh, so what is the copybara situation ? Can't see it ...

@copybara-service copybara-service Bot closed this in 75af886 Sep 2, 2026
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copybara:import Trigger copybara to import the PR team-Rules-CPP Issues for C++ rules team-Rules-Java Issues for Java rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants