diff --git a/bazel/upb_c_proto_library.bzl b/bazel/upb_c_proto_library.bzl index b0474b81de..96b4f4f259 100644 --- a/bazel/upb_c_proto_library.bzl +++ b/bazel/upb_c_proto_library.bzl @@ -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", diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 18eaedb038..9140cf9a4c 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -230,7 +230,7 @@ cc_dist_library( ], tags = ["manual"], deps = [ - "//upb_generator:protoc-gen-upb_lib", + "//upb_generator/c:generator_with_main", ], ) diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 9bd4ab155c..703beb90e4 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -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"], -) diff --git a/upb_generator/bootstrap_compiler.bzl b/upb_generator/bootstrap_compiler.bzl index 95fc98e0ea..b26e2d1a54 100644 --- a/upb_generator/bootstrap_compiler.bzl +++ b/upb_generator/bootstrap_compiler.bzl @@ -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] diff --git a/upb_generator/c/BUILD b/upb_generator/c/BUILD new file mode 100644 index 0000000000..057894b52d --- /dev/null +++ b/upb_generator/c/BUILD @@ -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"], +) diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/c/generator.cc similarity index 100% rename from upb_generator/protoc-gen-upb.cc rename to upb_generator/c/generator.cc diff --git a/upb_generator/minitable/BUILD b/upb_generator/minitable/BUILD index f608103ce4..f60b1b1acc 100644 --- a/upb_generator/minitable/BUILD +++ b/upb_generator/minitable/BUILD @@ -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 = [ diff --git a/upb_generator/reflection/BUILD b/upb_generator/reflection/BUILD index 792ca2915d..f432cd4dcd 100644 --- a/upb_generator/reflection/BUILD +++ b/upb_generator/reflection/BUILD @@ -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"],