Skip to content

Commit 898d8fa

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Open-source editions Bazel rules for embedding defaults.
These utilities provide a way to embed a FeatureSetDefaults message into generators or runtimes that need to implement feature resolution. They use protoc to handle the tricky reflection-based algorithm over feature protos, leaving only simple merges to be implemented in other languages. See docs/design/editions/editions-life-of-a-featureset.md for more information. PiperOrigin-RevId: 574554333
1 parent 536066e commit 898d8fa

21 files changed

Lines changed: 503 additions & 55 deletions

File tree

BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ alias(
224224
cc_library(
225225
name = "protobuf",
226226
copts = COPTS,
227-
include_prefix = "google/protobuf/io",
228227
linkopts = LINK_OPTS,
229228
visibility = ["//visibility:public"],
230229
deps = [

cmake/tests.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(tests_files
6262
${protobuf_test_files}
6363
${compiler_test_files}
6464
${annotation_test_util_srcs}
65+
${editions_test_files}
6566
${io_test_files}
6667
${util_test_files}
6768
${stubs_test_files}

src/google/protobuf/BUILD.bazel

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ cc_library(
162162
copts = COPTS,
163163
includes = ["wkt"],
164164
linkopts = LINK_OPTS,
165+
strip_include_prefix = "/src",
165166
visibility = ["//pkg:__pkg__"],
166167
deps = [":protobuf_nowkt"],
167168
)
@@ -198,7 +199,7 @@ cc_library(
198199
"port_def.inc",
199200
"port_undef.inc",
200201
],
201-
include_prefix = "google/protobuf",
202+
strip_include_prefix = "/src",
202203
visibility = [
203204
"//:__subpackages__",
204205
"//src/google/protobuf:__subpackages__",
@@ -212,7 +213,7 @@ cc_library(
212213
name = "varint_shuffle",
213214
hdrs = ["varint_shuffle.h"],
214215
copts = COPTS,
215-
include_prefix = "google/protobuf",
216+
strip_include_prefix = "/src",
216217
visibility = [
217218
"//:__subpackages__",
218219
"//src/google/protobuf:__subpackages__",
@@ -248,7 +249,7 @@ cc_library(
248249
name = "arena_align",
249250
srcs = ["arena_align.cc"],
250251
hdrs = ["arena_align.h"],
251-
include_prefix = "google/protobuf",
252+
strip_include_prefix = "/src",
252253
visibility = [
253254
"//:__subpackages__",
254255
"//src/google/protobuf:__subpackages__",
@@ -264,7 +265,7 @@ cc_library(
264265
cc_library(
265266
name = "arena_cleanup",
266267
hdrs = ["arena_cleanup.h"],
267-
include_prefix = "google/protobuf",
268+
strip_include_prefix = "/src",
268269
visibility = [
269270
"//:__subpackages__",
270271
"//src/google/protobuf:__subpackages__",
@@ -278,7 +279,7 @@ cc_library(
278279
cc_library(
279280
name = "arena_allocation_policy",
280281
hdrs = ["arena_allocation_policy.h"],
281-
include_prefix = "google/protobuf",
282+
strip_include_prefix = "/src",
282283
visibility = [
283284
"//:__subpackages__",
284285
"//src/google/protobuf:__subpackages__",
@@ -291,7 +292,7 @@ cc_library(
291292
cc_library(
292293
name = "string_block",
293294
hdrs = ["string_block.h"],
294-
include_prefix = "google/protobuf",
295+
strip_include_prefix = "/src",
295296
deps = [
296297
":arena_align",
297298
"@com_google_absl//absl/base:core_headers",
@@ -320,7 +321,7 @@ cc_library(
320321
"serial_arena.h",
321322
"thread_safe_arena.h",
322323
],
323-
include_prefix = "google/protobuf",
324+
strip_include_prefix = "/src",
324325
visibility = [
325326
"//:__subpackages__",
326327
"//src/google/protobuf:__subpackages__",
@@ -343,7 +344,7 @@ cc_library(
343344
name = "internal_visibility",
344345
hdrs = ["internal_visibility.h"],
345346
copts = COPTS,
346-
include_prefix = "google/protobuf",
347+
strip_include_prefix = "/src",
347348
visibility = [
348349
"//:__subpackages__",
349350
"//src/google/protobuf:__subpackages__",
@@ -355,7 +356,7 @@ cc_library(
355356
testonly = 1,
356357
hdrs = ["internal_visibility_for_testing.h"],
357358
copts = COPTS,
358-
include_prefix = "google/protobuf",
359+
strip_include_prefix = "/src",
359360
visibility = [
360361
"//:__subpackages__",
361362
"//src/google/protobuf:__subpackages__",
@@ -419,8 +420,8 @@ cc_library(
419420
"-Wno-error",
420421
],
421422
}),
422-
include_prefix = "google/protobuf",
423423
linkopts = LINK_OPTS,
424+
strip_include_prefix = "/src",
424425
visibility = [
425426
"//:__pkg__",
426427
"//pkg:__pkg__",
@@ -506,8 +507,8 @@ cc_library(
506507
"wire_format.h",
507508
],
508509
copts = COPTS,
509-
include_prefix = "google/protobuf",
510510
linkopts = LINK_OPTS,
511+
strip_include_prefix = "/src",
511512
visibility = [
512513
"//:__pkg__",
513514
"//pkg:__pkg__",
@@ -549,8 +550,8 @@ cc_test(
549550
cc_library(
550551
name = "protobuf",
551552
copts = COPTS,
552-
include_prefix = "google/protobuf",
553553
linkopts = LINK_OPTS,
554+
strip_include_prefix = "/src",
554555
visibility = [
555556
"//:__pkg__",
556557
"//pkg:__pkg__",
@@ -573,14 +574,15 @@ cc_library(
573574
"**/*.h",
574575
"**/*.inc",
575576
]),
577+
strip_include_prefix = "/src",
576578
)
577579

578580
cc_library(
579581
name = "descriptor_legacy",
580582
hdrs = ["descriptor_legacy.h"],
581583
copts = COPTS,
582-
include_prefix = "google/protobuf",
583584
linkopts = LINK_OPTS,
585+
strip_include_prefix = "/src",
584586
visibility = ["//:__subpackages__"],
585587
deps = [
586588
":port_def",
@@ -593,8 +595,8 @@ cc_library(
593595
name = "descriptor_visitor",
594596
hdrs = ["descriptor_visitor.h"],
595597
copts = COPTS,
596-
include_prefix = "google/protobuf",
597598
linkopts = LINK_OPTS,
599+
strip_include_prefix = "/src",
598600
visibility = ["//:__subpackages__"],
599601
deps = [
600602
":port_def",
@@ -749,6 +751,22 @@ proto_library(
749751
],
750752
)
751753

754+
proto_library(
755+
name = "unittest_features_proto",
756+
srcs = ["unittest_features.proto"],
757+
strip_import_prefix = "/src",
758+
visibility = ["//src/google/protobuf:__subpackages__"],
759+
deps = [
760+
":descriptor_proto",
761+
],
762+
)
763+
764+
cc_proto_library(
765+
name = "unittest_features_cc_proto",
766+
visibility = ["//src/google/protobuf:__subpackages__"],
767+
deps = [":unittest_features_proto"],
768+
)
769+
752770
proto_library(
753771
name = "generic_test_protos",
754772
srcs = [":test_proto_srcs"],

src/google/protobuf/compiler/BUILD.bazel

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ cc_library(
4242
"parser.h",
4343
],
4444
copts = COPTS,
45-
include_prefix = "google/protobuf/compiler",
45+
strip_include_prefix = "/src",
4646
visibility = ["//visibility:public"],
4747
deps = [
4848
"//src/google/protobuf:protobuf_nowkt",
@@ -66,7 +66,7 @@ cc_library(
6666
"scc.h",
6767
],
6868
copts = COPTS,
69-
include_prefix = "google/protobuf/compiler",
69+
strip_include_prefix = "/src",
7070
visibility = ["//visibility:public"],
7171
deps = [
7272
"//src/google/protobuf:protobuf_nowkt",
@@ -87,7 +87,7 @@ cc_library(
8787
"versions_suffix.h",
8888
],
8989
copts = COPTS,
90-
include_prefix = "google/protobuf/compiler",
90+
strip_include_prefix = "/src",
9191
visibility = [
9292
"//src/google/protobuf/compiler:__subpackages__",
9393
],
@@ -107,7 +107,7 @@ cc_library(
107107
"zip_writer.h",
108108
],
109109
copts = COPTS,
110-
include_prefix = "google/protobuf/compiler",
110+
strip_include_prefix = "/src",
111111
visibility = ["//visibility:public"],
112112
deps = [
113113
":code_generator",
@@ -133,6 +133,7 @@ cc_library(
133133
"main.cc",
134134
],
135135
copts = COPTS,
136+
strip_include_prefix = "/src",
136137
visibility = [
137138
"//:__pkg__",
138139
"//pkg:__pkg__",
@@ -154,6 +155,23 @@ cc_library(
154155
],
155156
)
156157

158+
# This is a build of the protobuf compiler without code generators.
159+
cc_binary(
160+
name = "protoc_minimal",
161+
srcs = [
162+
"main_no_generators.cc",
163+
],
164+
copts = COPTS,
165+
visibility = [
166+
"//src/google/protobuf:__subpackages__",
167+
],
168+
deps = [
169+
":command_line_interface",
170+
"//src/google/protobuf:port_def",
171+
"@com_google_absl//absl/log:initialize",
172+
],
173+
)
174+
157175
# Note: this is an alias for now. In the future, this rule will become the
158176
# cc_binary for protoc, and //:protoc will become an alias.
159177
alias(
@@ -397,7 +415,7 @@ cc_library(
397415
name = "retention",
398416
srcs = ["retention.cc"],
399417
hdrs = ["retention.h"],
400-
include_prefix = "google/protobuf/compiler",
418+
strip_include_prefix = "/src",
401419
visibility = ["//src/google/protobuf:__subpackages__"],
402420
deps = [
403421
"//src/google/protobuf:protobuf_nowkt",

src/google/protobuf/compiler/allowlists/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cc_library(
77
name = "allowlist",
88
hdrs = ["allowlist.h"],
99
copts = COPTS,
10-
include_prefix = "google/protobuf/compiler/allowlists",
10+
strip_include_prefix = "/src",
1111
deps = [
1212
"//src/google/protobuf/stubs",
1313
"@com_google_absl//absl/algorithm:container",
@@ -28,7 +28,7 @@ cc_library(
2828
],
2929
hdrs = ["allowlists.h"],
3030
copts = COPTS,
31-
include_prefix = "google/protobuf/compiler/allowlists",
31+
strip_include_prefix = "/src",
3232
visibility = ["//src/google/protobuf:__subpackages__"],
3333
deps = [
3434
":allowlist",

src/google/protobuf/compiler/cpp/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cc_library(
1111
name = "names",
1212
hdrs = ["names.h"],
1313
copts = COPTS,
14-
include_prefix = "google/protobuf/compiler/cpp",
14+
strip_include_prefix = "/src",
1515
visibility = ["//visibility:public"],
1616
deps = [
1717
":names_internal",
@@ -32,7 +32,7 @@ cc_library(
3232
"options.h",
3333
],
3434
copts = COPTS,
35-
include_prefix = "google/protobuf/compiler/cpp",
35+
strip_include_prefix = "/src",
3636
visibility = [
3737
"//pkg:__pkg__",
3838
"//src/google/protobuf/compiler/rust:__subpackages__",
@@ -79,7 +79,7 @@ cc_library(
7979
"tracker.h",
8080
],
8181
copts = COPTS,
82-
include_prefix = "google/protobuf/compiler/cpp",
82+
strip_include_prefix = "/src",
8383
visibility = [
8484
"//pkg:__pkg__",
8585
"//src/google/protobuf/compiler:__pkg__",

src/google/protobuf/compiler/csharp/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cc_library(
1111
srcs = ["names.cc"],
1212
hdrs = ["names.h"],
1313
copts = COPTS,
14-
include_prefix = "google/protobuf/compiler/csharp",
14+
strip_include_prefix = "/src",
1515
visibility = ["//visibility:public"],
1616
deps = [
1717
"//src/google/protobuf:protobuf_nowkt",
@@ -62,7 +62,7 @@ cc_library(
6262
"//build_defs:config_msvc": [],
6363
"//conditions:default": ["-Wno-overloaded-virtual"],
6464
}),
65-
include_prefix = "google/protobuf/compiler/csharp",
65+
strip_include_prefix = "/src",
6666
visibility = [
6767
"//pkg:__pkg__",
6868
"//src/google/protobuf/compiler:__pkg__",

src/google/protobuf/compiler/java/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cc_library(
1010
name = "names",
1111
hdrs = ["names.h"],
1212
copts = COPTS,
13-
include_prefix = "google/protobuf/compiler/java",
13+
strip_include_prefix = "/src",
1414
visibility = ["//visibility:public"],
1515
deps = [
1616
":names_internal",
@@ -33,7 +33,7 @@ cc_library(
3333
"options.h",
3434
],
3535
copts = COPTS,
36-
include_prefix = "google/protobuf/compiler/java",
36+
strip_include_prefix = "/src",
3737
visibility = ["//pkg:__pkg__"],
3838
deps = [
3939
":java_features_bootstrap",
@@ -48,7 +48,7 @@ cc_library(
4848
name = "java_features_bootstrap",
4949
srcs = ["java_features.pb.cc"],
5050
hdrs = ["java_features.pb.h"],
51-
include_prefix = "google/protobuf/compiler/java",
51+
strip_include_prefix = "/src",
5252
deps = [
5353
"//src/google/protobuf:arena",
5454
"//src/google/protobuf:protobuf_nowkt",
@@ -119,7 +119,7 @@ cc_library(
119119
"string_field_lite.h",
120120
],
121121
copts = COPTS,
122-
include_prefix = "google/protobuf/compiler/java",
122+
strip_include_prefix = "/src",
123123
visibility = [
124124
"//pkg:__pkg__",
125125
"//src/google/protobuf/compiler:__pkg__",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Protocol Buffers - Google's data interchange format
2+
// Copyright 2008 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+
8+
#include "google/protobuf/compiler/command_line_interface.h"
9+
10+
#include "absl/log/initialize.h"
11+
12+
// Must be included last.
13+
#include "google/protobuf/port_def.inc"
14+
15+
namespace google {
16+
namespace protobuf {
17+
namespace compiler {
18+
19+
// This is a version of protoc that has no built-in code generators.
20+
// See go/protobuf-toolchain-protoc
21+
int ProtocMain(int argc, char* argv[]) {
22+
absl::InitializeLog();
23+
24+
CommandLineInterface cli;
25+
cli.AllowPlugins("protoc-");
26+
27+
return cli.Run(argc, argv);
28+
}
29+
30+
} // namespace compiler
31+
} // namespace protobuf
32+
} // namespace google
33+
34+
int main(int argc, char* argv[]) {
35+
return google::protobuf::compiler::ProtocMain(argc, argv);
36+
}

0 commit comments

Comments
 (0)