Skip to content

Commit 4b1c73e

Browse files
comiuscopybara-github
authored andcommitted
Remove dependency on protobuf
Copybara Import from #449 BEGIN_PUBLIC Remove dependency on protobuf (#449) This is a new attempt, which is slightly softer than before. It only fails on Bazel8 and later, because it uses native cc_proto_library, so that it doesn't need to depend on the protobuf repository. Closes #449 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=#449 from comius:cc-proto-library-removal-2 655d095 PiperOrigin-RevId: 791120562 Change-Id: I94e82caf10d08283d4730982b2959058bed4da2d
1 parent 31ba5f6 commit 4b1c73e

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module(
77
bazel_dep(name = "bazel_features", version = "1.28.0")
88
bazel_dep(name = "bazel_skylib", version = "1.7.1")
99
bazel_dep(name = "platforms", version = "0.0.10")
10-
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
1110

1211
cc_configure = use_extension("//cc:extensions.bzl", "cc_configure_extension")
1312
use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains")

WORKSPACE

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ http_archive(
4444
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
4545
)
4646

47-
http_archive(
48-
name = "com_google_protobuf",
49-
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
50-
strip_prefix = "protobuf-27.0",
51-
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
52-
)
53-
5447
http_archive(
5548
name = "googletest",
5649
integrity = "sha256-e0K01u1IgQxTYsJloX+uvpDcI3PIheUhZDnTeSfwKSY=",

cc/defs.bzl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
"""Starlark rules for building C++ projects."""
1515

16-
load("@com_google_protobuf//bazel:cc_proto_library.bzl", _cc_proto_library = "cc_proto_library")
1716
load("//cc:cc_binary.bzl", _cc_binary = "cc_binary")
1817
load("//cc:cc_import.bzl", _cc_import = "cc_import")
1918
load("//cc:cc_library.bzl", _cc_library = "cc_library")
@@ -24,6 +23,7 @@ load("//cc:objc_library.bzl", _objc_library = "objc_library")
2423
load("//cc/common:cc_common.bzl", _cc_common = "cc_common")
2524
load("//cc/common:cc_info.bzl", _CcInfo = "CcInfo")
2625
load("//cc/common:debug_package_info.bzl", _DebugPackageInfo = "DebugPackageInfo")
26+
load("//cc/private/rules_impl:failing_cc_proto_library.bzl", "CC_PROTO_LIBRARY_DEPRECATION", _cc_proto_library = "cc_proto_library")
2727
load("//cc/toolchains:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier")
2828
load("//cc/toolchains:cc_toolchain.bzl", _cc_toolchain = "cc_toolchain")
2929
load("//cc/toolchains:cc_toolchain_config_info.bzl", _CcToolchainConfigInfo = "CcToolchainConfigInfo")
@@ -45,10 +45,22 @@ objc_import = _objc_import
4545

4646
# DEPRECATED: use rule from com_google_protobuf repository
4747
def cc_proto_library(**kwargs):
48+
"""Deprecated redirection macro for cc_proto_library.
49+
50+
Use cc_proto_library from com_google_protobuf.
51+
52+
On Bazel <8, redirects to native.cc_proto_library.
53+
On Bazel >=8, redirects to a mock rule, that fails when analyzed.
54+
This allows for a gradual migration away from this macro.
55+
56+
Args:
57+
**kwargs: passed directly into cc_proto_library
58+
"""
59+
__cc_proto_library = getattr(native, "cc_proto_library", _cc_proto_library)
4860
if "deprecation" not in kwargs:
49-
_cc_proto_library(deprecation = "Use cc_proto_library from com_google_protobuf", **kwargs)
61+
__cc_proto_library(deprecation = CC_PROTO_LIBRARY_DEPRECATION, **kwargs)
5062
else:
51-
_cc_proto_library(**kwargs)
63+
__cc_proto_library(**kwargs)
5264

5365
# Toolchain rules
5466

cc/private/rules_impl/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ bzl_library(
3535
"cc_shared_library.bzl",
3636
"cc_static_library.bzl",
3737
"cc_test.bzl",
38+
"failing_cc_proto_library.bzl",
3839
"objc_import.bzl",
3940
"objc_library.bzl",
4041
],
4142
visibility = ["//cc:__subpackages__"],
43+
deps = ["//cc/common"],
4244
)
4345

4446
bzl_library(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2025 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""A failing cc_proto_library rule."""
15+
16+
load("//cc/common:cc_info.bzl", "CcInfo")
17+
18+
CC_PROTO_LIBRARY_DEPRECATION = (
19+
"cc_proto_library is removed from @rules_cc//cc:defs.bzl in Bazel 8. " +
20+
"Please load the implementation from https://github.com/protocolbuffers/protobuf. " +
21+
"After adding the dependency to WORKSPACE or MODULE.bazel use the load statement: " +
22+
'`load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")`'
23+
)
24+
25+
def _impl(_ctx):
26+
fail(CC_PROTO_LIBRARY_DEPRECATION)
27+
28+
cc_proto_library = rule(
29+
implementation = _impl,
30+
provides = [CcInfo],
31+
doc = "Do not use. The rule always fails",
32+
attrs = {
33+
"deps": attr.label_list(),
34+
},
35+
)

cc/private/rules_impl/native.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
#
1515
# Redefine native symbols with a new name as a workaround for
16-
# exporting them in `//third_party/bazel_rules/rules_proto/proto:defs.bzl` with their original name.
16+
# exporting them in `@rules_cc//cc:defs.bzl` with their original name.
1717
#
1818
# While we cannot force users to load these symbol due to the lack of a
1919
# allowlisting mechanism, we can still export them and tell users to

0 commit comments

Comments
 (0)