Skip to content

Commit 6e3f753

Browse files
committed
feat: include Go codegen
See bazel-contrib/rules_go#3658
1 parent fd97d87 commit 6e3f753

File tree

3 files changed

+240
-1
lines changed

3 files changed

+240
-1
lines changed

examples/proto/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
load("@aspect_rules_ts//ts:proto.bzl", "ts_proto_library")
2-
load("@rules_go//proto:def.bzl", "go_proto_library")
32
load("@rules_proto//proto:defs.bzl", "proto_library")
43
load("@rules_rust_prost//:defs.bzl", "rust_prost_library")
54
load("@protobuf//bazel:py_proto_library.bzl", "py_proto_library")
5+
load("//tools:go_proto_library.bzl", "go_proto_library")
66

77
package(default_visibility = ["//visibility:public"])
88

examples/proto/greeter.pb.go

Lines changed: 195 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"go_proto_library wrapper macro to check in the resulting stub files for the editor"
2+
3+
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
4+
load("@aspect_bazel_lib//lib:output_files.bzl", "make_output_files")
5+
load("@bazel_skylib//lib:paths.bzl", "paths")
6+
load("@rules_go//proto:def.bzl", _go_proto_library = "go_proto_library")
7+
8+
def go_proto_library(name, importpath, proto_srcs = [], **kwargs):
9+
"""Wrap go_proto_library with write_source_files.
10+
11+
This causes the resulting .pb.go files to be checked into the source tree.
12+
Args:
13+
name: name of the go_proto_library rule produced
14+
importpath: passed to go_proto_library#importpath
15+
proto_srcs: the srcs of the proto_library target passed to go_proto_library#proto
16+
If unset, a glob() of all ".proto" files in the package is used.
17+
**kwargs: remaining arguments to go_proto_library
18+
"""
19+
20+
# Based on our knowledge of the rule implementation,
21+
# predict the output paths it writes.
22+
proto_out_path = "{0}/{1}_/{2}/%s.pb.go".format(
23+
native.package_name(),
24+
name,
25+
importpath,
26+
)
27+
28+
if len(proto_srcs) < 1:
29+
proto_srcs = native.glob(["*.proto"])
30+
31+
_go_proto_library(
32+
name = name,
33+
importpath = importpath,
34+
**kwargs
35+
)
36+
37+
write_source_files(
38+
name = name + ".update_go_pb",
39+
files = {
40+
base + ".pb.go": make_output_files(base + "_pb_go", name, [proto_out_path % base], output_group = "go_generated_srcs")
41+
for base in [paths.replace_extension(p, "") for p in proto_srcs]
42+
},
43+
visibility = ["//write_source_files:__pkg__"],
44+
)

0 commit comments

Comments
 (0)