• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
10
11package(default_applicable_licenses = ["//:license"])
12
13licenses(["notice"])
14
15cc_library(
16    name = "names",
17    srcs = ["names.cc"],
18    hdrs = ["names.h"],
19    deps = [
20        "//upb:port",
21        "//upb_generator/common:names",
22        "@com_google_absl//absl/strings",
23    ],
24)
25
26cc_binary(
27    name = "protoc-gen-upbdefs",
28    linkopts = ["-lm"],
29    visibility = ["//net/proto2/contrib/protoc_explorer:__pkg__"],
30    deps = [":generator_with_main"],
31)
32
33# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6.
34# In Bazel 7, our cmake dependency scraping works fine with cc_binary.
35cc_library(
36    name = "generator_with_main",
37    srcs = ["generator.cc"],
38    copts = UPB_DEFAULT_CPPOPTS,
39    visibility = ["//pkg:__pkg__"],
40    # To work around the following link error from ABSL:
41    # /usr/bin/x86_64-linux-gnu-ld: bazel-out/k8-opt-exec-2B5CBBC6-ST-c1776f9924ec/bin/external/com_google_absl/absl/time/libtime.a(duration.o): undefined reference to symbol 'floor@@GLIBC_2.2.5'
42    # /usr/bin/x86_64-linux-gnu-ld: /opt/manylinux/2014/x86_64/lib64/libm.so.6: error adding symbols: DSO missing from command line
43    # clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
44    deps = [
45        ":names",
46        "//src/google/protobuf:descriptor_upb_c_proto",
47        "//upb:mem",
48        "//upb:reflection",
49        "//upb/util:def_to_proto",
50        "//upb_generator:common",
51        "//upb_generator:file_layout",
52        "//upb_generator:plugin",
53        "//upb_generator/common:names",
54        "//upb_generator/minitable:names",
55        "@com_google_absl//absl/strings",
56        "@com_google_absl//absl/strings:string_view",
57    ],
58)
59
60proto_lang_toolchain(
61    name = "toolchain",
62    command_line = "--upbdefs_out=$(OUT)",
63    output_files = "multiple",
64    plugin = ":protoc-gen-upbdefs",
65    plugin_format_flag = "--plugin=protoc-gen-upbdefs=%s",
66    progress_message = "Generating upb protos",
67    runtime = "//upb:generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
68    # TODO: Restrict to "//bazel:__pkg__" once we are on Bazel >=6.5.
69    visibility = ["//visibility:public"],
70)
71