• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15"""Builds a proto collection."""
16
17load("@npm//@bazel/typescript:index.bzl", "ts_library")
18load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
19load("@//pw_protobuf_compiler/ts/codegen:template_replacement.bzl", "template_replacement")
20
21def _lib(name, proto_library, js_proto_library):
22    js_proto_library_name = Label(js_proto_library).name
23    proto_root_dir = js_proto_library_name + "/" + js_proto_library_name + "_pb"
24    template_name = name + "_template"
25    template_replacement(
26        name = template_name,
27        descriptor_data = proto_library,
28        proto_root_dir = proto_root_dir,
29        output_file = "generated/ts_proto_collection.ts",
30    )
31
32    ts_library(
33        name = name + "_lib",
34        package_name = name,
35        module_name = name,
36        srcs = [template_name],
37        deps = [
38            js_proto_library,
39            "@//pw_protobuf_compiler/ts:pw_protobuf_compiler",
40            "@//pw_rpc/ts:packet_proto_tspb",
41            "@npm//@types/google-protobuf",
42            "@npm//@types/node",
43            "@npm//base64-js",
44        ],
45    )
46
47    native.filegroup(
48        name = name + "_esm",
49        srcs = [name + "_lib"],
50        output_group = "es6_sources",
51    )
52
53def ts_proto_collection(name, proto_library, js_proto_library):
54    _lib(name, proto_library, js_proto_library)
55    js_library(
56        name = name,
57        package_name = "@pigweed/" + name + "/pw_protobuf_compiler",
58        deps = [name + "_lib", name + "_esm"],
59    )
60