Skip to content

Conversation

@electronjoe
Copy link

This PR stacks on top of !127 but I've split them as the rationale is different / you might not agree with both (let me know!). The issue of this PR was uncovered in !127 fix of #117. This PR Plus !127 resolve at least the base case issues of #117.

Fix target name generation in the buf gazelle plugin's CrossResolve function to use the proto file name instead of the directory name. This aligns with the official Bazel proto_library naming convention documented at: https://bazel.build/reference/be/protocol-buffer

Per Bazel's convention: "A file named foo.proto will be in a rule named foo_proto, which is located in the same package."

The original code used proto.RuleName(path.Dir(importSpec.Imp)) which incorrectly derived target names from the directory path.

Example import: logical/interface.proto
Before (wrong): @buf_deps//logical:logical_proto (from directory)
After (correct): @buf_deps//logical:interface_proto (from file)

Co-Authored-By: Claude Opus 4.5 [email protected]

electronjoe and others added 2 commits January 16, 2026 17:44
…ution

Addresses bufbuild#117.

Add support for `gazelle:resolve buf` directives in the buf gazelle plugin's
`CrossResolve` function. This allows users to override the default `@buf_deps//`
resolution for proto imports, enabling proper integration with `local_path_override`
modules in bzlmod monorepos.

The `CrossResolve` function now first checks for `gazelle:resolve buf` directives
using the standard `resolve.FindRuleWithOverride` function. If a matching directive
is found, return that label. Otherwise, fall back to the default `@buf_deps//`
resolution.

Example Usage

```python

This directive goes in a BUILD file (typically root or parent directory) and tells gazelle to resolve imports of proto/foo/bar.proto to the label @com_example//proto/foo:bar_proto instead of the default @buf_deps//... resolution.
```

Test Coverage

```
bazel test //...
```

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Fix target name generation in the buf gazelle plugin's `CrossResolve` function
to use the proto file name instead of the directory name. This aligns with the
official Bazel proto_library naming convention documented at:
https://bazel.build/reference/be/protocol-buffer

Per Bazel's convention: "A file named foo.proto will be in a rule named
foo_proto, which is located in the same package."

The original code used `proto.RuleName(path.Dir(importSpec.Imp))` which
incorrectly derived target names from the directory path.

Example import: `logical/interface.proto`
  Before (wrong): `@buf_deps//logical:logical_proto` (from directory)
  After (correct): `@buf_deps//logical:interface_proto` (from file)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

1 participant