Skip to content

buildifier: decouple runner scripts from binaries#1398

Merged
AnnaSvalova merged 1 commit intobazelbuild:mainfrom
rdesgroppes:export-buildifier-scripts-without-build-deps
Nov 10, 2025
Merged

buildifier: decouple runner scripts from binaries#1398
AnnaSvalova merged 1 commit intobazelbuild:mainfrom
rdesgroppes:export-buildifier-scripts-without-build-deps

Conversation

@rdesgroppes
Copy link
Contributor

@rdesgroppes rdesgroppes commented Sep 30, 2025

This change aims at making buildtools/buildifier more modular and easier to consume by enabling use of prebuilt binaries without having to pull in unnecessary dependencies - while strengthening upstream as the authoritative home for runner script templates.

Today, buildifier/BUILD.bazel exposes two different sets of rules:

  • exports for runner script templates (runner.bash.template, runner.bat.template) as well as README.md,
  • go build & sh test rules which require external repos (rules_go, rules_shell) even for consumers who don't need to build the buildifier binary.

It is worth noticing there are two distinct community efforts on runner scripts, the present/upstream bazelbuild/buildtools and the derived keith/buildifier-prebuilt (Bazel Central Registry module). These drift apart over time, leading to unsynchronized contents (factory.bzl, runner.bash.template) and efforts, e.g. on Windows support:

