Skip to content

Commit 496387e

Browse files
Merge pull request #25196 from protocolbuffers/bazel_binary_fix
Bazel binary fix
2 parents 1042c3c + c9583c0 commit 496387e

File tree

54 files changed

+2209
-78
lines changed

Some content is hidden

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

54 files changed

+2209
-78
lines changed

BUILD.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,13 @@ proto_lang_toolchain(
566566
command_line = "--cpp_out=$(OUT)",
567567
plugin = "//src/google/protobuf/compiler/cpp:protoc-gen-cpp",
568568
plugin_format_flag = "--plugin=protoc-gen-cpp=%s",
569-
protoc_minimal_do_not_use = "//src/google/protobuf/compiler:protoc_minimal",
569+
protoc_minimal_do_not_use = select({
570+
# Set minimal protoc if prefer_prebuilt_protoc.flag_set is true since a prebuilt for protoc_minimal is not available
571+
# TODO: Add a flag to switch between minimal and full protoc with proto_lang_toolchain once we have a minimal protoc binary.
572+
# Setting this attribute to None will make the toolchain to pick the full protoc binary.
573+
"//bazel/toolchains:prefer_prebuilt_protoc.flag_set": None,
574+
"//conditions:default": "//src/google/protobuf/compiler:protoc_minimal",
575+
}),
570576
runtime = "//src/google/protobuf",
571577
visibility = ["//visibility:public"],
572578
)

