Skip to content

[bazel] Run buildifier on Bazel build files#2904

Open
adhoc-bobcat wants to merge 4 commits intoraspberrypi:developfrom
adhoc-bobcat:buildifier
Open

[bazel] Run buildifier on Bazel build files#2904
adhoc-bobcat wants to merge 4 commits intoraspberrypi:developfrom
adhoc-bobcat:buildifier

Conversation

@adhoc-bobcat
Copy link
Copy Markdown

This is an automated change made with the following command:

$ buildifier --mode=fix --lint=fix **/BUILD.bazel \
      src/rp2_common/pico_lwip/lwip.BUILD \
      src/rp2_common/pico_mbedtls/mbedtls.BUILD \
      src/rp2_common/tinyusb/tinyusb.BUILD \
      src/rp2_common/pico_cyw43_driver/cyw43-driver.BUILD \
      src/rp2_common/pico_btstack/btstack.BUILD

The primary purpose was to get back Bazel 9 compatibility lost since the last time this was done, as doing this automatically adds the necessary rules_cc loads for its rules (cc_library, ...)

It also normalizes the formatting, in particular

  • Loads go at the top
  • Rule attributes are sorted
  • Deps lists are sorted
  • Trailing commas are added on multiline lists
  • Standardizes whitespace between declarations, and at the end of file

Verified by running:

$ bazelisk build //...  # Uses .bazelversion (8.1.0)
$ USE_BAZEL_VERSION=9.1.0.rc3 bazelisk build //...

@adhoc-bobcat
Copy link
Copy Markdown
Author

I reproduced the "bazel-build-check (ubuntu-latest)" failure, and confirmed it was my patch. I'll mark this as a draft PR until I figure what I did wrong (I'm guessing the full set of fixes was the wrong thing to do, and perhaps deps should NOT have been sorted).

@adhoc-bobcat adhoc-bobcat marked this pull request as draft April 16, 2026 08:52
This is an automated change made with the following command:

$ buildifier --mode=fix --lint=fix **/BUILD.bazel \
      src/rp2_common/pico_lwip/lwip.BUILD \
      src/rp2_common/pico_mbedtls/mbedtls.BUILD \
      src/rp2_common/tinyusb/tinyusb.BUILD \
      src/rp2_common/pico_cyw43_driver/cyw43-driver.BUILD \
      src/rp2_common/pico_btstack/btstack.BUILD

But with additional fixups.

- The ordering of certain linker script deps matters. For those places a
  quick command and a "buildifier: leave-alone" comment were added to
  prevent automatic reordering when this tool is next used to clean up
  the Bazel build files.

The primary purpose was to get back Bazel 9 compatibility lost since the
last time this was done, as doing this automatically adds the necessary
rules_cc loads for its rules (cc_library, ...)

It also normalizes the formatting, in particular

- Loads go at the top
- Rule attributes are sorted
- Deps lists are sorted
- Trailing commas are added on multiline lists
- Standardizes whitespace between declarations, and at the end of file

Verified by running:

$ bazelisk build //...  # Uses .bazelversion (8.1.0)
$ USE_BAZEL_VERSION=9.1.0.rc3 bazelisk build //...
@will-v-pi
Copy link
Copy Markdown
Contributor

I reproduced the "bazel-build-check (ubuntu-latest)" failure, and confirmed it was my patch. I'll mark this as a draft PR until I figure what I did wrong (I'm guessing the full set of fixes was the wrong thing to do, and perhaps deps should NOT have been sorted).

Yes, the dependency ordering for the linker scripts is important, as earlier dependencies override files in later ones.

If there's a way to run buildifier without doing the re-ordering of those dependencies, it might be nice to add that to the other Bazel CI checks (throwing an error and printing out the diff if there are any changes needed, for the PR author to copy into their PR) - that would ensure Bazel 9 compatibility doesn't get lost again

@adhoc-bobcat
Copy link
Copy Markdown
Author

I reproduced the "bazel-build-check (ubuntu-latest)" failure, and confirmed it was my patch. I'll mark this as a draft PR until I figure what I did wrong (I'm guessing the full set of fixes was the wrong thing to do, and perhaps deps should NOT have been sorted).

Yes, the dependency ordering for the linker scripts is important, as earlier dependencies override files in later ones.

If there's a way to run buildifier without doing the re-ordering of those dependencies, it might be nice to add that to the other Bazel CI checks (throwing an error and printing out the diff if there are any changes needed, for the PR author to copy into their PR) - that would ensure Bazel 9 compatibility doesn't get lost again

Hi Will!

There are "buildifier: leave-alone" and even a check for "do not sort" comments that can be added, which may not be quite what you want. I added them in a test branch (to not add noise to this PR) about an hour ago after tracking down the deps where the order mattered, and reverting that part of the CL:

I was about to update this PR with that commit. And while I didn't think about adding a buildifier check to the presubmit tests, I was going to look into adding a Bazel 9 check build, but I can look into that too.

@adhoc-bobcat adhoc-bobcat marked this pull request as ready for review April 16, 2026 18:23
@armandomontanez
Copy link
Copy Markdown
Contributor

@adhoc-bobcat
Copy link
Copy Markdown
Author

I have what should be a Bazel 9 check (and a Bazel latest advisory check) as a local commit, but I'll need to upload it to my fork to see if it works as intended.

I also have a working buildifier check which does run locally, and which runs on more files than I initially cleaned up (WORKSPACE, *.bzl, REPO.bazel). I'm now working on getting those to be lint-clean, which requires some manual intervention to satisfy checks about missing docstrings et al.

After that, I'll do some testing on my fork that they catch regressions, but I think that won't take long. I think I'll have it working over the next few hours, but I've got some other things on my calendar today.

I was planning on adding them to this PR, since it makes sense for them to all go in together, but if needed I'm happy to set up a new PR.

@adhoc-bobcat
Copy link
Copy Markdown
Author

I pulled out the latest Bazel ("last_rc") advisory check. It only checks a floating "9.x" version (latest released Bazel 9), which might be somewhat problematic on its own if a new version is released that requires changes. A "last_rc" check might be equally problematic, and if there is no release candidate, it duplicates the "9.x" run.

Otherwise it looks like the Bazel 9 check and the buildifier check both work as intended.

@adhoc-bobcat
Copy link
Copy Markdown
Author

Maybe it works too well. It flagged one picotool file because it found it, though that isn't really part of the code here. I'll create a PR there.

pico-sdk/lib/picotool/bazel/defs.bzl:1: module-docstring: The file has no module docstring.

The checks is added as part of the "other" checks that are already run.
Running a build with the latest release of Bazel 9 will ensure it works,
even as the main builds support only Bazel 8.

Bazel 9 removes some built-ins (like cc_library), that now require using
the appropriate replacement Bazel Module (like rules_cc).
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.

3 participants