Intended benefits of this change:

  • decoupling: by moving go_binary and sh_test targets into buildifier/cmd, the top-level buildifier/BUILD.bazel no longer requires rules_go nor rules_shell,
  • flexibility: users can either build binaries from source (via //buildifier/cmd) or configure rules to use prebuilt binaries (e.g. via rules_multitool) while still consuming the same upstream runner script templates,
  • backward compatibility: aliases keep earlier //buildifier:buildifier* labels working by delegating to the corresponding //buildifier/cmd:buildifier*.

@rdesgroppes rdesgroppes force-pushed the export-buildifier-scripts-without-build-deps branch from 7028e17 to f376c5b Compare September 30, 2025 10:14
@rdesgroppes rdesgroppes marked this pull request as draft September 30, 2025 10:15
@rdesgroppes rdesgroppes force-pushed the export-buildifier-scripts-without-build-deps branch from f376c5b to 8914e45 Compare September 30, 2025 10:30
@rdesgroppes rdesgroppes marked this pull request as ready for review September 30, 2025 10:37
@rdesgroppes rdesgroppes force-pushed the export-buildifier-scripts-without-build-deps branch from 8914e45 to e72e822 Compare October 7, 2025 14:52
@rdesgroppes rdesgroppes force-pushed the export-buildifier-scripts-without-build-deps branch from e72e822 to ab54e73 Compare November 6, 2025 14:26
Copy link
Collaborator

@AnnaSvalova AnnaSvalova left a comment

Choose a reason for hiding this comment

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

I'm not against this change, but cmd sounds a bit unusual for build tools and bazel 🤔 Maybe cli or similar?

@rdesgroppes
Copy link
Contributor Author

I'm not against this change, but cmd sounds a bit unusual for build tools and bazel 🤔 Maybe cli or similar?

@AnnaSvalova, I'll of course follow your call here, but I was wondering whether the Go convention should be favored in this case? The cmd directory seems to be the standard location for CLI applications there: https://github.com/golang-standards/project-layout?tab=readme-ov-file#cmd

I thought it might be helpful to stick with it for familiarity. But happy to change it to cli if you prefer:

  • rename to cli
  • stick to cmd

This change aims at making `buildtools/buildifier` more modular and
easier to consume by enabling use of prebuilt binaries without pulling
in unnecessary dependencies - while strengthening upstream as the
authoritative home for runner script templates.

Today, `buildifier/BUILD.bazel` exposes two different sets of rules:
- exports for runner script templates (`runner.bash.template`,
  `runner.bat.template`) as well as `README.md`,
- `go` build & `sh` test rules which require external repos (`rules_go`,
  `rules_shell`) even for consumers who don't need to build the
  `buildifier` binary.

It is worth noticing there are two distinct community efforts on runner
scripts, the present/upstream `bazelbuild/buildtools` and the derived
`keith/buildifier-prebuilt` (Bazel Central Registry module).
These drift apart over time, leading to unsynchronized contents
(`factory.bzl`, `runner.bash.template`) and efforts, e.g. on Windows
support:
- bazelbuild#1230
- keith/buildifier-prebuilt#89 (open for a year)

Intended benefits of this change:
- decoupling: by moving `go_binary` and `sh_test` targets into
  `buildifier/cmd`, the top-level `buildifier/BUILD.bazel` no longer
  requires `rules_go` nor `rules_shell`,
- flexibility: users can either build binaries from source (via
  `//buildifier/cmd`) or configure rules to use prebuilt binaries (e.g.
  via `multitool`) while still consuming the same upstream runner script
  templates,
- backward compatibility: aliases keep `//buildifier:buildifier*`
  working by delegating to `//buildifier/cmd:buildifier*`.
@rdesgroppes rdesgroppes force-pushed the export-buildifier-scripts-without-build-deps branch from ab54e73 to 49852da Compare November 7, 2025 14:25
@AnnaSvalova
Copy link
Collaborator

I'm not against this change, but cmd sounds a bit unusual for build tools and bazel 🤔 Maybe cli or similar?

@AnnaSvalova, I'll of course follow your call here, but I was wondering whether the Go convention should be favored in this case? The cmd directory seems to be the standard location for CLI applications there: https://github.com/golang-standards/project-layout?tab=readme-ov-file#cmd

I thought it might be helpful to stick with it for familiarity. But happy to change it to cli if you prefer:

  • rename to cli
  • stick to cmd

Fair point. Also, I'd say that an even more common pattern is using a project name instead of "cli" or "cmd".

In any case it was a nit, LGTM.

@AnnaSvalova AnnaSvalova merged commit 9a9819e into bazelbuild:main Nov 10, 2025
2 checks passed
@gunsch
Copy link

gunsch commented Nov 10, 2025

Drive-by FYI --- I think this broke the go install command listed in the docs.

i.e. as documented here:

go install github.com/bazelbuild/buildtools/buildifier@latest

Difference between your commit and the one prior:

$ go install github.com/bazelbuild/buildtools/buildifier@e879524f2986d9b75488855aa938013db2cda4ea
go: downloading github.com/bazelbuild/buildtools v0.0.0-20251107112229-e879524f2986

$ go install github.com/bazelbuild/buildtools/buildifier@9a9819efe30f
go: github.com/bazelbuild/buildtools/buildifier@9a9819efe30f: module github.com/bazelbuild/buildtools@9a9819efe30f found (v0.0.0-20251110131859-9a9819efe30f), but does not contain package github.com/bazelbuild/buildtools/buildifier

Edit: looks like this works now instead:

$ go install github.com/bazelbuild/buildtools/buildifier/cmd@9a9819efe30f

@DavyWk
Copy link

DavyWk commented Nov 10, 2025

Emphasizing @gunsch's comment above- we use the documented go install github.com/bazelbuild/buildtools/buildifier@latest and several of our builds broke.

@rdesgroppes
Copy link
Contributor Author

rdesgroppes commented Nov 10, 2025

@rdesgroppes rdesgroppes deleted the export-buildifier-scripts-without-build-deps branch November 10, 2025 15:42
AnnaSvalova pushed a commit that referenced this pull request Nov 12, 2025
@thejcannon
Copy link

You can't win 'em all. We got broken too, so I fixed it to use the new location. Guess who just got broken again 😅 ?

If anything this is a reminder using @latest is a footgun, and I, now with two holes in my feet, have run out of feet.

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.

5 participants