Skip to content

Commit

Permalink
Open-source editions Bazel rules for embedding defaults.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkruskal-google authored and Copybara-Service committed Oct 18, 2023
1 parent 536066e commit 898d8fa
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 55 deletions.
1 change: 0 additions & 1 deletion BUILD.bazel
Expand Up @@ -224,7 +224,6 @@ alias(
cc_library(
name = "protobuf",
copts = COPTS,
include_prefix = "google/protobuf/io",
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [
Expand Down
1 change: 1 addition & 0 deletions cmake/tests.cmake
Expand Up @@ -62,6 +62,7 @@ set(tests_files
${protobuf_test_files}
${compiler_test_files}
${annotation_test_util_srcs}
${editions_test_files}
${io_test_files}
${util_test_files}
${stubs_test_files}
Expand Down
46 changes: 32 additions & 14 deletions src/google/protobuf/BUILD.bazel
Expand Up @@ -162,6 +162,7 @@ cc_library(
copts = COPTS,
includes = ["wkt"],
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = ["//pkg:__pkg__"],
deps = [":protobuf_nowkt"],
)
Expand Down Expand Up @@ -198,7 +199,7 @@ cc_library(
"port_def.inc",
"port_undef.inc",
],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -212,7 +213,7 @@ cc_library(
name = "varint_shuffle",
hdrs = ["varint_shuffle.h"],
copts = COPTS,
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand Down Expand Up @@ -248,7 +249,7 @@ cc_library(
name = "arena_align",
srcs = ["arena_align.cc"],
hdrs = ["arena_align.h"],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -264,7 +265,7 @@ cc_library(
cc_library(
name = "arena_cleanup",
hdrs = ["arena_cleanup.h"],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -278,7 +279,7 @@ cc_library(
cc_library(
name = "arena_allocation_policy",
hdrs = ["arena_allocation_policy.h"],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -291,7 +292,7 @@ cc_library(
cc_library(
name = "string_block",
hdrs = ["string_block.h"],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
deps = [
":arena_align",
"@com_google_absl//absl/base:core_headers",
Expand Down Expand Up @@ -320,7 +321,7 @@ cc_library(
"serial_arena.h",
"thread_safe_arena.h",
],
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -343,7 +344,7 @@ cc_library(
name = "internal_visibility",
hdrs = ["internal_visibility.h"],
copts = COPTS,
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand All @@ -355,7 +356,7 @@ cc_library(
testonly = 1,
hdrs = ["internal_visibility_for_testing.h"],
copts = COPTS,
include_prefix = "google/protobuf",
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"//src/google/protobuf:__subpackages__",
Expand Down Expand Up @@ -419,8 +420,8 @@ cc_library(
"-Wno-error",
],
}),
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
Expand Down Expand Up @@ -506,8 +507,8 @@ cc_library(
"wire_format.h",
],
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
Expand Down Expand Up @@ -549,8 +550,8 @@ cc_test(
cc_library(
name = "protobuf",
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
Expand All @@ -573,14 +574,15 @@ cc_library(
"**/*.h",
"**/*.inc",
]),
strip_include_prefix = "/src",
)

cc_library(
name = "descriptor_legacy",
hdrs = ["descriptor_legacy.h"],
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = ["//:__subpackages__"],
deps = [
":port_def",
Expand All @@ -593,8 +595,8 @@ cc_library(
name = "descriptor_visitor",
hdrs = ["descriptor_visitor.h"],
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = ["//:__subpackages__"],
deps = [
":port_def",
Expand Down Expand Up @@ -749,6 +751,22 @@ proto_library(
],
)

proto_library(
name = "unittest_features_proto",
srcs = ["unittest_features.proto"],
strip_import_prefix = "/src",
visibility = ["//src/google/protobuf:__subpackages__"],
deps = [
":descriptor_proto",
],
)

cc_proto_library(
name = "unittest_features_cc_proto",
visibility = ["//src/google/protobuf:__subpackages__"],
deps = [":unittest_features_proto"],
)

proto_library(
name = "generic_test_protos",
srcs = [":test_proto_srcs"],
Expand Down
28 changes: 23 additions & 5 deletions src/google/protobuf/compiler/BUILD.bazel
Expand Up @@ -42,7 +42,7 @@ cc_library(
"parser.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
Expand All @@ -66,7 +66,7 @@ cc_library(
"scc.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
Expand All @@ -87,7 +87,7 @@ cc_library(
"versions_suffix.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
strip_include_prefix = "/src",
visibility = [
"//src/google/protobuf/compiler:__subpackages__",
],
Expand All @@ -107,7 +107,7 @@ cc_library(
"zip_writer.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
":code_generator",
Expand All @@ -133,6 +133,7 @@ cc_library(
"main.cc",
],
copts = COPTS,
strip_include_prefix = "/src",
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
Expand All @@ -154,6 +155,23 @@ cc_library(
],
)

# This is a build of the protobuf compiler without code generators.
cc_binary(
name = "protoc_minimal",
srcs = [
"main_no_generators.cc",
],
copts = COPTS,
visibility = [
"//src/google/protobuf:__subpackages__",
],
deps = [
":command_line_interface",
"//src/google/protobuf:port_def",
"@com_google_absl//absl/log:initialize",
],
)

# Note: this is an alias for now. In the future, this rule will become the
# cc_binary for protoc, and //:protoc will become an alias.
alias(
Expand Down Expand Up @@ -397,7 +415,7 @@ cc_library(
name = "retention",
srcs = ["retention.cc"],
hdrs = ["retention.h"],
include_prefix = "google/protobuf/compiler",
strip_include_prefix = "/src",
visibility = ["//src/google/protobuf:__subpackages__"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/allowlists/BUILD.bazel
Expand Up @@ -7,7 +7,7 @@ cc_library(
name = "allowlist",
hdrs = ["allowlist.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/allowlists",
strip_include_prefix = "/src",
deps = [
"//src/google/protobuf/stubs",
"@com_google_absl//absl/algorithm:container",
Expand All @@ -28,7 +28,7 @@ cc_library(
],
hdrs = ["allowlists.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/allowlists",
strip_include_prefix = "/src",
visibility = ["//src/google/protobuf:__subpackages__"],
deps = [
":allowlist",
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/cpp/BUILD.bazel
Expand Up @@ -11,7 +11,7 @@ cc_library(
name = "names",
hdrs = ["names.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/cpp",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
":names_internal",
Expand All @@ -32,7 +32,7 @@ cc_library(
"options.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler/cpp",
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler/rust:__subpackages__",
Expand Down Expand Up @@ -79,7 +79,7 @@ cc_library(
"tracker.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler/cpp",
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/csharp/BUILD.bazel
Expand Up @@ -11,7 +11,7 @@ cc_library(
srcs = ["names.cc"],
hdrs = ["names.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/csharp",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
Expand Down Expand Up @@ -62,7 +62,7 @@ cc_library(
"//build_defs:config_msvc": [],
"//conditions:default": ["-Wno-overloaded-virtual"],
}),
include_prefix = "google/protobuf/compiler/csharp",
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
Expand Down
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/java/BUILD.bazel
Expand Up @@ -10,7 +10,7 @@ cc_library(
name = "names",
hdrs = ["names.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/java",
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
":names_internal",
Expand All @@ -33,7 +33,7 @@ cc_library(
"options.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler/java",
strip_include_prefix = "/src",
visibility = ["//pkg:__pkg__"],
deps = [
":java_features_bootstrap",
Expand All @@ -48,7 +48,7 @@ cc_library(
name = "java_features_bootstrap",
srcs = ["java_features.pb.cc"],
hdrs = ["java_features.pb.h"],
include_prefix = "google/protobuf/compiler/java",
strip_include_prefix = "/src",
deps = [
"//src/google/protobuf:arena",
"//src/google/protobuf:protobuf_nowkt",
Expand Down Expand Up @@ -119,7 +119,7 @@ cc_library(
"string_field_lite.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler/java",
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
Expand Down
36 changes: 36 additions & 0 deletions src/google/protobuf/compiler/main_no_generators.cc
@@ -0,0 +1,36 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#include "google/protobuf/compiler/command_line_interface.h"

#include "absl/log/initialize.h"

// Must be included last.
#include "google/protobuf/port_def.inc"

namespace google {
namespace protobuf {
namespace compiler {

// This is a version of protoc that has no built-in code generators.
// See go/protobuf-toolchain-protoc
int ProtocMain(int argc, char* argv[]) {
absl::InitializeLog();

CommandLineInterface cli;
cli.AllowPlugins("protoc-");

return cli.Run(argc, argv);
}

} // namespace compiler
} // namespace protobuf
} // namespace google

int main(int argc, char* argv[]) {
return google::protobuf::compiler::ProtocMain(argc, argv);
}

0 comments on commit 898d8fa

Please sign in to comment.