Align rulegen and buildifier

This commit is contained in:
Adam Liddell 2023-09-08 12:20:17 +01:00
parent 6a0f5f93a6
commit f2cc8a3369
11 changed files with 56 additions and 57 deletions

View File

@ -61,7 +61,6 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
``BUILD.bazel``
^^^^^^^^^^^^^^^
@ -191,7 +190,6 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
``BUILD.bazel``
^^^^^^^^^^^^^^^
@ -204,8 +202,8 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
name = "greeter_rust_grpc",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
)
@ -303,7 +301,6 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
``BUILD.bazel``
^^^^^^^^^^^^^^^
@ -315,10 +312,6 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
rust_prost_proto_library(
name = "person_place_rust_prost_proto",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -328,18 +321,22 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
prost_proto_deps = [
":thing_rust_prost_proto",
],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
)
rust_prost_proto_library(
name = "thing_rust_prost_proto",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
options = {
# Known limitation, can't derive if the type contains a pbjson type.
# "//rust:rust_prost_plugin": ["type_attribute=.example.proto.Thing=#[derive(Eq\\,Hash)]"],
},
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
)
Attributes
@ -443,24 +440,17 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
``BUILD.bazel``
^^^^^^^^^^^^^^^
.. code-block:: python
load("@rules_proto_grpc//rust:defs.bzl", "rust_tonic_grpc_library", "rust_prost_proto_library")
load("@rules_proto_grpc//rust:defs.bzl", "rust_prost_proto_library", "rust_tonic_grpc_library")
rust_tonic_grpc_library(
name = "greeter_rust_tonic_grpc",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -471,6 +461,12 @@ Full example project can be found `here <https://github.com/rules-proto-grpc/rul
prost_proto_deps = [
":thing_prost",
],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
)
# See https://github.com/rules-proto-grpc/rules_proto_grpc/pull/265/#issuecomment-1577920311

View File

@ -36,4 +36,3 @@ crate_universe_dependencies(bootstrap = True)
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()

View File

@ -3,10 +3,6 @@ load("@rules_proto_grpc//rust:defs.bzl", "rust_prost_proto_library")
rust_prost_proto_library(
name = "person_place_rust_prost_proto",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -16,16 +12,20 @@ rust_prost_proto_library(
prost_proto_deps = [
":thing_rust_prost_proto",
],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
)
rust_prost_proto_library(
name = "thing_rust_prost_proto",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
options = {
# Known limitation, can't derive if the type contains a pbjson type.
# "//rust:rust_prost_plugin": ["type_attribute=.example.proto.Thing=#[derive(Eq\\,Hash)]"],
},
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
)

View File

@ -36,4 +36,3 @@ crate_universe_dependencies(bootstrap = True)
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()

View File

@ -4,7 +4,7 @@ rust_tonic_grpc_compile(
name = "greeter_rust_grpc",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
)

View File

@ -36,4 +36,3 @@ crate_universe_dependencies(bootstrap = True)
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()

View File

@ -1,14 +1,8 @@
load("@rules_proto_grpc//rust:defs.bzl", "rust_tonic_grpc_library", "rust_prost_proto_library")
load("@rules_proto_grpc//rust:defs.bzl", "rust_prost_proto_library", "rust_tonic_grpc_library")
rust_tonic_grpc_library(
name = "greeter_rust_tonic_grpc",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -19,6 +13,12 @@ rust_tonic_grpc_library(
prost_proto_deps = [
":thing_prost",
],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
)
# See https://github.com/rules-proto-grpc/rules_proto_grpc/pull/265/#issuecomment-1577920311

View File

@ -36,4 +36,3 @@ crate_universe_dependencies(bootstrap = True)
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()

View File

@ -144,7 +144,7 @@ def snake_case(s):
for char in s.elems():
if char.isupper():
if is_last_lower_case:
converted += "_"+char
converted += "_" + char
is_last_lower_case = False
continue
elif char.islower() or char.isdigit():

View File

@ -20,7 +20,15 @@ def create_name_to_label(name):
return Label("//rust/3rdparty/crates:" + name)
def prepare_prost_proto_deps(prost_proto_deps):
"""Convert a list of prost proto deps to correct format."""
"""Convert a list of prost proto deps to correct format.
Args:
prost_proto_deps: List of target names to be converted.
Returns:
List of converted target names.
"""
# We assume that all targets in prost_proto_deps[] were also generated with this macro.
# For convenience we append the _pb suffix if its missing to allow users to provide the same
# name as they used when they used this macro to generate that dependency.

View File

@ -56,8 +56,7 @@ crate_universe_dependencies(bootstrap = True)
load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
`)
crate_repositories()`)
var rustLibraryRuleTemplateString = `load("//rust:common.bzl", "create_name_to_label", "prepare_prost_proto_deps", "prost_compile_attrs")
load("//{{ .Lang.Dir }}:{{ .Rule.Base }}_{{ .Rule.Kind }}_compile.bzl", "{{ .Rule.Base }}_{{ .Rule.Kind }}_compile")
@ -176,8 +175,8 @@ var rustGrpcCompileExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .
name = "greeter_{{ .Lang.Name }}_{{ .Rule.Kind }}",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
)`)
@ -186,10 +185,6 @@ var rustProtoLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{
{{ .Rule.Name }}(
name = "person_place_{{ .Rule.Base }}_{{ .Rule.Kind }}",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -199,31 +194,29 @@ var rustProtoLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{
prost_proto_deps = [
":thing_{{ .Rule.Base }}_{{ .Rule.Kind }}",
],
protos = [
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
],
)
{{ .Rule.Name }}(
name = "thing_{{ .Rule.Base }}_{{ .Rule.Kind }}",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
options = {
# Known limitation, can't derive if the type contains a pbjson type.
# "//rust:rust_prost_plugin": ["type_attribute=.example.proto.Thing=#[derive(Eq\\,Hash)]"],
},
protos = [
"@rules_proto_grpc//example/proto:thing_proto",
],
)`)
var rustGrpcLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .Lang.Dir }}:defs.bzl", "{{ .Rule.Name }}", "rust_prost_proto_library")
var rustGrpcLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .Lang.Dir }}:defs.bzl", "rust_prost_proto_library", "{{ .Rule.Name }}")
{{ .Rule.Name }}(
name = "greeter_{{ .Rule.Base }}_{{ .Rule.Kind }}",
declared_proto_packages = ["example.proto"],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
@ -234,6 +227,12 @@ var rustGrpcLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .
prost_proto_deps = [
":thing_prost",
],
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:person_proto",
"@rules_proto_grpc//example/proto:place_proto",
# "@rules_proto_grpc//example/proto:thing_proto",
],
)
# See https://github.com/rules-proto-grpc/rules_proto_grpc/pull/265/#issuecomment-1577920311