Skip to content

Commit

Permalink
Build: one proto per proto_library (#26)
Browse files Browse the repository at this point in the history
Bazel
[docs](https://bazel.build/reference/be/protocol-buffer#proto_library)
recommend:

> One `proto_library` rule per `.proto` file.

I also encountered the following error when trying to include
`protovalidate` in some internal repos:

```
Error in fail: attribute srcs: Can only compile a single .proto file at a time.
```

---

This is a very small change but it would be amazing to get it into the
next release 🙏🏻

---------

Co-authored-by: Chris Roche <[email protected]>
  • Loading branch information
ggirelli and rodaine authored Sep 12, 2023
1 parent fa51112 commit d8ae2ed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proto_library(
strip_import_prefix = "/proto/protovalidate-testing",
visibility = ["//visibility:public"],
deps = [
"//proto/protovalidate/buf/validate:validate_proto",
"//proto/protovalidate/buf/validate:expression_proto",
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto",
],
Expand Down
27 changes: 23 additions & 4 deletions proto/protovalidate/buf/validate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_buf//buf:defs.bzl", "buf_lint_test")

# gazelle:proto file

proto_library(
name = "validate_proto",
srcs = [
"expression.proto",
"validate.proto",
],
srcs = ["validate.proto"],
strip_import_prefix = "/proto/protovalidate",
visibility = ["//visibility:public"],
deps = [
":expression_proto",
"//proto/protovalidate/buf/validate/priv:priv_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
Expand All @@ -42,3 +42,22 @@ cc_proto_library(
visibility = ["//visibility:public"],
deps = [":validate_proto"],
)

proto_library(
name = "expression_proto",
srcs = ["expression.proto"],
strip_import_prefix = "/proto/protovalidate",
visibility = ["//visibility:public"],
)

buf_lint_test(
name = "expression_proto_lint",
config = "//proto/protovalidate:buf.yaml",
targets = [":expression_proto"],
)

cc_proto_library(
name = "expression_proto_cc",
visibility = ["//visibility:public"],
deps = [":expression_proto"],
)
2 changes: 2 additions & 0 deletions proto/protovalidate/buf/validate/priv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_buf//buf:defs.bzl", "buf_lint_test")

# gazelle:proto default

proto_library(
name = "priv_proto",
srcs = ["private.proto"],
Expand Down

0 comments on commit d8ae2ed

Please sign in to comment.