Repository navigation
Walk directories using gazelle helper - #171
Merged
Merged
Conversation
In module mode, `buf_breaking_test` generated at the module root listed every .proto file, including ones skipped by Gazelle (in `.bazelignore`, `.git`, etc.). Switch the walk to use Gazelle's `walk.GetDirInfo` to match what Gazelle visits. This requires gazelle >= 0.45. Update the `WORKSPACE` example to 0.54.0 and newer rules_go. Fixes #133.
emcfarlane
approved these changes
Nov 5, 2026
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Nov 18, 2026
Upgrades `rules_buf` from 0.5.2 to [0.6.1](https://github.com/bufbuild/rules_buf/releases/tag/v0.6.1), its latest release. 0.6.0 never reached the BCR, and 0.6.1 adds only a test fix on top of it. This PR was stacked on dfinity#12149, which has landed. dfinity#12149 upgraded gazelle from 0.51.3 to 0.54.0, which rules_buf 0.6.1 requires ([bufbuild/rules_buf#170](bufbuild/rules_buf#170)), and moved the gazelle targets out of the root package, so that loading it doesn't fetch the Go SDK. This PR now targets master, with master merged in (no conflicts). We use rules_buf directly only for the buf CLI it downloads. The `buf` extension at the top of `MODULE.bazel` creates `@rules_buf_toolchains`, and `//pre-commit:buf-check`, `//pre-commit:buf-breaking-check` and `//pre-commit:buf-fix` (aliased as `//:protobuf-format`) run its `:buf` binary. Nothing in the repo loads rules_buf's `buf_lint_test`, `buf_breaking_test` or `buf_format` rules, and nothing uses its Gazelle extension. Indirectly, rules_buf's `go.mod` also takes part in gazelle's `go_deps` version selection. So this PR also changes some of the Go modules that the `//:gazelle` binary is built from (see "Upstream changes that touch our setup"). Neither rules_buf nor gazelle is in the build graph of the release artifacts. ## Changes - **`MODULE.bazel`**: `rules_buf` 0.5.2 → 0.6.1. On top of dfinity#12149, this PR also changes the `//:gazelle` binary: it links a newer buildtools (see below). The gazelle checks under Verification ran with this PR's binary. - **`go.mod`, `go.sum`**: `github.com/stretchr/testify` v1.8.4 → v1.12.1, and with it the indirect `github.com/stretchr/objx` v0.5.0 → v0.5.3. rules_buf 0.6.1's own `go.mod` requires testify v1.12.1. Gazelle's `go_deps` extension merges the `go.mod` files of all Bazel modules, so it resolves testify to v1.12.1 for us too. We run with `--lockfile_mode=off`, so every new Bazel server printed: ``` The following Go modules were required by the root module at the given versions, but were implicitly updated to higher versions due to transitive dependencies: github.com/stretchr/testify: v1.8.4 -> v1.12.1 ``` I ran the command that the warning suggests: `bazel run @rules_go//go -- get github.com/stretchr/[email protected]`. The repo has no Go code, so nothing uses testify and this change only removes the warning. The new testify lines in `go.sum` match rules_buf 0.6.1's `go.sum`. The `@rules_go//go` wrapper also runs `bazel mod tidy`, which rewrites the `rules_qemu` `use_repo` that already warns on master. I reverted that change because it's unrelated. ## Upstream changes that touch our setup - **The buf CLI moves from v1.47.2 to v1.75.0** ([bufbuild/rules_buf#166](bufbuild/rules_buf#166)). We don't pin a version with `buf.toolchains(version = ...)`, so the pre-commit checks now run buf v1.75.0. Some changes in buf's [changelog](https://github.com/bufbuild/buf/blob/v1.75.0/CHANGELOG.md) could change our results: a new compiler for `buf build` (v1.68.0), a new formatter (v1.71.0) and further `buf format` fixes (v1.59.0, v1.73.0). On our protos the results don't change (see Verification). buf v1.75.0 still accepts our `version: v1beta1` `buf.yaml` without warnings and sees the same 64 files. It also configures the same breaking rules. The configured lint rules differ only by `IMPORT_NO_WEAK`. buf deprecated that rule and made it a no-op when protobuf-go dropped weak imports ([bufbuild/buf#3653](bufbuild/buf#3653)), and none of our protos uses `import weak`. - **rules_buf's `go.mod` also changes Go modules in the `//:gazelle` binary** ([bufbuild/rules_buf#170](bufbuild/rules_buf#170)). rules_buf calls `go_deps.from_file(go_mod = "//:go.mod")` as a regular dependency, not a dev dependency. For Go modules that aren't also Bazel modules, `go_deps` picks the highest version that any Bazel module's `go.mod` requires. Compared with the gazelle bump alone (dfinity#12149, which resolves the same Go module versions as master), this PR changes: - `github.com/bazelbuild/buildtools` v0.0.0-20250930140053-2eb4fccefb52 (gazelle's own pin) → v0.0.0-20260904073137-eaa4d125b423 (rules_buf's pin). - `github.com/stretchr/testify` v1.8.4 → v1.12.1 and `github.com/stretchr/objx` v0.5.0 → v0.5.3 (see `go.mod` above). - New: `go.yaml.in/yaml/v3` v3.0.5, which testify v1.12.1 requires, and `github.com/google/safeopen` v0.0.0-20260327150837-43626d6f4685, which the new buildtools requires. `//:gazelle` runs `@gazelle//cmd/gazelle`, and `//pre-commit:gazelle-check` is an alias for it. That binary links buildtools' `build`, `labels` and `tables` packages. Gazelle runs every existing BUILD file it visits through `build.Format`, rewrites included, and writes the file back if the output differs. So this PR changes the tool behind the Linter's `gazelle-check` and the Autofix job's `bazel run :gazelle`. Apart from code comments, the [53 buildtools commits](bazel-contrib/buildtools@2eb4fcc...eaa4d12) change those packages as follows; `labels` doesn't change: - Add Starlark type-annotation syntax ([bazel-contrib/buildtools#1403](bazel-contrib/buildtools#1403), [bazel-contrib/buildtools#1488](bazel-contrib/buildtools#1488), [bazel-contrib/buildtools#1509](bazel-contrib/buildtools#1509)). - Make formatting idempotent for compact block statements followed by comments ([bazel-contrib/buildtools#1481](bazel-contrib/buildtools#1481)). - Sort `visibility()` arguments in `.bzl` files ([bazel-contrib/buildtools#1452](bazel-contrib/buildtools#1452)) and classify more file names, including the new REPO.bazel and VENDOR.bazel types ([bazel-contrib/buildtools#1433](bazel-contrib/buildtools#1433), [bazel-contrib/buildtools#1485](bazel-contrib/buildtools#1485)). Neither matters for `//:gazelle`, which parses BUILD files with `ParseBuild` and formats only BUILD files. - Add a helper for buildozer's `comment` command ([bazel-contrib/buildtools#1434](bazel-contrib/buildtools#1434)), a lint table ([bazel-contrib/buildtools#1318](bazel-contrib/buildtools#1318)) and parser/printer speedups ([bazel-contrib/buildtools#1473](bazel-contrib/buildtools#1473), [bazel-contrib/buildtools#1474](bazel-contrib/buildtools#1474), [bazel-contrib/buildtools#1475](bazel-contrib/buildtools#1475)). With this PR's binary, `bazel run //:gazelle` visits all 637 BUILD files and changes none of them, both locally and in this PR's Autofix job. `buildifier-check` and `buildifier-fix` run the prebuilt buildifier from `buildifier_prebuilt`, which this PR doesn't change. Nothing we build uses the two new repositories, and Bazel fetches a repository only when a build needs it. rules_buf's `MODULE.bazel` notes that safeopen's BUILD files reference repositories that `go_deps` doesn't create. Its fix, a `gazelle_override`, is declared with `dev_dependency = True`, so it doesn't apply here. That would only matter if something here built safeopen. - **New minimum versions**: - 0.5.4: rules_go 0.42.0 → 0.59.0 (we're on 0.62.0) and gazelle 0.34.0 → 0.40.0 ([bufbuild/rules_buf#134](bufbuild/rules_buf#134)). - 0.6.0: gazelle 0.54.0 (dfinity#12149), platforms 1.1.0 and rules_proto 7.1.0 (our graph already resolves both). Across the whole Bazel module graph, only `rules_buf` changes version compared with master. - **0.5.4's other changes**: 0.5.4 is a re-release of 0.5.3, which never reached the BCR. [bufbuild/rules_buf#127](bufbuild/rules_buf#127) adds `gazelle:resolve` support to the Gazelle extension, which we don't use. [bufbuild/rules_buf#129](bufbuild/rules_buf#129) makes the toolchain repository rule return `repo_metadata(reproducible = True)` when it has a sha256. We don't set `buf.toolchains(...)`, so the extension passes the sha256 of the default buf release. `@rules_buf_toolchains` is therefore now marked reproducible, and Bazel can keep it in its repository contents cache. That doesn't change which buf binary it provides. - **Changes we don't use**: `buf_lint_test` and `buf_breaking_test` now load `ProtoInfo` and the proto toolchain from protobuf instead of rules_proto ([bufbuild/rules_buf#167](bufbuild/rules_buf#167)). The Gazelle extension also changed ([bufbuild/rules_buf#148](bufbuild/rules_buf#148), [bufbuild/rules_buf#171](bufbuild/rules_buf#171)). ## Verification In the dev container: - **Module graph**: `bazel mod graph` resolves `[email protected]` and `[email protected]`, and no other Bazel module version changes from the base commit. Before the `go.mod` change, the `go_deps` warning above was the only new warning. Now only the existing `rules_qemu` `use_repo` warning remains. - **`go_deps` module set**: I ran `bazel mod show_extension @gazelle//:extensions.bzl%go_deps`, and `bazel mod show_repo` on each repository it lists, in three states: the base commit, the base commit plus only the gazelle bump (dfinity#12149's change), and this PR. - The base commit and the gazelle bump resolve the same Go module versions. - This PR changes exactly the five Go modules listed above. - `bazel query 'somepath(//:gazelle, @@gazelle++go_deps+com_github_bazelbuild_buildtools//build)'` goes through `@gazelle//cmd/gazelle`. - `deps(//:gazelle + //:gazelle-update-repos)` contains no target from safeopen or `go.yaml.in/yaml/v3`. No Bazel file in the repo references a `go_deps` repository directly. - `deps(//pre-commit:buildifier-check + //pre-commit:buildifier-fix)` contains no `go_deps` target. - **Analysis**: `bazel build //... --nobuild` analyzes all 3387 targets. After stacking this branch on dfinity#12149 (a merge, no other change), `//:gazelle` and `//bazel/gazelle:all` build and `bazel build //... --nobuild` analyzes all 3389 targets (dfinity#12149 adds two root aliases). After merging master, `bazel build //... --nobuild` again analyzes all 3389 targets, and `bazel run //:buildifier` changes nothing. - **CI Linter checks**: - `shfmt-check`, `ruff-check`, `buf-check`, `DFINITY-capitalization-check`, `do-not-merge-check`, `buildifier-check`, `gazelle-check` and `buf-breaking-check` all pass. - The autofixes (`buildifier-fix`, `shfmt-fix`, `ruff-fix`, `//:gazelle`) and `bazel run //:protobuf-format` leave the tree unchanged. - A second, separate run of `bazel run //pre-commit:gazelle-check` and `bazel run //:gazelle` with this PR's gazelle binary: both exit 0 and `git status` stays clean. - `//:gazelle` and `//:gazelle-update-repos` build with gazelle 0.54.0. I didn't run `//:gazelle-update-repos`. - **buf v1.47.2 vs v1.75.0**: I ran the commands of `buf-check` (`buf format --exit-code --diff .` and `buf lint .`) and of `buf-breaking-check` (`buf build`, `buf build ".git#ref=HEAD"` and `buf breaking`) with both versions. I ran them on the unmodified tree and on three deliberately broken variants of `rs/protobuf/def/determinism_test/v1/determinism_test.proto`. Both versions gave identical results: - Unmodified tree: all checks pass. - Extra spaces in a field declaration: `buf format` fails with the same diff. - An added `message bad_message_name {}`: `buf lint` reports the same PascalCase violation. - `float v_float = 1;` changed to `string v_float = 1;`: `buf breaking` reports the same `changed type from "float" to "string"`. `bazel run //pre-commit:buf-check` and `bazel run //pre-commit:buf-breaking-check` also fail on these variants. - **Release artifacts**: I ran `bazel cquery 'deps(...)'` over the IC-OS bundles that `ci/container/build-ic.sh --icos` builds plus `//publish/binaries:bundle` and `//publish/canisters:bundle`. The result has no target from rules_buf, `@rules_buf_toolchains`, gazelle, its `go_deps` repositories or rules_go, so I didn't run a byte-identity comparison. - **Tests**: no tests in the repo use rules_buf or gazelle. CI covers the full build and test suite. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In module mode,
buf_breaking_testgenerated at the module root listed every .proto file, including ones skipped by Gazelle (in.bazelignore,.git, etc.).Switch the walk to use Gazelle's
walk.GetDirInfoto match what Gazelle visits. This requires gazelle >= 0.45. Update theWORKSPACEexample to 0.54.0 and newer rules_go.Fixes #133.