Skip to content

Commit

Permalink
bazel: Add proto_library rules for well known types. Fixes protocolbu…
Browse files Browse the repository at this point in the history
…ffers#2763

Adds a proto_library rule for each well known type proto:

$ bazel query "filter(\".*_proto$\", \"...\")"
//:wrappers_proto
//:timestamp_proto
//:struct_proto
//:field_mask_proto
//:empty_proto
//:duration_proto
//:compiler_plugin_proto
//:descriptor_proto
//:api_proto
//:type_proto
//:source_context_proto
//:any_proto

Bazel users can reference these proto_library rules for their own
language specific rules i.e.

java_proto_library(
  name = "any_java_proto",
  deps = ["@com_google_protobuf//:any_proto"],
)

Also set the workspace name to "com_google_protobuf", as proto_library
rules reference protobuf that way.
  • Loading branch information
buchgr committed Sep 5, 2017
1 parent 6699f2c commit 699c0eb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
60 changes: 45 additions & 15 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,24 @@ objc_library(
visibility = ["//visibility:public"],
)

RELATIVE_WELL_KNOWN_PROTOS = [
# AUTOGEN(well_known_protos)
"google/protobuf/any.proto",
"google/protobuf/api.proto",
"google/protobuf/compiler/plugin.proto",
"google/protobuf/descriptor.proto",
"google/protobuf/duration.proto",
"google/protobuf/empty.proto",
"google/protobuf/field_mask.proto",
"google/protobuf/source_context.proto",
"google/protobuf/struct.proto",
"google/protobuf/timestamp.proto",
"google/protobuf/type.proto",
"google/protobuf/wrappers.proto",
]
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
"any" : ("google/protobuf/any.proto", []),
"api" : ("google/protobuf/api.proto", ["source_context", "type"]),
"compiler_plugin" : ("google/protobuf/compiler/plugin.proto", ["descriptor"]),
"descriptor" : ("google/protobuf/descriptor.proto", []),
"duration" : ("google/protobuf/duration.proto", []),
"empty" : ("google/protobuf/empty.proto", []),
"field_mask" : ("google/protobuf/field_mask.proto", []),
"source_context" : ("google/protobuf/source_context.proto", []),
"struct" : ("google/protobuf/struct.proto", []),
"timestamp" : ("google/protobuf/timestamp.proto", []),
"type" : ("google/protobuf/type.proto", ["any", "source_context"]),
"wrappers" : ("google/protobuf/wrappers.proto", []),
}

RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]

WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

Expand All @@ -258,6 +261,33 @@ cc_proto_library(
visibility = ["//visibility:public"],
)

################################################################################
# Well Known Types Proto Library Rules
#
# These proto_library rules can be used with one of the language specific proto
# library rules i.e. java_proto_library:
#
# java_proto_library(
# name = "any_java_proto",
# deps = ["@com_google_protobuf//:any_proto],
# )
################################################################################

internal_copied_filegroup(
name = "_internal_wkt_protos",
srcs = WELL_KNOWN_PROTOS,
dest = "",
strip_prefix = "src",
visibility = ["//visibility:hidden"],
)

[proto_library(
name = proto[0] + "_proto",
srcs = [proto[1][0]],
deps = [dep + "_proto" for dep in proto[1][1]],
visibility = ["//visibility:public"],
) for proto in WELL_KNOWN_PROTO_MAP.items()]

################################################################################
# Protocol Buffers Compiler
################################################################################
Expand Down
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
workspace(name = "com_google_protobuf")

new_git_repository(
name = "googletest",
build_file = "gmock.BUILD",
Expand Down

0 comments on commit 699c0eb

Please sign in to comment.