Repository navigation
Description
My team and I are evaluating rules_buf for our project and have run into several integration challenges. Would love to get some clarity on the current capabilities and recommendation.
Workspace setup
- Multiple proto trees with different import paths
- example: directory:
/service/common/common.protoimport path:company.com/sub//service/common
- example: directory:
- Existing Bazel build setup with gazelle directives
- A preference to avoid publishing to BSR for dependency management
Questions/Issues
1. Dependency Management Without BSR
The Buf documentation states that dependencies must be published to BSR:
The value must be a valid path to a BSR module (either the public BSR at buf.build or a private BSR instance). It can't be a local Git reference to a buf.yaml file or a URL path to a Git repo.
Question: Is there any support for local dependencies or workspace-style setups? We have multiple proto modules in the same repo that need to reference each other, but we'd prefer not to publish internal modules to BSR.
2. Gazelle Integration and Ignore Patterns
Questions:
- Does rules_buf respect
gazelle:resolvedirectives for controlling dependency resolution? - How does it interact with
.bazelignorefiles? We need certain directories to be excluded from processing.
3. Multi-Module Repo Support
Since we have multiple proto trees with different import paths:
- Can rules_buf handle multiple buf modules in a single repository?
- What's the recommended approach for this kind of setup?
Example: We have a repository structure like:
/core # Contains foundational proto definitions (separate bzlmod module)
/service # Contains service-specific protos that import from /core
Where the /service protos have imports like:
import "core/types/common.proto";
import "core/config/settings.proto";Currently, each directory only contains Bazel BUILD files with proto_library definitions - there are no buf.yaml files in these directories yet. The /core directory is configured as a separate bzlmod module, and the /service protos depend on definitions from /core, but we need both to be built together in the same repository without publishing /core to BSR as an external dependency.
4. Well-Known Types Import Resolution
We're encountering errors for standard protobuf types when running bazel run //:buf_breaking:
system error: proto: could not resolve import "google/protobuf/timestamp.proto": not found
Questions:
- How should well-known types (like
google/protobuf/*) be handled in rules_buf? From our understanding this should work out the box. - Are there dependencies or buf modules that need to be explicitly declared for well-known types?
Any guidance, examples, or documentation pointers would be greatly appreciated! Happy to provide more specific details about our setup if that would help.
Thanks!
Activity
srikrsna-buf commentedon Jul 28, 2025
For local, we don't need a special rule. Regular bazel repo rules will work.
rules_bufdoesn't interfere withproto_libraryimports unless the gazelle proto plugin is unable to figure it out. If everything is local it should be able to figure it out. You can read more on this here.The
gazelle:excludedirective can be used, more on this here.Yes, you can look at this example.
Dependencies need to be declared but they are handled by gazelle. Otherwise they need to be added from the protobuf repo.
michaelloehnig commentedon Jul 28, 2025
Thanks for the helpful response!
The reason that I ask about
gazelle:resolveis becauseWe have a
local_path_overridein our setup:When we run
bazel run //:gazelle, it always adds out"core"modules as "@buf_deps//core/...:core_proto", instead of using the referenceorg_example_corewhich is local. This causes an issue when running thebuf_breaking_testsince it attempts to find the modules externally. We need gazelle to use themodule_namerather than the path because our.bazelignorefilters out thecoredirectory.Is there a way to configure gazelle to respect the
module_namefrom thelocal_path_overrideinstead of using the path?After manually editing the
buf_breaking_testdefinition to use the appropriate module name, we're still getting:We've tried adding these dependencies to our
buf.yaml:But this didn't resolve the import issues. It is mentioned here that these types should work out of the box, is there a way to debug why they are not being found?
For further context here is a slimmed down version of out tree structure:
Any suggestions for troubleshooting this would be really helpful!
ciarand commentedon Sep 9, 2025
Just chiming in here with a few more details:
Our setup:
local_path_override) with its own .proto files.gazelle:resolvedirectives that make the core Gazelle experience work relatively seamlessly across module boundaries (running Gazelle generates buildable libraries, libraries that depend on targets from both the root module and the core submodule work correctly)..bazelignorefile to work around Targets in nested modules are visible from top module bazelbuild/bazel#21515What we expected:
buf_breaking_testrule. Targets within thecore/directory should be generated as@org_example_core//target/nameWhat we're getting:
buf_breaking_testrule that look like@buf_deps//core/v1/proto:proto_protoWhat we've tried:
gazelle:resolve protodirectives (seem to be ignored by the Buf Gazelle plugin)I recognize that this is probably a bit of an unusual case. Our team would be happy to help contribute fixes to make this work, but probably need some guidance on how you'd like cases like this to be handled in the future
feat(gazelle): respect gazelle:resolve buf directives for cross resol…
feat(gazelle): respect gazelle:resolve buf directives for cross resol…
feat(gazelle): respect gazelle:resolve buf directives for cross resol…
Add support for `gazelle:resolve` directives (#127)