Apply buildifier

This commit is contained in:
Adam Liddell 2023-07-25 23:01:55 +01:00
parent 8248be4ec4
commit 28dd16e995
12 changed files with 47 additions and 52 deletions

9
rust/3rdparty/BUILD vendored
View File

@ -1,6 +1,7 @@
# Third party crates/deps for rules_proto_grpc_rust.
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
crates_vendor(
name = "crates_vendor",
annotations = {
@ -22,7 +23,7 @@ crates_vendor(
# See https://github.com/neoeinstein/protoc-gen-prost/issues/62
"protoc-gen-prost-crate": crate.spec(
git = "https://github.com/neoeinstein/protoc-gen-prost",
rev = "038cd342677dfa869f8c3a2a2787a139fc561df8"
rev = "038cd342677dfa869f8c3a2a2787a139fc561df8",
),
"protoc-gen-tonic": crate.spec(
version = "0.2.1",
@ -71,11 +72,11 @@ crates_vendor(
),
# See: https://github.com/influxdata/pbjson/pull/90
"pbjson-types": crate.spec(
git = 'https://github.com/echochamber/pbjson',
rev = 'a4f760e5d53086d989f28dc9d1d0adcc22fe37c4'
git = "https://github.com/echochamber/pbjson",
rev = "a4f760e5d53086d989f28dc9d1d0adcc22fe37c4",
),
"pbjson": crate.spec(
version = "0.5.1",
version = "0.5.1",
),
},
repository_name = "rules_proto_grpc_rust",

View File

@ -5,13 +5,13 @@ proto_plugin(
exclusions = [
# "google/protobuf",
],
separate_options_flag = True,
options = [
"file_descriptor_set",
"extern_path=.google.protobuf=::pbjson_types",
"compile_well_known_types",
"file_descriptor_set",
"extern_path=.google.protobuf=::pbjson_types",
"compile_well_known_types",
],
output_directory = True,
separate_options_flag = True,
tool = "@rules_proto_grpc//rust/3rdparty/crates:protoc-gen-prost-0.2.1__protoc-gen-prost",
visibility = ["//visibility:public"],
)
@ -22,12 +22,12 @@ proto_plugin(
# "google/protobuf",
],
options = [
"no_include",
"extern_path=.google.protobuf=::pbjson_types",
"compile_well_known_types",
"no_include",
"extern_path=.google.protobuf=::pbjson_types",
"compile_well_known_types",
],
separate_options_flag = True,
output_directory = True,
separate_options_flag = True,
tool = "@rules_proto_grpc//rust/3rdparty/crates:protoc-gen-tonic__protoc-gen-tonic",
visibility = ["//visibility:public"],
)
@ -37,9 +37,9 @@ proto_plugin(
exclusions = [
# "google/protobuf",
],
separate_options_flag = True,
options = ["no_features"],
output_directory = True,
separate_options_flag = True,
tool = "@rules_proto_grpc//rust/3rdparty/crates:protoc-gen-prost-crate__protoc-gen-prost-crate",
visibility = ["//visibility:public"],
)
@ -61,7 +61,6 @@ proto_plugin(
)
# @rules_proto_grpc_rust
sh_binary(
name = "rust_fixer",
srcs = ["rust_fixer.sh"],

View File

@ -1,12 +1,7 @@
"""Rules for compiling .proto files using the prost via the prost protoc plugins."""
load(
"//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile",
)
load(":providers.bzl", "ProstProtoInfo")
load("//:defs.bzl", "proto_compile")
load(":providers.bzl", "ProstProtoInfo")
prost_compile_attrs = [
"declared_proto_packages",
@ -25,6 +20,7 @@ def rust_prost_proto_compile_impl(ctx):
- (ProtoCompileInfo): From core proto_compile function
- (DefaultInfo): Default build rule info.
"""
# Build extern options
externs = []
for dep in ctx.attr.prost_proto_deps:
@ -33,7 +29,7 @@ def rust_prost_proto_compile_impl(ctx):
proto_info = dep[ProstProtoInfo]
packages = proto_info.declared_proto_packages
dep_crate = proto_info.crate_name or proto_info.name
for package in packages:
externs.append("extern_path={}=::{}::{}".format(
"." + package,
@ -47,15 +43,16 @@ def rust_prost_proto_compile_impl(ctx):
if "//rust:rust_prost_plugin" not in options:
options["//rust:rust_prost_plugin"] = []
options["//rust:rust_prost_plugin"] = options["//rust:rust_prost_plugin"] + externs
compile_result = proto_compile(
ctx,
options,
getattr(ctx.attr, "extra_protoc_args", []),
ctx.files.extra_protoc_files)
ctx.files.extra_protoc_files,
)
crate_name = ctx.attr.crate_name or ctx.attr.name
return compile_result + [ProstProtoInfo(
declared_proto_packages = ctx.attr.declared_proto_packages,
crate_name = crate_name
crate_name = crate_name,
)]

View File

@ -1,4 +1,5 @@
"""3rd party crate dependencies for rules_rust."""
load("//rust/3rdparty/crates:crates.bzl", _crate_repositories = "crate_repositories")
crate_repositories = _crate_repositories
crate_repositories = _crate_repositories

View File

@ -1,22 +1,22 @@
load("//rust:defs.bzl", "rust_prost_proto_library", "rust_tonic_grpc_library")
rust_tonic_grpc_library(
name = "greeter_grpc",
declared_proto_packages = ["example.proto"],
protos = [
"//example/proto:person_proto",
"//example/proto:place_proto",
"//example/proto:greeter_grpc",
],
options = {
"//rust:rust_prost_plugin": [
"type_attribute=.example.proto.Person=#[derive(Eq\\,Hash)]",
"type_attribute=.example.proto.Place=#[derive(Eq\\,Hash)]",
]},
],
},
prost_proto_deps = [
":other_prost",
]
],
protos = [
"//example/proto:greeter_grpc",
"//example/proto:person_proto",
"//example/proto:place_proto",
],
)
rust_prost_proto_library(
@ -25,4 +25,4 @@ rust_prost_proto_library(
protos = [
"//example/proto:thing_proto",
],
)
)

View File

@ -3,20 +3,20 @@ load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_prost_proto_library(
name = "routeguide_prost",
declared_proto_packages = ["routeguide"],
options = {
"//rust:rust_prost_plugin": ["type_attribute=.routeguide.Point=#[derive(Eq\\,Hash)]"],
},
declared_proto_packages = ["routeguide"],
protos = ["//example/proto:routeguide_proto"],
)
rust_tonic_grpc_library(
name = "routeguide_tonic",
protos = ["//example/proto:routeguide_proto"],
declared_proto_packages = ["routeguide"],
options = {
"//rust:rust_prost_plugin": ["type_attribute=.routeguide.Point=#[derive(Eq\\,Hash)]"],
},
protos = ["//example/proto:routeguide_proto"],
# prost_proto = ":routeguide_prost",
# service_proto_package = "routeguide",
)
@ -45,7 +45,6 @@ rust_binary(
"data.rs",
"server.rs",
],
data = ["//example/proto:routeguide_features"],
edition = "2021",
visibility = ["//example/routeguide:__pkg__"],

View File

@ -1,7 +1,9 @@
"""Provider for Rust Prost info."""
ProstProtoInfo = provider(
doc = "Additional information needed for prost compilation rules.",
fields = {
"crate_name": "Name of the crate that will wrap this module.",
"declared_proto_packages": "All proto packages that this compile rule generates bindings for.",
}
},
)

View File

@ -6,7 +6,6 @@ load(
"rules_rust",
)
def rust_repos(**kwargs): # buildifier: disable=function-docstring
rules_proto_grpc_repos(**kwargs)
rules_rust(**kwargs)

View File

@ -4,7 +4,6 @@ load(
"//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
)
load(":compile.bzl", "rust_prost_proto_compile_impl")
load(":providers.bzl", "ProstProtoInfo")
@ -16,7 +15,7 @@ rust_prost_proto_compile = rule(
prost_proto_deps = attr.label_list(
providers = [ProstProtoInfo],
mandatory = False,
doc = "Other protos compiled by prost that our proto directly depends upon. Used to generated externs_path=... options for prost."
doc = "Other protos compiled by prost that our proto directly depends upon. Used to generated externs_path=... options for prost.",
),
declared_proto_packages = attr.string_list(
mandatory = True,

View File

@ -13,7 +13,6 @@ def _crate(name):
# 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.
def _prepare_prost_proto_deps(prost_proto_deps):
prost_proto_compiled_targets = []
for dep in prost_proto_deps:
@ -65,10 +64,10 @@ def rust_prost_proto_library(name, **kwargs): # buildifier: disable=function-do
crate_name = kwargs.get("crate_name"),
srcs = [name_fixed],
deps = kwargs.get("prost_deps", [_crate("prost"), _crate("prost-types")]) +
kwargs.get("pbjson_deps", [_crate("pbjson-types"), _crate("pbjson")]) +
kwargs.get("serde_deps", [_crate("serde")]) +
kwargs.get("deps", []) +
prost_proto_deps,
kwargs.get("pbjson_deps", [_crate("pbjson-types"), _crate("pbjson")]) +
kwargs.get("serde_deps", [_crate("serde")]) +
kwargs.get("deps", []) +
prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", _crate("prost-derive"))],
**{
k: v

View File

@ -1,9 +1,9 @@
"""Rules for compiling .proto files using the prost via the prost protoc plugins."""
load(
"//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile",
)
load(":compile.bzl", "rust_prost_proto_compile_impl")
load(":providers.bzl", "ProstProtoInfo")
@ -15,7 +15,7 @@ rust_tonic_grpc_compile = rule(
prost_proto_deps = attr.label_list(
providers = [ProstProtoInfo],
mandatory = False,
doc = "Other protos compiled by prost that our proto directly depends upon. Used to generated externs_path=... options for prost."
doc = "Other protos compiled by prost that our proto directly depends upon. Used to generated externs_path=... options for prost.",
),
declared_proto_packages = attr.string_list(
mandatory = True,
@ -37,4 +37,4 @@ rust_tonic_grpc_compile = rule(
),
),
toolchains = [str(Label("//protobuf:toolchain_type"))],
)
)

View File

@ -13,7 +13,6 @@ def _crate(name):
# 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.
def _prepare_prost_proto_deps(prost_proto_deps):
prost_proto_compiled_targets = []
for dep in prost_proto_deps:
@ -65,7 +64,7 @@ def rust_tonic_grpc_library(name, **kwargs): # buildifier: disable=function-doc
deps = kwargs.get("prost_deps", [_crate("prost"), _crate("prost-types")]) +
[kwargs.get("tonic_dep", _crate("tonic"))] +
kwargs.get("pbjson_deps", [_crate("pbjson-types"), _crate("pbjson")]) +
kwargs.get("serde_deps", [_crate("serde")]) + # Label(CRATES_PATH + ":serde-types")
kwargs.get("serde_deps", [_crate("serde")]) + # Label(CRATES_PATH + ":serde-types")
kwargs.get("deps", []) + prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", Label("//rust/3rdparty/crates:prost-derive"))],
**{