Created proper `names.h` headers for all upb generators.
The goal of the `names.h` convention is to have a single canonical place where a code generator can define the set of symbols it exports to other code generators, and a canonical place where the name mangling logic is implemented.
Each upb code generator now has its own `names.h` file defining the symbols that it owns & exports:
* `third_party/upb/upb_generator/c/names.h` (for `foo.upb.h` files)
* `third_party/upb/upb_generator/minitable/names.h` (for `foo.upb_minitable.h` files)
* `third_party/upb/upb_generator/reflection/names.h` (for `foo.upbdefs.h` files)
This is a significant improvement over the previous situation where the name mangling functions were co-mingled in `common.h`/`mangle.h`, or sprinkled throughout the generators, with no clear structure for which code generator owns which symbols.
With this structure in place, the visibility lists for the various `names.h` files provide a clear dependency graph for how different generators depend on each other. In general, we want to keep dependencies on the "C" code generator to a minimum, since it is the largest and most complicated of upb's generated APIs, and is also the most prone to symbol name clashes.
Note that upb's `names.h` headers are somewhat unusual, in that we do not want them to depend on C++'s reflection or upb's reflection. Most `names.h` headers in protobuf would use types like `proto2::Descriptor`, but we don't want upb to depend on C++ reflection, especially during its bootstrapping process. We also don't want to force users to build upb defs just to use these name mangling functions. So we use only plain string types like `absl::string_view` and `std::string`.
PiperOrigin-RevId: 672397247
3 months ago
|
|
|
# Copyright (c) 2009-2024, Google LLC
|
|
|
|
# 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
|
|
|
|
|
|
|
|
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
|
|
|
|
load(
|
|
|
|
"//upb/bazel:build_defs.bzl",
|
|
|
|
"UPB_DEFAULT_CPPOPTS",
|
|
|
|
)
|
|
|
|
load(
|
|
|
|
"//upb_generator:bootstrap_compiler.bzl",
|
|
|
|
"bootstrap_cc_binary",
|
|
|
|
"bootstrap_cc_library",
|
|
|
|
)
|
|
|
|
|
|
|
|
package(default_applicable_licenses = ["//:license"])
|
|
|
|
|
|
|
|
licenses(["notice"])
|
|
|
|
|
Created proper `names.h` headers for all upb generators.
The goal of the `names.h` convention is to have a single canonical place where a code generator can define the set of symbols it exports to other code generators, and a canonical place where the name mangling logic is implemented.
Each upb code generator now has its own `names.h` file defining the symbols that it owns & exports:
* `third_party/upb/upb_generator/c/names.h` (for `foo.upb.h` files)
* `third_party/upb/upb_generator/minitable/names.h` (for `foo.upb_minitable.h` files)
* `third_party/upb/upb_generator/reflection/names.h` (for `foo.upbdefs.h` files)
This is a significant improvement over the previous situation where the name mangling functions were co-mingled in `common.h`/`mangle.h`, or sprinkled throughout the generators, with no clear structure for which code generator owns which symbols.
With this structure in place, the visibility lists for the various `names.h` files provide a clear dependency graph for how different generators depend on each other. In general, we want to keep dependencies on the "C" code generator to a minimum, since it is the largest and most complicated of upb's generated APIs, and is also the most prone to symbol name clashes.
Note that upb's `names.h` headers are somewhat unusual, in that we do not want them to depend on C++'s reflection or upb's reflection. Most `names.h` headers in protobuf would use types like `proto2::Descriptor`, but we don't want upb to depend on C++ reflection, especially during its bootstrapping process. We also don't want to force users to build upb defs just to use these name mangling functions. So we use only plain string types like `absl::string_view` and `std::string`.
PiperOrigin-RevId: 672397247
3 months ago
|
|
|
cc_library(
|
|
|
|
name = "names",
|
|
|
|
srcs = ["names.cc"],
|
|
|
|
hdrs = ["names.h"],
|
|
|
|
visibility = ["//src/google/protobuf/compiler/hpb:__pkg__"],
|
|
|
|
deps = [
|
|
|
|
":names_internal",
|
|
|
|
"@com_google_absl//absl/container:flat_hash_map",
|
|
|
|
"@com_google_absl//absl/strings",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_library(
|
|
|
|
name = "names_internal",
|
|
|
|
srcs = ["names_internal.cc"],
|
|
|
|
hdrs = ["names_internal.h"],
|
|
|
|
deps = [
|
|
|
|
"//upb_generator/common:names",
|
|
|
|
"@com_google_absl//absl/strings",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
bootstrap_cc_binary(
|
|
|
|
name = "protoc-gen-upb",
|
|
|
|
bootstrap_deps = [":generator_with_main"],
|
|
|
|
copts = UPB_DEFAULT_CPPOPTS,
|
|
|
|
visibility = [
|
|
|
|
"//editions/codegen_tests:__pkg__",
|
|
|
|
"//net/proto2/contrib/protoc_explorer:__pkg__",
|
|
|
|
"//third_party/prototiller/transformer:__pkg__",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6.
|
|
|
|
# In Bazel 7, our cmake dependency scraping works fine with cc_binary.
|
|
|
|
bootstrap_cc_library(
|
|
|
|
name = "generator_with_main",
|
|
|
|
srcs = ["generator.cc"],
|
|
|
|
bootstrap_deps = [
|
|
|
|
"//upb_generator:common",
|
|
|
|
"//upb_generator:file_layout",
|
|
|
|
"//upb_generator:plugin",
|
|
|
|
"//upb_generator:plugin_upb_proto",
|
|
|
|
"//upb/reflection:descriptor_upb_proto",
|
|
|
|
"//upb/reflection:reflection",
|
|
|
|
],
|
|
|
|
copts = UPB_DEFAULT_CPPOPTS,
|
|
|
|
visibility = ["//pkg:__pkg__"],
|
|
|
|
deps = [
|
Created proper `names.h` headers for all upb generators.
The goal of the `names.h` convention is to have a single canonical place where a code generator can define the set of symbols it exports to other code generators, and a canonical place where the name mangling logic is implemented.
Each upb code generator now has its own `names.h` file defining the symbols that it owns & exports:
* `third_party/upb/upb_generator/c/names.h` (for `foo.upb.h` files)
* `third_party/upb/upb_generator/minitable/names.h` (for `foo.upb_minitable.h` files)
* `third_party/upb/upb_generator/reflection/names.h` (for `foo.upbdefs.h` files)
This is a significant improvement over the previous situation where the name mangling functions were co-mingled in `common.h`/`mangle.h`, or sprinkled throughout the generators, with no clear structure for which code generator owns which symbols.
With this structure in place, the visibility lists for the various `names.h` files provide a clear dependency graph for how different generators depend on each other. In general, we want to keep dependencies on the "C" code generator to a minimum, since it is the largest and most complicated of upb's generated APIs, and is also the most prone to symbol name clashes.
Note that upb's `names.h` headers are somewhat unusual, in that we do not want them to depend on C++'s reflection or upb's reflection. Most `names.h` headers in protobuf would use types like `proto2::Descriptor`, but we don't want upb to depend on C++ reflection, especially during its bootstrapping process. We also don't want to force users to build upb defs just to use these name mangling functions. So we use only plain string types like `absl::string_view` and `std::string`.
PiperOrigin-RevId: 672397247
3 months ago
|
|
|
":names",
|
|
|
|
":names_internal",
|
|
|
|
"//upb:base",
|
|
|
|
"//upb:mem",
|
|
|
|
"//upb:mini_table",
|
|
|
|
"//upb:port",
|
|
|
|
"//upb:wire_reader",
|
Created proper `names.h` headers for all upb generators.
The goal of the `names.h` convention is to have a single canonical place where a code generator can define the set of symbols it exports to other code generators, and a canonical place where the name mangling logic is implemented.
Each upb code generator now has its own `names.h` file defining the symbols that it owns & exports:
* `third_party/upb/upb_generator/c/names.h` (for `foo.upb.h` files)
* `third_party/upb/upb_generator/minitable/names.h` (for `foo.upb_minitable.h` files)
* `third_party/upb/upb_generator/reflection/names.h` (for `foo.upbdefs.h` files)
This is a significant improvement over the previous situation where the name mangling functions were co-mingled in `common.h`/`mangle.h`, or sprinkled throughout the generators, with no clear structure for which code generator owns which symbols.
With this structure in place, the visibility lists for the various `names.h` files provide a clear dependency graph for how different generators depend on each other. In general, we want to keep dependencies on the "C" code generator to a minimum, since it is the largest and most complicated of upb's generated APIs, and is also the most prone to symbol name clashes.
Note that upb's `names.h` headers are somewhat unusual, in that we do not want them to depend on C++'s reflection or upb's reflection. Most `names.h` headers in protobuf would use types like `proto2::Descriptor`, but we don't want upb to depend on C++ reflection, especially during its bootstrapping process. We also don't want to force users to build upb defs just to use these name mangling functions. So we use only plain string types like `absl::string_view` and `std::string`.
PiperOrigin-RevId: 672397247
3 months ago
|
|
|
"//upb_generator/common:names",
|
|
|
|
"//upb_generator/minitable:names",
|
|
|
|
"//upb_generator/minitable:names_internal",
|
|
|
|
"@com_google_absl//absl/base:core_headers",
|
|
|
|
"@com_google_absl//absl/container:flat_hash_map",
|
|
|
|
"@com_google_absl//absl/container:flat_hash_set",
|
|
|
|
"@com_google_absl//absl/log:absl_check",
|
|
|
|
"@com_google_absl//absl/log:absl_log",
|
|
|
|
"@com_google_absl//absl/strings",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
proto_lang_toolchain(
|
|
|
|
name = "toolchain",
|
|
|
|
command_line = "--upb_out=$(OUT)",
|
|
|
|
output_files = "multiple",
|
|
|
|
plugin = ":protoc-gen-upb_stage1",
|
|
|
|
plugin_format_flag = "--plugin=protoc-gen-upb=%s",
|
|
|
|
progress_message = "Generating upb protos",
|
|
|
|
runtime = "//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
|
|
|
|
# TODO: Restrict to "//bazel:__pkg__" once we are on Bazel >=6.5.
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|