Skip to content

Commit 0ba6ce8

Browse files
committed
chore: do TODO so all wkt are available
1 parent f5bd744 commit 0ba6ce8

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

protoc/private/prebuilt_protoc_toolchain.bzl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ It exposes bin/protoc as a proto_toolchain.
55

66
load(":versions.bzl", "PROTOC_PLATFORMS", "PROTOC_VERSIONS")
77

8+
# TODO: we should read this dynamically by `ls *.proto` and then search for "import" statements
9+
# inside the files. Currently this assumes the wkt srcs/deps are fixed over time.
10+
GOOGLE_PROTOBUF_DEP_EDGES = {
11+
"any": [],
12+
"api": ["source_context", "type"],
13+
"compiler/plugin": ["descriptor"],
14+
"descriptor": [],
15+
"duration": [],
16+
"empty": [],
17+
"field_mask": [],
18+
"source_context": [],
19+
"struct": [],
20+
"timestamp": [],
21+
"type": ["any", "source_context"],
22+
"wrappers": [],
23+
}
24+
825
def _prebuilt_protoc_repo_impl(rctx):
926
release_version = rctx.attr.version
1027

@@ -21,7 +38,7 @@ def _prebuilt_protoc_repo_impl(rctx):
2138
url = url,
2239
integrity = PROTOC_VERSIONS[release_version][filename],
2340
)
24-
rctx.file("BUILD.bazel", """\
41+
build_content = """\
2542
# Generated by @rules_proto//proto/toolchains:prebuilt_protoc_toolchain.bzl
2643
load("@rules_proto//proto/private/rules:proto_toolchain_rule.bzl", "proto_toolchain")
2744
@@ -32,17 +49,20 @@ proto_toolchain(
3249
proto_compiler = "{protoc_label}",
3350
visibility = ["//visibility:public"],
3451
)
52+
""".format(
53+
protoc_label = ":bin/protoc.exe" if rctx.attr.platform.startswith("win") else ":bin/protoc",
54+
)
3555

36-
# TODO: add proto_library for each .proto file
37-
# and add deps[] in cases where they dep on each other
56+
for src, deps in GOOGLE_PROTOBUF_DEP_EDGES.items():
57+
build_content += """\
3858
proto_library(
39-
name = "any_proto",
40-
srcs = ["include/google/protobuf/any.proto"],
59+
name = "{0}_proto",
60+
srcs = ["include/google/protobuf/{0}.proto"],
61+
deps = [":%s_proto" % dep for dep in {1}],
4162
strip_import_prefix = "include",
4263
)
43-
""".format(
44-
protoc_label = ":bin/protoc.exe" if rctx.attr.platform.startswith("win") else ":bin/protoc",
45-
))
64+
""".format(src, deps)
65+
rctx.file("BUILD.bazel", build_content)
4666

4767
prebuilt_protoc_repo = repository_rule(
4868
doc = "Download a pre-built protoc and create a concrete toolchains for it",

0 commit comments

Comments
 (0)