diff --git a/rust/defs.bzl b/rust/defs.bzl index 7ad37d0751b80..60371837120f8 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -29,27 +29,29 @@ def rust_proto_library(name, deps, **args): .format(name), ) name = name.removesuffix("_rust_proto") + rust_cpp_target_name = "_%s_cpp_rust_proto" % name + rust_upb_target_name = "_%s_upb_rust_proto" % name alias_args = {} if "visibility" in args: alias_args["visibility"] = args.pop("visibility") native.alias( name = name + "_rust_proto", actual = select({ - "//rust:use_upb_kernel": name + "_upb_rust_proto", - "//conditions:default": name + "_cpp_rust_proto", + "//rust:use_upb_kernel": rust_upb_target_name, + "//conditions:default": rust_cpp_target_name, }), **alias_args ) rust_upb_proto_library( - name = name + "_upb_rust_proto", + name = rust_upb_target_name, deps = deps, visibility = ["//rust/test:__subpackages__"], **args ) rust_cc_proto_library( - name = name + "_cpp_rust_proto", + name = rust_cpp_target_name, deps = deps, visibility = ["//rust/test:__subpackages__"], **args diff --git a/rust/rules.bzl b/rust/rules.bzl index 941e9957e0d2b..0afdb6b3ac35b 100644 --- a/rust/rules.bzl +++ b/rust/rules.bzl @@ -24,6 +24,10 @@ ProtoCrateNamesInfo = provider( def _user_visible_label(ctx): label = str(ctx.label) + + # Remove exactly one leading underscore for the crate name, since we add that when + # rust_proto_library delegates to either rust_cc_proto_library or rust_upb_proto_library. + label = label.removeprefix("_") label = label.removesuffix("_cpp_rust_proto") label = label.removesuffix("_upb_rust_proto") return label + "_rust_proto"