Skip to content

feat(prebuilt): do not depend on the gazelle bazel module#248

Draft
jbedard wants to merge 1 commit intomainfrom
prebuilt-no-gazelle
Draft

feat(prebuilt): do not depend on the gazelle bazel module#248
jbedard wants to merge 1 commit intomainfrom
prebuilt-no-gazelle

Conversation

@jbedard
Copy link
Copy Markdown
Member

@jbedard jbedard commented Apr 14, 2026

To avoid pulling in gazelle+rules_go and many other repos when 99% of scenarios don't need them when running a prebuilt.

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

The aspect_gazelle_prebuilt module no longer carries any dependencies on gazelle or rules_go and is fully self-contained.

Test plan

  • Manual testing; please provide instructions so we can reproduce:

Copilot AI review requested due to automatic review settings April 14, 2026 20:40

This comment was marked as outdated.

@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 9257fbd to ad26786 Compare April 16, 2026 19:45
@aspect-workflows
Copy link
Copy Markdown

aspect-workflows bot commented Apr 16, 2026

Test

All tests were cache hits

6 tests (100.0%) were fully cached saving 1s.


Test

language/js

All tests were cache hits

128 tests (100.0%) were fully cached saving 26s.


Test

language/kotlin

All tests were cache hits

19 tests (100.0%) were fully cached saving 5s.


Test

language/orion

All tests were cache hits

55 tests (100.0%) were fully cached saving 8s.


Test

runner

All tests were cache hits

33 tests (100.0%) were fully cached saving 7s.


Test

runner/e2e/bin

All tests were cache hits

1 test (100.0%) was fully cached saving 61ms.


Buildifier      Gazelle      Gazelle [language/js]      Gazelle [language/kotlin]      Gazelle [language/orion]      Gazelle [runner]      Gazelle [runner/e2e/bin]

Copilot AI review requested due to automatic review settings April 16, 2026 19:57
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from ad26786 to 5e54328 Compare April 16, 2026 19:57
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 5e54328 to 997acd6 Compare April 16, 2026 20:01

This comment was marked as outdated.

@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 997acd6 to 161d75a Compare April 18, 2026 03:14
Copilot AI review requested due to automatic review settings April 18, 2026 03:52
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 161d75a to a9876b6 Compare April 18, 2026 03:52

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from a9876b6 to 318a51e Compare April 18, 2026 04:45
Copilot AI review requested due to automatic review settings April 18, 2026 09:01
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 318a51e to 1fcb047 Compare April 18, 2026 09:01

This comment was marked as resolved.

@jbedard jbedard force-pushed the prebuilt-no-gazelle branch 2 times, most recently from e80d11b to f0b13ec Compare April 19, 2026 06:06
Copilot AI review requested due to automatic review settings April 19, 2026 06:06
@jbedard jbedard changed the title feat: do not depend on the gazelle bazel module feat(prebuilt): do not depend on the gazelle bazel module Apr 19, 2026

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the prebuilt distribution so it no longer pulls in the gazelle Bazel module (and its transitive deps like rules_go) for typical consumers, while keeping a compatible API surface between the runner and prebuilt variants.

Changes:

  • Introduces a runner/rules.bzl wrapper macro (aspect_gazelle_runner) around upstream @gazelle//:def.bzl to keep the public attribute shape aligned with prebuilt.
  • Replaces the prebuilt gazelle_runner symlink rule with a standalone aspect_gazelle_runner rule that generates a bash wrapper script (avoiding a non-dev gazelle dependency).
  • Updates module deps/docs to reflect the new prebuilt behavior (adds bazel_skylib, makes gazelle dev-only, adjusts README + BUILD wiring).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
