1# Copyright (c) 2009-2024, Google LLC 2# All rights reserved. 3# 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file or at 6# https://developers.google.com/open-source/licenses/bsd 7 8load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain") 9load( 10 "//upb/bazel:build_defs.bzl", 11 "UPB_DEFAULT_CPPOPTS", 12) 13load( 14 "//upb_generator:bootstrap_compiler.bzl", 15 "bootstrap_cc_binary", 16 "bootstrap_cc_library", 17) 18 19package(default_applicable_licenses = ["//:license"]) 20 21licenses(["notice"]) 22 23cc_library( 24 name = "names", 25 srcs = ["names.cc"], 26 hdrs = ["names.h"], 27 visibility = ["//src/google/protobuf/compiler/hpb:__pkg__"], 28 deps = [ 29 ":names_internal", 30 "@com_google_absl//absl/container:flat_hash_map", 31 "@com_google_absl//absl/strings", 32 ], 33) 34 35cc_library( 36 name = "names_internal", 37 srcs = ["names_internal.cc"], 38 hdrs = ["names_internal.h"], 39 deps = [ 40 "//upb_generator/common:names", 41 "@com_google_absl//absl/strings", 42 ], 43) 44 45bootstrap_cc_binary( 46 name = "protoc-gen-upb", 47 bootstrap_deps = [":generator_with_main"], 48 copts = UPB_DEFAULT_CPPOPTS, 49 visibility = [ 50 "//editions/codegen_tests:__pkg__", 51 "//net/proto2/contrib/protoc_explorer:__pkg__", 52 "//third_party/prototiller/transformer:__pkg__", 53 ], 54) 55 56# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6. 57# In Bazel 7, our cmake dependency scraping works fine with cc_binary. 58bootstrap_cc_library( 59 name = "generator_with_main", 60 srcs = ["generator.cc"], 61 bootstrap_deps = [ 62 "//upb_generator:common", 63 "//upb_generator:file_layout", 64 "//upb_generator:plugin", 65 "//upb_generator:plugin_upb_proto", 66 "//upb/reflection:descriptor_upb_proto", 67 "//upb/reflection:reflection", 68 ], 69 copts = UPB_DEFAULT_CPPOPTS, 70 visibility = ["//pkg:__pkg__"], 71 deps = [ 72 ":names", 73 ":names_internal", 74 "//upb:base", 75 "//upb:mem", 76 "//upb:mini_table", 77 "//upb:port", 78 "//upb:wire_reader", 79 "//upb_generator/common:names", 80 "//upb_generator/minitable:names", 81 "//upb_generator/minitable:names_internal", 82 "@com_google_absl//absl/base:core_headers", 83 "@com_google_absl//absl/container:flat_hash_map", 84 "@com_google_absl//absl/container:flat_hash_set", 85 "@com_google_absl//absl/log:absl_check", 86 "@com_google_absl//absl/log:absl_log", 87 "@com_google_absl//absl/strings", 88 ], 89) 90 91proto_lang_toolchain( 92 name = "toolchain", 93 command_line = "--upb_out=$(OUT)", 94 output_files = "multiple", 95 plugin = ":protoc-gen-upb_stage1", 96 plugin_format_flag = "--plugin=protoc-gen-upb=%s", 97 progress_message = "Generating upb protos", 98 runtime = "//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", 99 # TODO: Restrict to "//bazel:__pkg__" once we are on Bazel >=6.5. 100 visibility = ["//visibility:public"], 101) 102