Skip to content

Commit

Permalink
Open up visibility for some compiler internals (#10608)
Browse files Browse the repository at this point in the history
* Expose language-specific naming utilities in Bazel for downstream code generators

* Expose language generators without exposing implementation details

* Update cmake configs

* Revert "Expose language generators without exposing implementation details"

This reverts commit b073d9b.

* Give gRPC privileged access to our python generator

* Naming cleanup

* Add linkage for public names.h helpers

* Fixing build/merge issues

* Fix extension docstring
  • Loading branch information
mkruskal-google committed Sep 26, 2022
1 parent d58d471 commit 01fe222
Show file tree
Hide file tree
Showing 32 changed files with 1,255 additions and 801 deletions.
8 changes: 8 additions & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,18 @@ cc_dist_library(
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler:command_line_interface",
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/cpp:names",
"//src/google/protobuf/compiler/cpp:names_internal",
"//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/csharp:names",
"//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:names",
"//src/google/protobuf/compiler/java:names_internal",
"//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/objectivec:names",
"//src/google/protobuf/compiler/objectivec:names_internal",
"//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/php:names",
"//src/google/protobuf/compiler/python",
"//src/google/protobuf/compiler/ruby",
],
Expand Down
9 changes: 7 additions & 2 deletions src/file_lists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ set(libprotoc_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.cc
Expand All @@ -342,24 +343,26 @@ set(libprotoc_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_file.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.cc
Expand Down Expand Up @@ -402,7 +405,6 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_map_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_options.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_reflection_class.h
Expand All @@ -411,6 +413,7 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.h
Expand Down Expand Up @@ -443,6 +446,7 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_extension.h
Expand All @@ -457,6 +461,7 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_options.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.h
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ cc_test(
":command_line_interface",
":mock_code_generator",
"//:protobuf",
"//src/google/protobuf/compiler/cpp:names",
"//src/google/protobuf:cc_test_protos",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "google/protobuf/compiler/command_line_interface.h"
#include "google/protobuf/compiler/mock_code_generator.h"
#include "google/protobuf/compiler/subprocess.h"
#include "google/protobuf/compiler/cpp/names.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/io_win32.h"
#include "google/protobuf/io/printer.h"
Expand Down
38 changes: 34 additions & 4 deletions src/google/protobuf/compiler/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS")

cc_library(
name = "names",
hdrs = ["names.h"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/cpp",
visibility = ["//visibility:public"],
deps = [
":names_internal",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf:protobuf_nowkt",
],
)

cc_library(
name = "names_internal",
hdrs = [
"helpers.h",
"names.h",
"options.h",
],
srcs = [
"helpers.cc",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler/cpp",
visibility = ["//pkg:__pkg__"],
deps = [
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf:protobuf_nowkt",
],
)

cc_library(
name = "cpp",
srcs = [
Expand All @@ -16,7 +48,6 @@ cc_library(
"field.cc",
"file.cc",
"generator.cc",
"helpers.cc",
"map_field.cc",
"message.cc",
"message_field.cc",
Expand All @@ -33,13 +64,10 @@ cc_library(
"field.h",
"file.h",
"generator.h",
"helpers.h",
"map_field.h",
"message.h",
"message_field.h",
"message_layout_helper.h",
"names.h",
"options.h",
"padding_optimizer.h",
"parse_function_generator.h",
"primitive_field.h",
Expand All @@ -53,6 +81,8 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
":names_internal",
":names",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/base:core_headers",
Expand Down
15 changes: 14 additions & 1 deletion src/google/protobuf/compiler/csharp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:cpp_opts.bzl", "COPTS")

cc_library(
name = "names",
hdrs = ["names.h"],
srcs = ["names.cc"],
copts = COPTS,
include_prefix = "google/protobuf/compiler/csharp",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings",
],
)

cc_library(
name = "csharp",
srcs = [
Expand Down Expand Up @@ -36,7 +49,6 @@ cc_library(
"csharp_map_field.h",
"csharp_message.h",
"csharp_message_field.h",
"csharp_names.h",
"csharp_options.h",
"csharp_primitive_field.h",
"csharp_reflection_class.h",
Expand All @@ -56,6 +68,7 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
":names",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/container:flat_hash_set",
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/csharp/csharp_field_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "google/protobuf/descriptor.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/compiler/csharp/names.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/printer.h"
Expand Down
3 changes: 2 additions & 1 deletion src/google/protobuf/compiler/csharp/csharp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/compiler/csharp/csharp_reflection_class.h"
#include "google/protobuf/compiler/csharp/names.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
Expand Down

0 comments on commit 01fe222

Please sign in to comment.