1load("@rules_proto//proto:defs.bzl", "proto_library") 2load( 3 "@com_google_protobuf//:protobuf.bzl", 4 "cc_proto_library", 5 "proto_gen", 6 "py_proto_library", 7) 8 9licenses(["notice"]) 10 11filegroup( 12 name = "LICENSE", 13 visibility = ["//visibility:public"], 14) 15 16# Map of all well known protos. 17# name => (include path, imports) 18WELL_KNOWN_PROTO_MAP = { 19 "any": ("google/protobuf/any.proto", []), 20 "api": ( 21 "google/protobuf/api.proto", 22 [ 23 "source_context", 24 "type", 25 ], 26 ), 27 "compiler_plugin": ( 28 "google/protobuf/compiler/plugin.proto", 29 ["descriptor"], 30 ), 31 "descriptor": ("google/protobuf/descriptor.proto", []), 32 "duration": ("google/protobuf/duration.proto", []), 33 "empty": ("google/protobuf/empty.proto", []), 34 "field_mask": ("google/protobuf/field_mask.proto", []), 35 "source_context": ("google/protobuf/source_context.proto", []), 36 "struct": ("google/protobuf/struct.proto", []), 37 "timestamp": ("google/protobuf/timestamp.proto", []), 38 "type": ( 39 "google/protobuf/type.proto", 40 [ 41 "any", 42 "source_context", 43 ], 44 ), 45 "wrappers": ("google/protobuf/wrappers.proto", []), 46} 47 48RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()] 49 50genrule( 51 name = "link_proto_files", 52 outs = RELATIVE_WELL_KNOWN_PROTOS, 53 cmd = """ 54 for i in $(OUTS); do 55 f=$${i#$(@D)/} 56 mkdir -p $(@D)/$${f%/*} 57 ln -sf $(PROTOBUF_INCLUDE_PATH)/$$f $(@D)/$$f 58 done 59 """, 60) 61 62cc_library( 63 name = "protobuf", 64 linkopts = ["-lprotobuf"], 65 visibility = ["//visibility:public"], 66) 67 68cc_library( 69 name = "protobuf_headers", 70 linkopts = ["-lprotobuf"], 71 visibility = ["//visibility:public"], 72) 73 74cc_library( 75 name = "protoc_lib", 76 linkopts = ["-lprotoc"], 77 visibility = ["//visibility:public"], 78) 79 80genrule( 81 name = "protoc", 82 outs = ["protoc.bin"], 83 cmd = "ln -s $$(which protoc) $@", 84 executable = 1, 85 visibility = ["//visibility:public"], 86) 87 88cc_proto_library( 89 name = "cc_wkt_protos", 90 internal_bootstrap_hack = 1, 91 protoc = ":protoc", 92 visibility = ["//visibility:public"], 93) 94 95proto_gen( 96 name = "protobuf_python_genproto", 97 includes = ["."], 98 protoc = "@com_google_protobuf//:protoc", 99 visibility = ["//visibility:public"], 100) 101 102py_library( 103 name = "protobuf_python", 104 srcs_version = "PY3", 105 visibility = ["//visibility:public"], 106) 107 108[proto_library( 109 name = proto[0] + "_proto", 110 srcs = [proto[1][0]], 111 visibility = ["//visibility:public"], 112 deps = [dep + "_proto" for dep in proto[1][1]], 113) for proto in WELL_KNOWN_PROTO_MAP.items()] 114