runner/rules.bzl New thin wrapper macro around upstream gazelle() to align API with prebuilt.
runner/def.bzl Switches aspect_gazelle to call aspect_gazelle_runner and adds repo_config plumbing.
runner/BUILD.bazel Adds bzl_library(name="rules") and rewires def to depend on it.
prebuilt/rules.bzl Replaces symlink runner with a self-contained bash-wrapper rule (no runtime @gazelle dep).
prebuilt/README.md Updates “How it works” description to match the new wrapper rule.
prebuilt/MODULE.bazel Removes non-dev gazelle/rules_go, adds bazel_skylib, keeps gazelle as dev-only.
prebuilt/BUILD.bazel Renames the published prebuilt target to use aspect_gazelle_runner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runner/rules.bzl
Comment on lines +11 to +13
Known divergence from the prebuilt rule: upstream `gazelle()` does not
expand $(location)/$(rootpath) tokens in `env` values, while the prebuilt
rule does. Avoid location tokens in `env` for portable behaviour.
Comment thread prebuilt/rules.bzl
Comment thread prebuilt/rules.bzl Outdated
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from cdec42d to cae50b5 Compare April 19, 2026 07:36
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cdec42d32e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread prebuilt/BUILD.bazel
Comment on lines +3 to 4
aspect_gazelle_runner(
name = "gazelle_prebuilt_bin",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep gazelle_prebuilt_bin a pass-through executable

Switching :gazelle_prebuilt_bin to aspect_gazelle_runner changes this public target from a raw binary symlink into a wrapper that always prepends its own command flags. That breaks compatibility for existing usages that treat it as the gazelle binary (for example gazelle(gazelle = "@aspect_gazelle_prebuilt//:gazelle_prebuilt_bin")), because invocations now become effectively update ... <caller args>, so caller-supplied commands like fix are parsed as positional args instead of the command. Preserving a pass-through binary target (and using a separate wrapper target for macro defaults) avoids this regression.

Useful? React with 👍 / 👎.

Comment thread runner/def.bzl
Comment on lines +107 to 109
aspect_gazelle_runner(
name = name,
mode = "fix",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore manual tag on generated aspect_gazelle targets

This call site now routes through aspect_gazelle_runner instead of upstream gazelle(), and prebuilt releases generated from runner/def.bzl therefore lose gazelle()'s automatic manual tagging. As a result, consumer wildcard builds like bazel build //... can unexpectedly include //:gazelle and //:gazelle.check, pulling the prebuilt tool into normal builds. Add manual explicitly to the macro's tags (or reintroduce a macro layer that appends it) to keep previous behavior.

Useful? React with 👍 / 👎.

Copilot AI review requested due to automatic review settings April 19, 2026 07:42
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from cae50b5 to b131cdf Compare April 19, 2026 07:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes aspect_gazelle_prebuilt self-contained by removing runtime bzlmod dependencies on @gazelle/rules_go and replacing upstream Gazelle rule usage with an in-repo aspect_gazelle_runner implementation that resolves the prebuilt binary via toolchains.

Changes:

  • Added runner/rules.bzl as a thin wrapper around upstream @gazelle//:def.bzl to keep the runner module’s API aligned with prebuilt.
  • Reimplemented aspect_gazelle_runner in prebuilt/rules.bzl to generate an executable wrapper script (toolchain-resolved binary + runfiles), eliminating runtime @gazelle usage.
  • Updated module metadata and docs so prebuilt only keeps gazelle as a dev_dependency and documents the new execution flow.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
runner/rules.bzl New wrapper macro around upstream gazelle() to provide the aspect_gazelle_runner entrypoint in the runner module.
runner/def.bzl Switches aspect_gazelle() to call aspect_gazelle_runner and adds repo_config plumbing.
runner/BUILD.bazel Adds bzl_library(name="rules") and rewires def to depend on it.
prebuilt/rules.bzl Implements a self-contained executable rule that generates a runfiles-aware bash launcher for the toolchain-resolved binary.
prebuilt/README.md Updates documentation to reflect the new wrapper-script execution model.
prebuilt/MODULE.bazel Drops runtime gazelle/rules_go deps; adds bazel_skylib; keeps gazelle as dev_dependency.
prebuilt/BUILD.bazel Updates to use the renamed aspect_gazelle_runner rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runner/def.bzl
Comment thread runner/rules.bzl
Comment on lines +23 to +66
def aspect_gazelle_runner(
name,
command = "update",
mode = "",
extra_args = [],
data = [],
env = {},
repo_config = None,
**kwargs):
"""Runs the aspect gazelle binary via the upstream gazelle() macro.

Args:
name: Target name.
command: Gazelle subcommand. One of "update", "fix".
mode: Gazelle mode. One of "", "fix", "diff" (empty means gazelle's default).
extra_args: Extra arguments forwarded to the gazelle binary.
data: Additional runtime files needed by the invocation (e.g. referenced
by $(location) tokens in `extra_args`).
env: Environment variables set before invoking gazelle.
repo_config: Optional repo config file for modules using a custom
repo_name in MODULE.bazel. Typically
@bazel_gazelle_go_repository_config//:WORKSPACE when gazelle is a dep.
**kwargs: Standard Bazel rule attributes (e.g. `tags`, `visibility`,
`testonly`) forwarded to the underlying target.
"""
if command not in _VALID_COMMANDS:
fail("Invalid 'command' %r. Must be one of: %s" % (command, ", ".join(_VALID_COMMANDS)))
if mode not in _VALID_MODES:
fail("Invalid 'mode' %r. Must be one of: %s" % (mode, ", ".join(_VALID_MODES)))

if repo_config:
extra_args = ["-repo_config=$(location %s)" % repo_config] + extra_args
data = [repo_config] + data

gazelle(
name = name,
gazelle = _GAZELLE_BINARY,
command = command,
mode = mode,
extra_args = extra_args,
data = data,
env = env,
**kwargs
)
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from b131cdf to 59632f1 Compare April 19, 2026 07:50
Copilot AI review requested due to automatic review settings April 19, 2026 08:00
@jbedard jbedard force-pushed the prebuilt-no-gazelle branch from 59632f1 to 2514c3f Compare April 19, 2026 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the aspect_gazelle_prebuilt module self-contained at runtime by removing non-dev dependencies on gazelle/rules_go, while preserving a compatible caller-facing API by introducing a small wrapper in the runner module.

Changes:

  • Replaces the prebuilt module’s dependency on upstream @gazelle with a self-contained aspect_gazelle_runner rule that generates a runfiles-aware bash wrapper.
  • Introduces runner/rules.bzl to wrap the upstream gazelle() macro behind an API-restricted surface aligned with the prebuilt rule.
  • Updates module/BUILD wiring and docs to reflect the new runner/prebuilt structure and dependency split (runtime vs dev-only).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
runner/rules.bzl Adds a wrapper macro around upstream gazelle() to align with prebuilt rule shape.
runner/def.bzl Switches aspect_gazelle to call the new wrapper and plumbs through repo_config.
runner/BUILD.bazel Adds a bzl_library for the new rules wrapper and updates deps accordingly.
prebuilt/rules.bzl Reimplements gazelle()-like execution without depending on @gazelle (toolchain-resolved binary + wrapper script).
prebuilt/README.md Updates “How it works” to describe the wrapper-rule-based execution model.
prebuilt/MODULE.bazel Drops runtime deps on gazelle/rules_go, adds bazel_skylib, keeps gazelle as dev-only.
prebuilt/BUILD.bazel Renames the exported executable rule to aspect_gazelle_runner and instantiates it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread prebuilt/rules.bzl
Comment on lines +107 to +111
transitive_runfiles = [d[DefaultInfo].default_runfiles for d in ctx.attr.data]
transitive_runfiles.append(ctx.attr._runfiles_lib[DefaultInfo].default_runfiles)
if ctx.file.repo_config:
runfile_files.append(ctx.file.repo_config)
transitive_runfiles.append(ctx.attr.repo_config[DefaultInfo].default_runfiles)
Comment thread runner/rules.bzl
Comment on lines +23 to +68
def aspect_gazelle_runner(
name,
command = "update",
mode = "",
extra_args = [],
data = [],
env = {},
repo_config = None,
**kwargs):
"""Internal wrapper around the upstream bazel-contrib/bazel-gazelle gazelle() macro.

Resolves to the in-tree aspect gazelle binary and applies the same
API-restricted attribute shape as the parallel rule in //prebuilt/rules.bzl
so callers don't have to branch on which module they resolved to. The public
surface is //runner/def.bzl:aspect_gazelle — prefer that for end users.

Args:
name: Target name.
command: Gazelle subcommand. One of "update", "fix".
mode: Gazelle mode. One of "", "fix", "diff" (empty means gazelle's default).
extra_args: Extra arguments forwarded to the gazelle binary.
data: Additional runtime files needed by the invocation (e.g. files
referenced by $(location) tokens in `extra_args`).
env: Environment variables set before invoking gazelle. Tokens in values
are NOT location-expanded here (upstream `gazelle()` does not expand
them), unlike the parallel rule in //prebuilt/rules.bzl which does.
repo_config: Optional repo config file mapping Go module paths to custom
Bazel repository names. Typically
@bazel_gazelle_go_repository_config//:WORKSPACE when gazelle is a dep.
**kwargs: Standard Bazel rule attributes (e.g. `tags`, `visibility`,
`testonly`) forwarded to the underlying target.
"""
if command not in _VALID_COMMANDS:
fail("Invalid 'command' %r. Must be one of: %s" % (command, ", ".join(_VALID_COMMANDS)))
if mode not in _VALID_MODES:
fail("Invalid 'mode' %r. Must be one of: %s" % (mode, ", ".join(_VALID_MODES)))

if repo_config:
extra_args = ["-repo_config=$(location %s)" % repo_config] + extra_args
data = [repo_config] + data

gazelle(
name = name,
gazelle = _GAZELLE_BINARY,
command = command,
mode = mode,
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