bazel/tests/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load("//bazel:proto_library.bzl", "proto_library")
13
load(":bazel_proto_library_tests.bzl", "bazel_proto_library_test_suite")
4+
load(":cc_toolchain_tests.bzl", "cc_toolchain_test_suite")
25
load(":java_proto_library_tests.bzl", "java_proto_library_test_suite")
36
load(":proto_common_check_collocated_tests.bzl", "proto_common_check_collocated_test_suite")
47
load(":proto_common_compile_tests.bzl", "proto_common_compile_test_suite")
@@ -17,4 +20,6 @@ proto_common_check_collocated_test_suite(name = "proto_common_check_collocated_t
1720

1821
bazel_proto_library_test_suite(name = "bazel_proto_library_test_suite")
1922

23+
cc_toolchain_test_suite(name = "cc_toolchain_test_suite")
24+
2025
java_proto_library_test_suite(name = "java_proto_library_test_suite")

bazel/tests/cc_toolchain_tests.bzl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Protocol Buffers - Google's data interchange format
2+
# Copyright 2025 Google Inc. 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+
"""Tests for cc_toolchain prebuilt protoc configuration."""
8+
9+
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
10+
load("@rules_testing//lib:truth.bzl", "matching")
11+
load("@rules_testing//lib:util.bzl", "util")
12+
load("//bazel:proto_library.bzl", "proto_library")
13+
load("//bazel/tests/testdata:compile_rule.bzl", "compile_rule")
14+
15+
_PREFER_PREBUILT_PROTOC = str(Label("//bazel/toolchains:prefer_prebuilt_protoc"))
16+
17+
def cc_toolchain_test_suite(name):
18+
test_suite(
19+
name = name,
20+
tests = [
21+
_test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set,
22+
_test_cc_toolchain_uses_protoc_minimal_by_default,
23+
],
24+
)
25+
26+
def _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set(name):
27+
util.helper_target(
28+
proto_library,
29+
name = name + "_proto",
30+
srcs = ["A.proto"],
31+
)
32+
util.helper_target(
33+
compile_rule,
34+
name = name + "_compile",
35+
proto_dep = ":" + name + "_proto",
36+
toolchain = "//:cc_toolchain",
37+
)
38+
39+
analysis_test(
40+
name = name,
41+
target = name + "_compile",
42+
impl = _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set_impl,
43+
config_settings = {_PREFER_PREBUILT_PROTOC: True},
44+
)
45+
46+
def _test_cc_toolchain_uses_full_protoc_when_prefer_prebuilt_flag_set_impl(env, target):
47+
# Find the compile action
48+
action = env.expect.that_target(target).action_named("GenProto")
49+
50+
# When prefer_prebuilt_protoc is True, protoc_minimal_do_not_use is None,
51+
# so the cc_toolchain should use the full protoc (not protoc_minimal).
52+
# The protoc path should end with "/protoc" not contain "protoc_minimal"
53+
action.argv().contains_predicate(matching.str_matches("*/protoc"))
54+
action.argv().not_contains_predicate(matching.str_matches("*protoc_minimal*"))
55+
56+
def _test_cc_toolchain_uses_protoc_minimal_by_default(name):
57+
util.helper_target(
58+
proto_library,
59+
name = name + "_proto",
60+
srcs = ["A.proto"],
61+
)
62+
util.helper_target(
63+
compile_rule,
64+
name = name + "_compile",
65+
proto_dep = ":" + name + "_proto",
66+
toolchain = "//:cc_toolchain",
67+
)
68+
69+
analysis_test(
70+
name = name,
71+
target = name + "_compile",
72+
impl = _test_cc_toolchain_uses_protoc_minimal_by_default_impl,
73+
)
74+
75+
def _test_cc_toolchain_uses_protoc_minimal_by_default_impl(env, target):
76+
# Find the compile action
77+
action = env.expect.that_target(target).action_named("GenProto")
78+
79+
# By default (prefer_prebuilt_protoc is False), protoc_minimal_do_not_use is set,
80+
# so the cc_toolchain should use protoc_minimal.
81+
action.argv().contains_predicate(matching.str_matches("*protoc_minimal*"))

bazel/toolchains/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ bool_flag(
5353
config_setting(
5454
name = "prefer_prebuilt_protoc.flag_set",
5555
flag_values = {":prefer_prebuilt_protoc": "true"},
56-
visibility = ["//bazel/private/toolchains/prebuilt:__pkg__"],
56+
visibility = [
57+
"//bazel/private/toolchains/prebuilt:__pkg__",
58+
# Needed by cc_toolchain to switch between minimal and full protoc
59+
"//:__pkg__",
60+
],
5761
)
5862

5963
# The public API users set to disable the validation action failing.

cmake/conformance.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ add_custom_command(
3838
${protobuf_BINARY_DIR}/conformance/conformance.pb.cc
3939
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h
4040
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc
41+
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition_unstable.pb.h
42+
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition_unstable.pb.cc
4143
DEPENDS ${protobuf_PROTOC_EXE}
4244
${protobuf_SOURCE_DIR}/conformance/conformance.proto
4345
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto
46+
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition_unstable.proto
4447
COMMAND ${protobuf_PROTOC_EXE}
4548
${protobuf_SOURCE_DIR}/conformance/conformance.proto
4649
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto
50+
${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition_unstable.proto
4751
--proto_path=${protobuf_SOURCE_DIR}
4852
--cpp_out=${protobuf_BINARY_DIR}
4953
)
@@ -89,6 +93,8 @@ add_library(libconformance_common STATIC
8993
${protobuf_BINARY_DIR}/conformance/conformance.pb.cc
9094
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h
9195
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc
96+
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition_unstable.pb.h
97+
${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition_unstable.pb.cc
9298
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.h
9399
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.cc
94100
${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.h

conformance/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ cc_library(
139139
"//:test_messages_proto2_cc_proto",
140140
"//:test_messages_proto3_cc_proto",
141141
"//conformance/test_protos:test_messages_edition2023_cc_proto",
142+
"//conformance/test_protos:test_messages_edition_unstable_cc_proto",
142143
"//editions:test_messages_proto2_editions_cc_proto",
143144
"//editions:test_messages_proto3_editions_cc_proto",
144145
"//src/google/protobuf",
@@ -167,6 +168,7 @@ cc_library(
167168
"//:test_messages_proto2_cc_proto",
168169
"//:test_messages_proto3_cc_proto",
169170
"//conformance/test_protos:test_messages_edition2023_cc_proto",
171+
"//conformance/test_protos:test_messages_edition_unstable_cc_proto",
170172
"//editions:test_messages_proto2_editions_cc_proto",
171173
"//editions:test_messages_proto3_editions_cc_proto",
172174
"//src/google/protobuf",
@@ -250,6 +252,7 @@ cc_test(
250252
"//:test_messages_proto2_cc_proto",
251253
"//:test_messages_proto3_cc_proto",
252254
"//conformance/test_protos:test_messages_edition2023_cc_proto",
255+
"//conformance/test_protos:test_messages_edition_unstable_cc_proto",
253256
"//editions:test_messages_proto2_editions_cc_proto",
254257
"//editions:test_messages_proto3_editions_cc_proto",
255258
"@googletest//:gtest",
@@ -449,6 +452,7 @@ cc_binary(
449452
"//:type_cc_proto",
450453
"//:wrappers_cc_proto",
451454
"//conformance/test_protos:test_messages_edition2023_cc_proto",
455+
"//conformance/test_protos:test_messages_edition_unstable_cc_proto",
452456
"//editions:test_messages_proto2_editions_cc_proto",
453457
"//editions:test_messages_proto3_editions_cc_proto",
454458
"//src/google/protobuf",
@@ -481,6 +485,7 @@ java_binary(
481485
"//:test_messages_proto2_java_proto",
482486
"//:test_messages_proto3_java_proto",
483487
"//conformance/test_protos:test_messages_edition2023_java_proto",
488+
"//conformance/test_protos:test_messages_edition_unstable_java_proto",
484489
"//editions:test_messages_proto2_editions_java_proto",
485490
"//editions:test_messages_proto3_editions_java_proto",
486491
],
@@ -501,6 +506,7 @@ java_binary(
501506
"//:test_messages_proto2_java_proto_lite",
502507
"//:test_messages_proto3_java_proto_lite",
503508
"//conformance/test_protos:test_messages_edition2023_java_proto_lite",
509+
"//conformance/test_protos:test_messages_edition_unstable_java_proto_lite",
504510
"//editions:test_messages_proto2_editions_java_proto_lite",
505511
"//editions:test_messages_proto3_editions_java_proto_lite",
506512
],
@@ -520,6 +526,7 @@ py_binary(
520526
":conformance_py_proto",
521527
"//:protobuf_python",
522528
"//conformance/test_protos:test_messages_edition2023_py_pb2",
529+
"//conformance/test_protos:test_messages_edition_unstable_py_pb2",
523530
"//editions:test_messages_proto2_editions_py_pb2",
524531
"//editions:test_messages_proto3_editions_py_pb2",
525532
"//python:_message", # Make upb visible if we need it.
@@ -581,6 +588,7 @@ inline_sh_binary(
581588
visibility = ["//csharp:__subpackages__"],
582589
deps = [
583590
"//conformance/test_protos:test_messages_edition2023_csharp_proto",
591+
"//conformance/test_protos:test_messages_edition_unstable_csharp_proto",
584592
"//csharp/src/Google.Protobuf.Conformance:conformance_runfiles",
585593
],
586594
)
@@ -596,6 +604,7 @@ objc_library(
596604
"//:test_messages_proto2_objc_proto",
597605
"//:test_messages_proto3_objc_proto",
598606
"//conformance/test_protos:test_messages_edition2023_objc_proto",
607+
"//conformance/test_protos:test_messages_edition_unstable_objc_proto",
599608
"//editions:test_messages_proto2_editions_objc_proto",
600609
"//editions:test_messages_proto3_editions_objc_proto",
601610
],
@@ -619,6 +628,7 @@ rb_binary(
619628
deps = [
620629
":conformance_ruby_proto",
621630
"//conformance/test_protos:test_messages_edition2023_ruby_proto",
631+
"//conformance/test_protos:test_messages_edition_unstable_ruby_proto",
622632
"//ruby:conformance_editions_test_ruby_proto",
623633
"//ruby:conformance_test_ruby_proto",
624634
"//ruby:protobuf",

conformance/ConformanceJava.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.google.protobuf.util.JsonFormat.TypeRegistry;
1818
import com.google.protobuf_test_messages.edition2023.TestAllTypesEdition2023;
1919
import com.google.protobuf_test_messages.edition2023.TestMessagesEdition2023;
20+
import com.google.protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable;
21+
import com.google.protobuf_test_messages.edition_unstable.TestMessagesEditionUnstableProto;
2022
import com.google.protobuf_test_messages.editions.proto2.TestMessagesProto2Editions;
2123
import com.google.protobuf_test_messages.editions.proto3.TestMessagesProto3Editions;
2224
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
@@ -217,6 +219,8 @@ private Class<? extends AbstractMessage> createTestMessage(String messageType) {
217219
return TestAllTypesProto2.class;
218220
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
219221
return TestAllTypesEdition2023.class;
222+
case "protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable":
223+
return TestAllTypesEditionUnstable.class;
220224
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
221225
return TestMessagesProto3Editions.TestAllTypesProto3.class;
222226
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
@@ -235,6 +239,8 @@ private Class<?> createTestFile(String messageType) {
235239
return TestMessagesProto2.class;
236240
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
237241
return TestMessagesEdition2023.class;
242+
case "protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable":
243+
return TestMessagesEditionUnstableProto.class;
238244
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
239245
return TestMessagesProto3Editions.class;
240246
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":

conformance/ConformanceJavaLite.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.google.protobuf.conformance.Conformance;
1616
import com.google.protobuf_test_messages.edition2023.TestAllTypesEdition2023;
1717
import com.google.protobuf_test_messages.edition2023.TestMessagesEdition2023;
18+
import com.google.protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable;
19+
import com.google.protobuf_test_messages.edition_unstable.TestMessagesEditionUnstableProto;
1820
import com.google.protobuf_test_messages.editions.proto2.TestMessagesProto2Editions;
1921
import com.google.protobuf_test_messages.editions.proto3.TestMessagesProto3Editions;
2022
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
@@ -216,6 +218,8 @@ private Class<? extends AbstractMessageLite> createTestMessage(String messageTyp
216218
return TestAllTypesProto2.class;
217219
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
218220
return TestAllTypesEdition2023.class;
221+
case "protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable":
222+
return TestAllTypesEditionUnstable.class;
219223
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
220224
return TestMessagesProto3Editions.TestAllTypesProto3.class;
221225
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":
@@ -234,6 +238,8 @@ private Class<?> createTestFile(String messageType) {
234238
return TestMessagesProto2.class;
235239
case "protobuf_test_messages.editions.TestAllTypesEdition2023":
236240
return TestMessagesEdition2023.class;
241+
case "protobuf_test_messages.edition_unstable.TestAllTypesEditionUnstable":
242+
return TestMessagesEditionUnstableProto.class;
237243
case "protobuf_test_messages.editions.proto3.TestAllTypesProto3":
238244
return TestMessagesProto3Editions.class;
239245
case "protobuf_test_messages.editions.proto2.TestAllTypesProto2":

conformance/binary_json_conformance_suite.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "conformance/conformance.pb.h"
3434
#include "conformance_test.h"
3535
#include "conformance/test_protos/test_messages_edition2023.pb.h"
36+
#include "conformance/test_protos/test_messages_edition_unstable.pb.h"
3637
#include "editions/golden/test_messages_proto2_editions.pb.h"
3738
#include "editions/golden/test_messages_proto3_editions.pb.h"
3839
#include "google/protobuf/json/json.h"
@@ -51,6 +52,7 @@ using google::protobuf::Descriptor;
5152
using google::protobuf::FieldDescriptor;
5253
using google::protobuf::internal::WireFormatLite;
5354
using google::protobuf::util::NewTypeResolverForDescriptorPool;
55+
using protobuf_test_messages::edition_unstable::TestAllTypesEditionUnstable;
5456
using protobuf_test_messages::editions::TestAllTypesEdition2023;
5557
using protobuf_test_messages::proto2::TestAllTypesProto2;
5658
using protobuf_test_messages::proto3::TestAllTypesProto3;
@@ -318,6 +320,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
318320
BinaryAndJsonConformanceSuiteImpl<TestAllTypesProto2Editions>(
319321
this, /*run_proto3_tests=*/false);
320322
RunDelimitedFieldTests();
323+
RunUnstableTests();
321324
}
322325
}
323326

@@ -375,6 +378,22 @@ void BinaryAndJsonConformanceSuite::RunDelimitedFieldTests() {
375378
R"pb([protobuf_test_messages.editions.delimited_ext] { c: 99 })pb");
376379
}
377380

381+
void BinaryAndJsonConformanceSuite::RunUnstableTests() {
382+
SetTypeUrl(GetTypeUrl(TestAllTypesEditionUnstable::GetDescriptor()));
383+
384+
RunValidProtobufTest<TestAllTypesEditionUnstable>(
385+
absl::StrCat("ValidInt32"), REQUIRED,
386+
field(1, WireFormatLite::WIRETYPE_VARINT, varint(99)),
387+
R"pb(optional_int32: 99)pb");
388+
389+
RunValidProtobufTest<TestAllTypesEditionUnstable>(
390+
absl::StrCat("ValidMap.Integer"), REQUIRED,
391+
len(8,
392+
absl::StrCat(field(1, WireFormatLite::WIRETYPE_VARINT, varint(99)),
393+
field(2, WireFormatLite::WIRETYPE_VARINT, varint(87)))),
394+
R"pb(map_int32_int32 { key: 99 value: 87 })pb");
395+
}
396+
378397
void BinaryAndJsonConformanceSuite::RunMessageSetTests() {
379398
RunValidBinaryProtobufTest<TestAllTypesProto2>(
380399
absl::StrCat("ValidMessageSetEncoding"), REQUIRED,

conformance/binary_json_conformance_suite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
5757

5858
void RunDelimitedFieldTests();
5959

60+
void RunUnstableTests();
61+
6062
void RunMessageSetTests();
6163

6264
template <typename MessageType>

0 commit comments

Comments
 (0)