Ensure that the rust_proto_library is in the same package as proto_library

PiperOrigin-RevId: 628308230
pull/16639/head
Marcel Hlopko 2024-04-25 23:44:09 -07:00 committed by Copybara-Service
parent 62f2b143d5
commit 93bd4bb012
3 changed files with 18 additions and 3 deletions

View File

@ -172,6 +172,11 @@ proto_lang_toolchain(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
package_group(
name = "rust_proto_library_allowed_in_different_package",
packages = ["//rust/test"], # for unittest proto_libraries
)
# This flag controls what kernel all Rust Protobufs are using in the current build. # This flag controls what kernel all Rust Protobufs are using in the current build.
string_flag( string_flag(
name = "rust_proto_library_kernel", name = "rust_proto_library_kernel",

View File

@ -33,6 +33,12 @@ RustProtoInfo = provider(
}, },
) )
def proto_rust_toolchain_label(is_upb):
if is_upb:
return "//rust:proto_rust_upb_toolchain"
else:
return "//rust:proto_rust_cpp_toolchain"
def _register_crate_mapping_write_action(name, actions, crate_mappings): def _register_crate_mapping_write_action(name, actions, crate_mappings):
"""Registers an action that generates a crate mapping for a proto_library. """Registers an action that generates a crate mapping for a proto_library.
@ -401,9 +407,7 @@ def _make_proto_library_aspect(is_upb):
cfg = "exec", cfg = "exec",
), ),
"_proto_lang_toolchain": attr.label( "_proto_lang_toolchain": attr.label(
default = Label( default = Label(proto_rust_toolchain_label(is_upb)),
"//rust:proto_rust_upb_toolchain" if is_upb else "//rust:proto_rust_cpp_toolchain",
),
), ),
}, },
fragments = ["cpp"], fragments = ["cpp"],

View File

@ -3,9 +3,11 @@
Disclaimer: This project is experimental, under heavy development, and should not Disclaimer: This project is experimental, under heavy development, and should not
be used yet.""" be used yet."""
load("@rules_proto//proto:defs.bzl", "ProtoInfo", "proto_common")
load( load(
"//rust:aspects.bzl", "//rust:aspects.bzl",
"RustProtoInfo", "RustProtoInfo",
"proto_rust_toolchain_label",
"rust_cc_proto_library_aspect", "rust_cc_proto_library_aspect",
"rust_upb_proto_library_aspect", "rust_upb_proto_library_aspect",
) )
@ -65,6 +67,7 @@ def _rust_proto_library_impl(ctx):
dep = deps[0] dep = deps[0]
rust_proto_info = dep[RustProtoInfo] rust_proto_info = dep[RustProtoInfo]
dep_variant_info = rust_proto_info.dep_variant_info dep_variant_info = rust_proto_info.dep_variant_info
return [ return [
dep_variant_info.crate_info, dep_variant_info.crate_info,
@ -82,6 +85,9 @@ def _make_rust_proto_library(is_upb):
providers = [ProtoInfo], providers = [ProtoInfo],
aspects = [rust_upb_proto_library_aspect if is_upb else rust_cc_proto_library_aspect], aspects = [rust_upb_proto_library_aspect if is_upb else rust_cc_proto_library_aspect],
), ),
"_proto_lang_toolchain": attr.label(
default = Label(proto_rust_toolchain_label(is_upb)),
),
}, },
) )