Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add renaming support to rust_proto_library targets. #1145

Merged
merged 3 commits into from
Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ load("//rust:defs.bzl", "rust_common")
load("//rust/private:rustc.bzl", "rustc_compile_action")

# buildifier: disable=bzl-visibility
load("//rust/private:utils.bzl", "determine_output_hash", "find_toolchain", "transform_deps")
load("//rust/private:utils.bzl", "compute_crate_name", "determine_output_hash", "find_toolchain", "transform_deps")

RustProtoInfo = provider(
doc = "Rust protobuf provider info",
Expand Down Expand Up @@ -168,7 +168,7 @@ def _expand_provider(lst, provider):
"""
return [el[provider] for el in lst if provider in el]

def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_grpc, compile_deps):
def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_grpc, compile_deps, toolchain):
"""Create and run a rustc compile action based on the current rule's attributes

Args:
Expand All @@ -179,6 +179,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
ctx (ctx): The current rule's context object
is_grpc (bool): True if the current rule is a `gRPC` rule.
compile_deps (list): A list of Rust dependencies (`List[Target]`)
toolchain (rust_toolchain): the current `rust_toolchain`.

Returns:
list: A list of providers, see `rustc_compile_action`
Expand Down Expand Up @@ -223,7 +224,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
return rustc_compile_action(
ctx = ctx,
attr = ctx.attr,
toolchain = find_toolchain(ctx),
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
name = crate_name,
type = "rlib",
Expand Down Expand Up @@ -260,14 +261,18 @@ def _rust_protogrpc_library_impl(ctx, is_grpc):
if RustProtoInfo in f
]

toolchain = find_toolchain(ctx)
crate_name = compute_crate_name(ctx.workspace_name, ctx.label, toolchain)

return _rust_proto_compile(
protos = depset(transitive = transitive_sources),
descriptor_sets = depset(transitive = [p.transitive_descriptor_sets for p in proto]),
imports = depset(transitive = [p.transitive_imports for p in proto]),
crate_name = ctx.label.name,
crate_name = crate_name,
ctx = ctx,
is_grpc = is_grpc,
compile_deps = ctx.attr.rust_deps,
toolchain = toolchain,
)

def _rust_proto_library_impl(ctx):
Expand Down