From ebbb2d656f7411497bb640e5e6a75be1d3d55f10 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Thu, 30 Mar 2023 00:38:10 -0700 Subject: [PATCH] Visibility restrict targets generated by rust_proto_library macro PiperOrigin-RevId: 520561115 --- rust/defs.bzl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/rust/defs.bzl b/rust/defs.bzl index 836aa196fe..741255c4d2 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -13,7 +13,7 @@ load( visibility(["//rust/..."]) -def rust_proto_library(name, deps, **args): +def rust_proto_library(name, deps, visibility = [], **args): """Declares all the boilerplate needed to use Rust protobufs conveniently. Hopefully no user will ever need to read this code. @@ -32,14 +32,31 @@ def rust_proto_library(name, deps, **args): "//rust:use_upb_kernel": name + "_upb_kernel", "//conditions:default": name + "_cpp_kernel", }), + visibility = visibility, ) - rust_upb_proto_library(name = name + "_upb_kernel", deps = deps, **args) + rust_upb_proto_library( + name = name + "_upb_kernel", + deps = deps, + visibility = ["//visibility:private"], + **args + ) + # TODO(b/275701445): Stop declaring cc_proto_library once we can use cc_proto_aspect directly. _cc_proto_name = name.removesuffix("_rust_proto") + "_cc_proto" if not native.existing_rule(_cc_proto_name): - cc_proto_library(name = _cc_proto_name, deps = deps, **args) - rust_cc_proto_library(name = name + "_cpp_kernel", deps = [_cc_proto_name], **args) + cc_proto_library( + name = _cc_proto_name, + deps = deps, + visibility = ["//visibility:private"], + **args + ) + rust_cc_proto_library( + name = name + "_cpp_kernel", + deps = [_cc_proto_name], + visibility = ["//visibility:private"], + **args + ) def _rust_proto_library_impl(ctx): deps = ctx.attr.deps