From b5df030a2d3891c4e5020011ed199ab958ce1cd1 Mon Sep 17 00:00:00 2001 From: Xudong Yang Date: Thu, 4 Nov 2021 15:16:02 +0100 Subject: [PATCH 1/2] Use repo-relative labels wherever possible The label `@com_google_protobuf//:foo` within the protobuf repo is often synonymous with just `//:foo`. We should prefer the latter as it allows us to use a shorter name for the module in the Bazel Central Registry (so just "protobuf" instead of "com_google_protobuf"). Note that the semantics can be subtle: in a macro, plain strings are anchored to the *calling* repo, so if we just use `//:foo` as the default value of a macro argument, it will be resolved to `@myrepo//:foo` if the macro is called from the repo `@myrepo`. In this case, it's necessary to directly call the `Label()` constructor to anchor the string label to the repo where the .bzl file lives. See https://github.com/bazelbuild/bazel-central-registry/pull/28#issuecomment-954741081 for a bit more context. --- protobuf.bzl | 10 +++++----- protobuf_deps.bzl | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/protobuf.bzl b/protobuf.bzl index 971612812157..26b662532790 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -259,9 +259,9 @@ def cc_proto_library( deps = [], cc_libs = [], include = None, - protoc = "@com_google_protobuf//:protoc", + protoc = Label("//:protoc"), use_grpc_plugin = False, - default_runtime = "@com_google_protobuf//:protobuf", + default_runtime = Label("//:protobuf"), **kargs): """Bazel rule to create a C++ protobuf library from proto source files @@ -379,7 +379,7 @@ internal_gen_well_known_protos_java = rule( "_protoc": attr.label( executable = True, cfg = "exec", - default = "@com_google_protobuf//:protoc", + default = "//:protoc", ), }, ) @@ -422,8 +422,8 @@ def py_proto_library( py_libs = [], py_extra_srcs = [], include = None, - default_runtime = "@com_google_protobuf//:protobuf_python", - protoc = "@com_google_protobuf//:protoc", + default_runtime = Label("//:protobuf_python"), + protoc = Label("//:protoc"), use_grpc_plugin = False, **kargs): """Bazel rule to create a Python protobuf library from proto source files diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 32f38ebb6ea0..f2d54590144c 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -29,7 +29,7 @@ def protobuf_deps(): if not native.existing_rule("zlib"): http_archive( name = "zlib", - build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + build_file = "//:third_party/zlib.BUILD", sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff", strip_prefix = "zlib-1.2.11", urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"], From aa33f7bf6a1add7bf18984d6c1e510993f92eba4 Mon Sep 17 00:00:00 2001 From: Xudong Yang Date: Thu, 4 Nov 2021 15:26:01 +0100 Subject: [PATCH 2/2] fix protobuf_deps.bzl --- protobuf_deps.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index f2d54590144c..45e413d94bc6 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -29,7 +29,7 @@ def protobuf_deps(): if not native.existing_rule("zlib"): http_archive( name = "zlib", - build_file = "//:third_party/zlib.BUILD", + build_file = Label("//:third_party/zlib.BUILD"), sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff", strip_prefix = "zlib-1.2.11", urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],