Moved the C code generator to its own directory.

PiperOrigin-RevId: 666928989
pull/17936/head
Joshua Haberman 7 months ago committed by Copybara-Service
parent f6a6b060e2
commit ddb863c38e
  1. 2
      bazel/upb_c_proto_library.bzl
  2. 2
      pkg/BUILD.bazel
  3. 53
      upb_generator/BUILD
  4. 2
      upb_generator/bootstrap_compiler.bzl
  5. 70
      upb_generator/c/BUILD
  6. 0
      upb_generator/c/generator.cc
  7. 6
      upb_generator/minitable/BUILD
  8. 6
      upb_generator/reflection/BUILD

@ -33,7 +33,7 @@ upb_c_proto_library_aspect = aspect(
default = "//upb:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upb_toolchain": attr.label(
default = Label("//upb_generator:protoc-gen-upb_toolchain"),
default = Label("//upb_generator/c:toolchain"),
),
"_cc_toolchain": attr.label(
default = "@bazel_tools//tools/cpp:current_cc_toolchain",

@ -230,7 +230,7 @@ cc_dist_library(
],
tags = ["manual"],
deps = [
"//upb_generator:protoc-gen-upb_lib",
"//upb_generator/c:generator_with_main",
],
)

@ -21,7 +21,6 @@ load(
)
load(
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_binary",
"bootstrap_cc_library",
"bootstrap_upb_proto_library",
)
@ -245,55 +244,3 @@ cc_library(
"//upb:wire",
],
)
bootstrap_cc_binary(
name = "protoc-gen-upb",
bootstrap_deps = [
":protoc-gen-upb_lib",
],
copts = UPB_DEFAULT_CPPOPTS,
visibility = ["//visibility:public"],
)
# 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 = "protoc-gen-upb_lib",
srcs = ["protoc-gen-upb.cc"],
bootstrap_deps = [
":common",
":file_layout",
":names",
":plugin",
":plugin_upb_proto",
"//upb/reflection:descriptor_upb_proto",
"//upb/reflection:reflection",
],
copts = UPB_DEFAULT_CPPOPTS,
visibility = ["//pkg:__pkg__"],
deps = [
"//src/google/protobuf/compiler:code_generator",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire_reader",
"@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 = "protoc-gen-upb_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",
visibility = ["//visibility:public"],
)

@ -44,7 +44,7 @@ def _stage_visibility(stage, visibility):
def _upbc(generator, stage):
if generator == "upb":
return "//upb_generator:protoc-gen-upb" + _stages[stage]
return "//upb_generator/c:protoc-gen-upb" + _stages[stage]
else:
return "//upb_generator/minitable:protoc-gen-upb_minitable" + _stages[stage]

@ -0,0 +1,70 @@
load(
"//upb/bazel:build_defs.bzl",
"UPB_DEFAULT_CPPOPTS",
)
load(
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_binary",
"bootstrap_cc_library",
)
# begin:google_only
# package(default_applicable_licenses = ["//upb:license"])
# end:google_only
licenses(["notice"])
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:names",
"//upb_generator:plugin",
"//upb_generator:plugin_upb_proto",
"//upb/reflection:descriptor_upb_proto",
"//upb/reflection:reflection",
],
copts = UPB_DEFAULT_CPPOPTS,
visibility = ["//pkg:__pkg__"],
deps = [
"//src/google/protobuf/compiler:code_generator",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire_reader",
"@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"],
)

@ -12,6 +12,12 @@ load(
"bootstrap_cc_library",
)
# begin:google_only
# package(default_applicable_licenses = ["//upb:license"])
# end:google_only
licenses(["notice"])
bootstrap_cc_library(
name = "generator",
srcs = [

@ -7,6 +7,12 @@
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
# begin:google_only
# package(default_applicable_licenses = ["//upb:license"])
# end:google_only
licenses(["notice"])
cc_binary(
name = "protoc-gen-upbdefs",
linkopts = ["-lm"],

Loading…
Cancel
Save