Skip to content

Commit fc876e2

Browse files
authored
Merge pull request #25707 from protocolbuffers/tonyliaoss-34.x-rc2-attempt3
To prepare for the 34.0-rc2 release.
2 parents ea5534f + 732ed49 commit fc876e2

File tree

93 files changed

+1332
-859
lines changed

Some content is hidden

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

93 files changed

+1332
-859
lines changed

.github/workflows/test_bazel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# Default flags, uses from-source protoc
3434
- ""
3535
# still uses from-source protoc unless
36-
# --@com_google_protobuf//bazel/toolchains:prefer_prebuilt_protoc is set
36+
# --@com_google_protobuf//bazel/flags:prefer_prebuilt_protoc is set
3737
- "--incompatible_enable_proto_toolchain_resolution=true"
3838
runs-on: ${{ matrix.runner }}-latest
3939
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Examples ${{ matrix.runner }} ${{ matrix.bazelversion }}${{ matrix.bzlmod && ' (bzlmod)' || '' }} ${{ matrix.toolchain_resolution && ' (toolchain resolution)' || '' }}

BUILD.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ alias(
272272
visibility = ["//visibility:public"],
273273
)
274274

275+
alias(
276+
name = "timestamp_upb_reflection_proto",
277+
actual = "//src/google/protobuf:timestamp_upb_reflection_proto",
278+
visibility = ["//visibility:public"],
279+
)
280+
275281
alias(
276282
name = "type_upb_reflection_proto",
277283
actual = "//src/google/protobuf:type_upb_reflection_proto",
@@ -570,7 +576,7 @@ proto_lang_toolchain(
570576
# Set minimal protoc if prefer_prebuilt_protoc.flag_set is true since a prebuilt for protoc_minimal is not available
571577
# TODO: Add a flag to switch between minimal and full protoc with proto_lang_toolchain once we have a minimal protoc binary.
572578
# Setting this attribute to None will make the toolchain to pick the full protoc binary.
573-
"//bazel/toolchains:prefer_prebuilt_protoc.flag_set": None,
579+
"//bazel/flags:prefer_prebuilt_protoc.flag_set": None,
574580
"//conditions:default": "//src/google/protobuf/compiler:protoc_minimal",
575581
}),
576582
runtime = "//src/google/protobuf",
@@ -671,7 +677,6 @@ internal_py_proto_library(
671677
testonly = 1,
672678
srcs = [":generated_protos"],
673679
default_runtime = "",
674-
protoc = ":protoc",
675680
deps = ["//python:python_common_test_protos"],
676681
)
677682

MODULE.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ register_toolchains(
120120
)
121121

122122
# Define toolchains that use pre-built protoc binaries.
123-
prebuilt_protoc = use_extension("//bazel/private:prebuilt_protoc_extension.bzl", "protoc")
123+
prebuilt_protoc = use_extension("//bazel/private/oss/toolchains/prebuilt:protoc_extension.bzl", "protoc")
124124
use_repo(
125125
prebuilt_protoc,
126126
"prebuilt_protoc.linux_aarch_64",
@@ -135,12 +135,12 @@ use_repo(
135135
)
136136

137137
# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
138-
# using --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
139-
register_toolchains("//bazel/private/toolchains/prebuilt:all")
138+
# using --@protobuf//bazel/flags:prefer_prebuilt_protoc
139+
register_toolchains("//bazel/private/oss/toolchains/prebuilt:all")
140140

141141
# From-source protobuf toolchains
142142
# Fallback if nothing is already registered
143-
register_toolchains("//bazel/private/toolchains:all")
143+
register_toolchains("//bazel/private/oss/toolchains:all")
144144

145145
SUPPORTED_PYTHON_VERSIONS = [
146146
"3.10",
Lines changed: 27 additions & 25 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,24 @@ 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",
44+
"//bazel/private/oss:py_proto_library_bzl",
5245
],
5346
)
5447

5548
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",
62-
],
49+
name = "upb_c_proto_library_bzl",
50+
srcs = ["upb_c_proto_library.bzl"],
51+
deprecation = "Use upb/bazel:upb_proto_library_bzl instead",
52+
visibility = ["//visibility:public"],
53+
deps = ["//upb/bazel:upb_proto_library_bzl"],
54+
)
55+
56+
bzl_library(
57+
name = "upb_proto_reflection_library_bzl",
58+
srcs = ["upb_proto_reflection_library.bzl"],
59+
deprecation = "Use upb/bazel:upb_proto_library_bzl instead",
6360
visibility = ["//visibility:public"],
64-
deps = ["//bazel/private:upb_proto_library_internal_bzl"],
61+
deps = ["//upb/bazel:upb_proto_library_bzl"],
6562
)
6663

