Extract _crate function to common.bzl

This commit is contained in:
Adam Liddell 2023-07-25 23:49:29 +01:00
parent 63fe77af11
commit 09d5274b39
3 changed files with 21 additions and 33 deletions

View File

@ -1,15 +1,11 @@
"""Generated definition of rust_prost_proto_library."""
load("//rust:common.bzl", "prost_compile_attrs")
load("//rust:common.bzl", "create_name_to_label", "prost_compile_attrs")
load("//rust:rust_prost_proto_compile.bzl", "rust_prost_proto_compile")
load("//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs")
load("//rust:rust_fixer.bzl", "rust_proto_crate_fixer", "rust_proto_crate_root")
load("@rules_rust//rust:defs.bzl", "rust_library")
def _crate(name):
"""Convert a simple crate name into its full label."""
return Label("//rust/3rdparty/crates:" + name)
# 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.
@ -64,12 +60,12 @@ def rust_prost_proto_library(name, **kwargs): # buildifier: disable=function-do
crate_root = name_root,
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")]) +
deps = kwargs.get("prost_deps", [create_name_to_label("prost"), create_name_to_label("prost-types")]) +
kwargs.get("pbjson_deps", [create_name_to_label("pbjson-types"), create_name_to_label("pbjson")]) +
kwargs.get("serde_deps", [create_name_to_label("serde")]) +
kwargs.get("deps", []) +
prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", _crate("prost-derive"))],
proc_macro_deps = [kwargs.get("prost_derive_dep", create_name_to_label("prost-derive"))],
**{
k: v
for (k, v) in kwargs.items()

View File

@ -1,15 +1,11 @@
"""Generated definition of rust_tonic_grpc_library."""
load("//rust:common.bzl", "prost_compile_attrs")
load("//rust:common.bzl", "create_name_to_label", "prost_compile_attrs")
load("//rust:rust_tonic_grpc_compile.bzl", "rust_tonic_grpc_compile")
load("//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs")
load("//rust:rust_fixer.bzl", "rust_proto_crate_fixer", "rust_proto_crate_root")
load("@rules_rust//rust:defs.bzl", "rust_library")
def _crate(name):
"""Convert a simple crate name into its full label."""
return Label("//rust/3rdparty/crates:" + name)
# 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.
@ -65,13 +61,13 @@ def rust_tonic_grpc_library(name, **kwargs): # buildifier: disable=function-doc
crate_root = name_root,
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("tonic_deps", [_crate("tonic")]) +
deps = kwargs.get("prost_deps", [create_name_to_label("prost"), create_name_to_label("prost-types")]) +
kwargs.get("pbjson_deps", [create_name_to_label("pbjson-types"), create_name_to_label("pbjson")]) +
kwargs.get("serde_deps", [create_name_to_label("serde")]) +
kwargs.get("tonic_deps", [create_name_to_label("tonic")]) +
kwargs.get("deps", []) +
prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", _crate("prost-derive"))],
proc_macro_deps = [kwargs.get("prost_derive_dep", create_name_to_label("prost-derive"))],
**{
k: v
for (k, v) in kwargs.items()

View File

@ -60,16 +60,12 @@ load("@rules_proto_grpc//rust:crate_deps.bzl", "crate_repositories")
crate_repositories()
`)
var rustLibraryRuleTemplateString = `load("//rust:common.bzl", "prost_compile_attrs")
var rustLibraryRuleTemplateString = `load("//rust:common.bzl", "create_name_to_label", "prost_compile_attrs")
load("//{{ .Lang.Dir }}:{{ .Rule.Base }}_{{ .Rule.Kind }}_compile.bzl", "{{ .Rule.Base }}_{{ .Rule.Kind }}_compile")
load("//:defs.bzl", "bazel_build_rule_common_attrs", "proto_compile_attrs")
load("//{{ .Lang.Dir }}:rust_fixer.bzl", "rust_proto_crate_fixer", "rust_proto_crate_root")
load("@rules_rust//rust:defs.bzl", "rust_library")
def _crate(name):
"""Convert a simple crate name into its full label."""
return Label("//rust/3rdparty/crates:" + name)
# 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.
@ -126,12 +122,12 @@ var rustProstProtoLibraryRuleTemplate = mustTemplate(rustLibraryRuleTemplateStri
crate_root = name_root,
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")]) +
deps = kwargs.get("prost_deps", [create_name_to_label("prost"), create_name_to_label("prost-types")]) +
kwargs.get("pbjson_deps", [create_name_to_label("pbjson-types"), create_name_to_label("pbjson")]) +
kwargs.get("serde_deps", [create_name_to_label("serde")]) +
kwargs.get("deps", []) +
prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", _crate("prost-derive"))],
proc_macro_deps = [kwargs.get("prost_derive_dep", create_name_to_label("prost-derive"))],
{{ .Common.LibraryArgsForwardingSnippet }}
)`)
@ -149,13 +145,13 @@ var rustTonicGrpcLibraryRuleTemplate = mustTemplate(rustLibraryRuleTemplateStrin
crate_root = name_root,
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("tonic_deps", [_crate("tonic")]) +
deps = kwargs.get("prost_deps", [create_name_to_label("prost"), create_name_to_label("prost-types")]) +
kwargs.get("pbjson_deps", [create_name_to_label("pbjson-types"), create_name_to_label("pbjson")]) +
kwargs.get("serde_deps", [create_name_to_label("serde")]) +
kwargs.get("tonic_deps", [create_name_to_label("tonic")]) +
kwargs.get("deps", []) +
prost_proto_deps,
proc_macro_deps = [kwargs.get("prost_derive_dep", _crate("prost-derive"))],
proc_macro_deps = [kwargs.get("prost_derive_dep", create_name_to_label("prost-derive"))],
{{ .Common.LibraryArgsForwardingSnippet }}
)`)