diff --git a/rust/defs.bzl b/rust/defs.bzl index da65623139..b63e4375b9 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -30,40 +30,60 @@ def rust_proto_library(name, deps, **args): **args: other args passed to the rust__proto_library targets. """ if not name.endswith("_rust_proto"): - fail("Name of each rust_proto_library target should end with `_rust_proto`") - + fail( + "{}: Name rust_proto_library target should end with `_rust_proto`, but was '{}'" + .format(name), + ) + name = name.removesuffix("_rust_proto") alias_args = {} if "visibility" in args: alias_args["visibility"] = args.pop("visibility") native.alias( - name = name, + name = name + "_rust_proto", actual = select({ - "//rust:use_upb_kernel": name + "_upb_kernel", - "//conditions:default": name + "_cpp_kernel", + "//rust:use_upb_kernel": name + "_upb_rust_proto", + "//conditions:default": name + "_cpp_rust_proto", }), **alias_args ) rust_upb_proto_library( - name = name + "_upb_kernel", + name = name + "_upb_rust_proto", deps = deps, visibility = ["//visibility:private"], **args ) rust_cc_proto_library( - name = name + "_cpp_kernel", + name = name + "_cpp_rust_proto", deps = deps, visibility = ["//visibility:private"], **args ) +def _user_visible_label(ctx): + label = str(ctx.label) + label = label.removesuffix("_cpp_rust_proto") + label = label.removesuffix("_upb_rust_proto") + return label + "_rust_proto" + def _rust_proto_library_impl(ctx): + if not ctx.label.name.endswith("_rust_proto"): + fail( + "{}: Name of rust_proto_library target should end with `_rust_proto`." + .format(_user_visible_label(ctx)), + ) deps = ctx.attr.deps if not deps: - fail("Exactly 1 dependency in `deps` attribute expected, none were provided.") + fail( + "{}: Exactly 1 dependency in `deps` attribute expected, none were provided." + .format(_user_visible_label(ctx)), + ) if len(deps) > 1: - fail("Exactly 1 dependency in `deps` attribute expected, too many were provided.") + fail( + "{}: Exactly 1 dependency in `deps` attribute expected, too many were provided." + .format(_user_visible_label(ctx)), + ) dep = deps[0] rust_proto_info = dep[RustProtoInfo] diff --git a/rust/test/BUILD b/rust/test/BUILD index 898bb075bc..9e3e9c44cd 100644 --- a/rust/test/BUILD +++ b/rust/test/BUILD @@ -1,7 +1,6 @@ load( "//rust:defs.bzl", "rust_cc_proto_library", - "rust_proto_library", "rust_upb_proto_library", ) @@ -11,13 +10,6 @@ UNITTEST_PROTO3_TARGET = "//src/google/protobuf:test_protos" UNITTEST_PROTO3_OPTIONAL_TARGET = "//src/google/protobuf:test_protos" -rust_proto_library( - name = "unittest_rust_proto", - testonly = True, - visibility = ["//visibility:private"], - deps = [UNITTEST_PROTO_TARGET], -) - rust_upb_proto_library( name = "unittest_upb_rust_proto", testonly = True, @@ -35,15 +27,6 @@ rust_cc_proto_library( deps = [UNITTEST_PROTO_TARGET], ) -rust_proto_library( - name = "unittest_proto3_rust_proto", - testonly = True, - visibility = ["//visibility:private"], - deps = [ - UNITTEST_PROTO3_TARGET, - ], -) - rust_cc_proto_library( name = "unittest_proto3_cc_rust_proto", testonly = True, @@ -58,15 +41,6 @@ rust_upb_proto_library( deps = [UNITTEST_PROTO3_TARGET], ) -rust_proto_library( - name = "unittest_proto3_optional_rust_proto", - testonly = True, - visibility = ["//visibility:private"], - deps = [ - UNITTEST_PROTO3_OPTIONAL_TARGET, - ], -) - rust_cc_proto_library( name = "unittest_proto3_optional_cc_rust_proto", testonly = True, diff --git a/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl b/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl index 610747666b..89ec161cce 100644 --- a/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl +++ b/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl @@ -173,8 +173,8 @@ def _rust_outputs_test_impl(ctx): target_under_test = analysistest.target_under_test(env) label_to_file = { - "child_rust_cc_proto": "child.c.pb.rs", - "child_rust_upb_proto": "child.u.pb.rs", + "child_cc_rust_proto": "child.c.pb.rs", + "child_upb_rust_proto": "child.u.pb.rs", } expected_output = label_to_file[target_under_test.label.name] asserts.true(env, target_under_test.files.to_list()[0].path.endswith(expected_output)) @@ -185,24 +185,24 @@ rust_outputs_test = analysistest.make(_rust_outputs_test_impl) def _test_cc_outputs(): rust_cc_proto_library( - name = "child_rust_cc_proto", + name = "child_cc_rust_proto", deps = [":child_proto"], ) rust_outputs_test( name = "rust_cc_outputs_test", - target_under_test = ":child_rust_cc_proto", + target_under_test = ":child_cc_rust_proto", ) def _test_upb_outputs(): rust_upb_proto_library( - name = "child_rust_upb_proto", + name = "child_upb_rust_proto", deps = [":child_proto"], ) rust_outputs_test( name = "rust_upb_outputs_test", - target_under_test = ":child_rust_upb_proto", + target_under_test = ":child_upb_rust_proto", ) def rust_proto_library_unit_test(name):