6764
bzl_library(
@@ -75,13 +72,18 @@ filegroup(
7572
name = "for_bazel_tests",
7673
testonly = True,
7774
srcs = [
78-
"BUILD.bazel",
75+
"BUILD",
7976
":cc_proto_library_bzl",
8077
":java_lite_proto_library_bzl",
8178
":proto_library_bzl",
8279
":py_proto_library_bzl",
80+
":upb_c_proto_library_bzl",
81+
":upb_proto_reflection_library_bzl",
8382
"//bazel/common:for_bazel_tests",
83+
"//bazel/flags:for_bazel_tests",
8484
"//bazel/toolchains:for_bazel_tests",
8585
],
86-
visibility = ["//bazel/private:__pkg__"],
86+
visibility = [
87+
"//bazel/private:__pkg__",
88+
],
8789
)

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

bazel/flags/BUILD

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag", "string_list_flag")
3+
4+
package(
5+
default_applicable_licenses = ["//:license"],
6+
default_visibility = ["//visibility:public"],
7+
)
8+
9+
bzl_library(
10+
name = "flags_bzl",
11+
srcs = ["flags.bzl"],
12+
deps = [
13+
"@bazel_skylib//rules:common_settings",
14+
],
15+
)
16+
17+
filegroup(
18+
name = "for_bazel_tests",
19+
testonly = True,
20+
srcs = [
21+
"BUILD",
22+
"flags.bzl",
23+
"//bazel/flags/cc:BUILD",
24+
"//bazel/flags/java:BUILD",
25+
],
26+
)
27+
28+
bool_flag(
29+
name = "experimental_proto_descriptor_sets_include_source_info",
30+
build_setting_default = False,
31+
scope = "universal",
32+
)
33+
34+
label_flag(
35+
name = "proto_compiler",
36+
build_setting_default = "@bazel_tools//tools/proto:protoc",
37+
)
38+
39+
# When set to true, we will use a prebuilt protoc binary from GitHub if it's available.
40+
bool_flag(
41+
name = "prefer_prebuilt_protoc",
42+
# TODO: this should be True after the feature is vetted with some adoption
43+
build_setting_default = False,
44+
visibility = ["//bazel/toolchains:__pkg__"],
45+
)
46+
47+
config_setting(
48+
name = "prefer_prebuilt_protoc.flag_set",
49+
flag_values = {":prefer_prebuilt_protoc": "true"},
50+
visibility = [
51+
"//bazel/private/oss/toolchains/prebuilt:__pkg__",
52+
# Needed by cc_toolchain to switch between minimal and full protoc
53+
"//:__pkg__",
54+
],
55+
)
56+
57+
# The public API users set to disable the validation action failing.
58+
bool_flag(
59+
name = "allow_nonstandard_protoc",
60+
build_setting_default = False,
61+
)
62+
63+
config_setting(
64+
name = "allow_nonstandard_protoc.flag_set",
65+
flag_values = {":allow_nonstandard_protoc": "true"},
66+
visibility = ["//bazel/private/oss/toolchains/prebuilt:__pkg__"],
67+
)
68+
69+
# TODO: deprecate this flag.
70+
string_flag(
71+
name = "strict_proto_deps",
72+
build_setting_default = "error",
73+
scope = "universal",
74+
values = [
75+
"off",
76+
"OFF",
77+
"warn",
78+
"WARN",
79+
"error",
80+
"ERROR",
81+
"strict",
82+
"STRICT",
83+
"default",
84+
"DEFAULT",
85+
],
86+
)
87+
88+
# TODO: deprecate this flag.
89+
string_flag(
90+
name = "strict_public_imports",
91+
build_setting_default = "off",
92+
scope = "universal",
93+
values = [
94+
"off",
95+
"OFF",
96+
"warn",
97+
"WARN",
98+
"error",
99+
"ERROR",
100+
"strict",
101+
"STRICT",
102+
"default",
103+
"DEFAULT",
104+
],
105+
)

bazel/flags/cc/BUILD

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_list_flag")
2+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
3+
4+
package(
5+
default_applicable_licenses = ["//:license"],
6+
default_visibility = ["//visibility:public"],
7+
)
8+
9+
exports_files(["BUILD"])
10+
11+
label_flag(
12+
name = "proto_toolchain_for_cc",
13+
build_setting_default = "@bazel_tools//tools/proto:cc_toolchain",
14+
)
15+
16+
string_list_flag(
17+
name = "protocopt",
18+
build_setting_default = [],
19+
scope = "universal",
20+
)
21+
22+
string_list_flag(
23+
name = "cc_proto_library_header_suffixes",
24+
build_setting_default = [".pb.h"],
25+
scope = "universal",
26+
)
27+
28+
string_list_flag(
29+
name = "cc_proto_library_source_suffixes",
30+
build_setting_default = [".pb.cc"],
31+
scope = "universal",
32+
)

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

File renamed without changes.

bazel/flags/flags.bzl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""An indirection layer for referencing flags whether they are native or defined in Starlark."""
2+
3+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
4+
5+
visibility([
6+
"//third_party/grpc/bazel",
7+
"//bazel/private/...",
8+
"//bazel/flags",
9+
])
10+
11+
# Maps flag names to their native reference
12+
_FLAGS = {
13+
"protocopt": struct(
14+
native = lambda ctx: getattr(ctx.fragments.proto, "experimental_protoc_opts"),
15+
default = [],
16+
),
17+
"experimental_proto_descriptor_sets_include_source_info": struct(
18+
native = lambda ctx: getattr(ctx.attr, "_experimental_proto_descriptor_sets_include_source_info_native")[BuildSettingInfo].value,
19+
default = False,
20+
),
21+
"proto_compiler": struct(native = lambda ctx: getattr(ctx.attr, "_proto_compiler_native")[BuildSettingInfo].value, default = "@bazel_tools//tools/proto:protoc"),
22+
"strict_proto_deps": struct(
23+
native = lambda ctx: getattr(ctx.attr, "_strict_proto_deps_native")[BuildSettingInfo].value,
24+
default = "error",
25+
),
26+
"strict_public_imports": struct(
27+
native = lambda ctx: getattr(ctx.attr, "_strict_public_imports_native")[BuildSettingInfo].value,
28+
default = "off",
29+
),
30+
"cc_proto_library_header_suffixes": struct(
31+
native = lambda ctx: getattr(ctx.fragments.proto, "cc_proto_library_header_suffixes"),
32+
default = [".pb.h"],
33+
),
34+
"cc_proto_library_source_suffixes": struct(
35+
native = lambda ctx: getattr(ctx.fragments.proto, "cc_proto_library_source_suffixes"),
36+
default = [".pb.cc"],
37+
),
38+
"proto_toolchain_for_java": struct(
39+
native = lambda ctx: getattr(ctx.attr, "_aspect_java_proto_toolchain"),
40+
default = "@bazel_tools//tools/proto:java_toolchain",
41+
),
42+
"proto_toolchain_for_javalite": struct(
43+
native = lambda ctx: getattr(ctx.attr, "_aspect_proto_toolchain_for_javalite"),
44+
default = "@bazel_tools//tools/proto:javalite_toolchain",
45+
),
46+
"proto_toolchain_for_cc": struct(
47+
native = lambda ctx: getattr(ctx.attr, "_aspect_cc_proto_toolchain"),
48+
default = "@bazel_tools//tools/proto:cc_toolchain",
49+
),
50+
}
51+
52+
def get_flag_value(ctx, flag_name):
53+
"""Returns the value of the given flag in Starlark if it's set, otherwise reads the Java flag value.
54+
55+
Args:
56+
ctx: The rule context.
57+
flag_name: The name of the flag to get the value for.
58+
59+
Returns:
60+
The value of the flag.
61+
"""
62+
63+
# We probably got here from toolchains.find_toolchain. Leave the attribute alone.
64+
if flag_name not in _FLAGS:
65+
return getattr(ctx.attr, "_" + flag_name)
66+
67+
# Label flags don't have a BuildSettingInfo, just get the value.
68+
if "toolchain" in flag_name and getattr(ctx.attr, "_" + flag_name).label != _FLAGS[flag_name].default:
69+
return getattr(ctx.attr, "_" + flag_name)
70+
elif getattr(ctx.attr, "_" + flag_name)[BuildSettingInfo].value != _FLAGS[flag_name].default:
71+
return getattr(ctx.attr, "_" + flag_name)[BuildSettingInfo].value
72+
else:
73+
return _FLAGS[flag_name].native(ctx)

0 commit comments

Comments
 (0)