Skip to content

Commit cfbb7ec

Browse files
habermancopybara-github
authored andcommitted
Refactored and rearranged Bazel rules
- OSS-specific code now lives in `bazel/private/oss`. - UPB rules (which are not truly public, as UPB is meant to be a backend to other impls) are moved from `bazel/` -> `upb/bazel/` PiperOrigin-RevId: 843750379
1 parent 272f68a commit cfbb7ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+845
-659
lines changed

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ use_repo(
132132

133133
# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
134134
# using --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
135-
register_toolchains("//bazel/private/toolchains/prebuilt:all")
135+
register_toolchains("//bazel/private/oss/toolchains/prebuilt:all")
136136

137137
# From-source protobuf toolchains
138138
# Fallback if nothing is already registered
139-
register_toolchains("//bazel/private/toolchains:all")
139+
register_toolchains("//bazel/private/oss/toolchains:all")
140140

141141
SUPPORTED_PYTHON_VERSIONS = [
142142
"3.10",
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
1-
# Copyright (c) 2009-2021, Google LLC
2-
# All rights reserved.
3-
#
4-
# Use of this source code is governed by a BSD-style
5-
# license that can be found in the LICENSE file or at
6-
# https://developers.google.com/open-source/licenses/bsd
7-
81
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
92

10-
licenses(["notice"])
3+
package(default_applicable_licenses = ["//:license"])
114

125
bzl_library(
136
name = "proto_library_bzl",
147
srcs = ["proto_library.bzl"],
158
visibility = ["//visibility:public"],
169
deps = [
1710
"//bazel/private:proto_library_rule_bzl",
18-
"@proto_bazel_features//:features",
1911
],
2012
)
2113

2214
bzl_library(
2315
name = "cc_proto_library_bzl",
2416
srcs = ["cc_proto_library.bzl"],
2517
visibility = ["//visibility:public"],
26-
deps = ["//bazel/private:bazel_cc_proto_library_bzl"],
18+
deps = [
19+
"//bazel/private/oss:cc_proto_library_bzl",
20+
],
2721
)
2822

2923
bzl_library(
3024
name = "java_proto_library_bzl",
3125
srcs = ["java_proto_library.bzl"],
3226
visibility = ["//visibility:public"],
33-
deps = ["//bazel/private:bazel_java_proto_library_rule_bzl"],
27+
deps = [
28+
"//bazel/private:java_proto_library_bzl",
29+
],
3430
)
3531

3632
bzl_library(
@@ -45,23 +41,8 @@ bzl_library(
4541
srcs = ["py_proto_library.bzl"],
4642
visibility = ["//visibility:public"],
4743
deps = [
48-
"//bazel/common:proto_common_bzl",
49-
"//bazel/common:proto_info_bzl",
50-
"//bazel/private:toolchain_helpers_bzl",
51-
"@rules_python//python:py_info_bzl",
52-
],
53-
)
54-
55-
bzl_library(
56-
name = "upb_proto_library_bzl",
57-
srcs = [
58-
"upb_c_proto_library.bzl",
59-
"upb_minitable_proto_library.bzl",
60-
"upb_proto_library.bzl",
61-
"upb_proto_reflection_library.bzl",
44+
"//bazel/private/oss:py_proto_library_bzl",
6245
],
63-
visibility = ["//visibility:public"],
64-
deps = ["//bazel/private:upb_proto_library_internal_bzl"],
6546
)
6647

6748
bzl_library(
@@ -75,13 +56,15 @@ filegroup(
7556
name = "for_bazel_tests",
7657
testonly = True,
7758
srcs = [
78-
"BUILD.bazel",
59+
"BUILD",
7960
":cc_proto_library_bzl",
8061
":java_lite_proto_library_bzl",
8162
":proto_library_bzl",
8263
":py_proto_library_bzl",
8364
"//bazel/common:for_bazel_tests",
8465
"//bazel/toolchains:for_bazel_tests",
8566
],
86-
visibility = ["//bazel/private:__pkg__"],
67+
visibility = [
68+
"//bazel/private:__pkg__",
69+
],
8770
)

bazel/cc_proto_library.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# Copyright (c) 2009-2024, Google LLC
2+
# All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style
5+
# license that can be found in the LICENSE file or at
6+
# https://developers.google.com/open-source/licenses/bsd
7+
18
"""cc_proto_library rule"""
29

3-
load("//bazel/private:bazel_cc_proto_library.bzl", _cc_proto_library = "cc_proto_library") # buildifier: disable=bzl-visibility
10+
load("//bazel/private/oss:cc_proto_library.bzl", _cc_proto_library = "cc_proto_library")
411

512
def cc_proto_library(**kwattrs):
613
# Only use Starlark rules when they are removed from Bazel

google3/third_party/protobuf/bazel/flags/BUILD renamed to bazel/flags/BUILD

File renamed without changes.

google3/third_party/protobuf/bazel/flags/cc/BUILD renamed to bazel/flags/cc/BUILD

File renamed without changes.

google3/third_party/protobuf/bazel/flags/cc/empty.sh renamed to bazel/flags/cc/empty.sh

File renamed without changes.

bazel/java_lite_proto_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# Use of this source code is governed by a BSD-style
55
# license that can be found in the LICENSE file or at
66
# https://developers.google.com/open-source/licenses/bsd
7+
78
"""java_lite_proto_library rule"""
89

9-
load("//bazel/private:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library") # buildifier: disable=bzl-visibility
10+
load("//bazel/private:java_lite_proto_library.bzl", _java_lite_proto_library = "java_lite_proto_library")
1011

1112
def java_lite_proto_library(**kwattrs):
1213
# Only use Starlark rules when they are removed from Bazel

bazel/java_proto_library.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# Use of this source code is governed by a BSD-style
55
# license that can be found in the LICENSE file or at
66
# https://developers.google.com/open-source/licenses/bsd
7-
"""java_proto_library rule"""
87

9-
load("//bazel/private:bazel_java_proto_library_rule.bzl", _java_proto_library = "java_proto_library") # buildifier: disable=bzl-visibility
8+
"""java_proto_library rule."""
9+
10+
load("//bazel/private:java_proto_library.bzl", _java_proto_library = "java_proto_library")
1011

1112
def java_proto_library(**kwattrs):
1213
# Only use Starlark rules when they are removed from Bazel

bazel/private/BUILD

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ toolchain_type(
2828
visibility = ["//visibility:public"],
2929
)
3030

31-
bzl_library(
32-
name = "upb_proto_library_internal_bzl",
33-
srcs = [
34-
"upb_proto_library_internal/aspect.bzl",
35-
"upb_proto_library_internal/cc_library_func.bzl",
36-
"upb_proto_library_internal/copts.bzl",
37-
"upb_proto_library_internal/rule.bzl",
38-
],
39-
visibility = ["//bazel:__pkg__"],
40-
deps = [
41-
"//bazel/common:proto_common_bzl",
42-
"@bazel_skylib//lib:paths",
43-
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
44-
],
45-
)
46-
4731
bzl_library(
4832
name = "native_bzl",
4933
srcs = [
@@ -75,9 +59,9 @@ bzl_library(
7559
)
7660

7761
bzl_library(
78-
name = "bazel_java_proto_library_rule_bzl",
62+
name = "java_proto_library_bzl",
7963
srcs = [
80-
"bazel_java_proto_library_rule.bzl",
64+
"java_proto_library.bzl",
8165
"java_proto_support.bzl",
8266
],
8367
visibility = [
@@ -109,18 +93,13 @@ bzl_library(
10993
)
11094

11195
bzl_library(
112-
name = "bazel_cc_proto_library_bzl",
113-
srcs = [
114-
"bazel_cc_proto_library.bzl",
115-
"cc_proto_support.bzl",
116-
],
117-
visibility = ["//bazel:__subpackages__"],
96+
name = "cc_proto_support_bzl",
97+
srcs = ["cc_proto_support.bzl"],
98+
visibility = ["//bazel/private:__subpackages__"],
11899
deps = [
119-
":toolchain_helpers_bzl",
120-
"//bazel/common:proto_common_bzl",
121-
"//bazel/common:proto_info_bzl",
122100
"@proto_bazel_features//:features",
123101
"@rules_cc//cc:find_cc_toolchain_bzl",
102+
"@rules_cc//cc/common",
124103
],
125104
)
126105

@@ -152,11 +131,27 @@ bzl_library(
152131
],
153132
)
154133

134+
bzl_library(
135+
name = "java_proto_aspect_names_bzl",
136+
srcs = ["java_proto_aspect_names.bzl"],
137+
visibility = ["@rules_java//java/google/rules:__pkg__"],
138+
)
139+
155140
bzl_library(
156141
name = "cc_proto_aspect_bzl",
157142
srcs = ["cc_proto_aspect.bzl"],
143+
visibility = [
144+
"//rust/bazel:__pkg__",
145+
],
158146
deps = [
159-
":bazel_cc_proto_library_bzl",
147+
"//bazel/private/oss:cc_proto_library_bzl",
148+
],
149+
)
150+
151+
bzl_library(
152+
name = "cc_proto_aspect_name_bzl",
153+
srcs = ["cc_proto_aspect_name.bzl"],
154+
visibility = [
160155
],
161156
)
162157

@@ -207,9 +202,12 @@ filegroup(
207202
testonly = True,
208203
srcs = [
209204
"BUILD",
205+
":java_proto_library_bzl",
210206
":native_bool_flag_bzl",
207+
":toolchain_helpers_bzl",
211208
"//bazel:for_bazel_tests",
212-
"//bazel/private/toolchains:for_bazel_tests",
209+
"//bazel/private/google:for_bazel_tests",
210+
"//bazel/private/oss/toolchains:for_bazel_tests",
213211
],
214212
visibility = ["//visibility:public"],
215213
)

0 commit comments

Comments
 (0)