Skip to content

Commit

Permalink
connectrpc: generate code with buf
Browse files Browse the repository at this point in the history
Generate the additional code required for connectrpc with the buf
tool. Currently, there is no bazel ruleset available for buf. We work
around this by invoking the buf binary directly and commiting the
generated code in git. To deal with generation, we pin the
`protoc-gen-connect-go` version in the go.mod file. A small scaffolding
go binary is added to deal with setting up the environment correctly
for the buf tool. While this could be a shell script, this is more
readable and maintainable.

This PR is broken out of the
https://github.com/scionproto/scion/tree/connectrpc branch to make
incremental review easier.

TL;DR: Run `bazel run //tools/buf` to generate the connectrpc code.
  • Loading branch information
oncilla committed Jun 6, 2024
1 parent 9d52e2f commit 1aa57f9
Show file tree
Hide file tree
Showing 28 changed files with 2,256 additions and 21 deletions.
8 changes: 4 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
Expand Down Expand Up @@ -140,9 +139,10 @@ gazelle(
go_lint_config(
name = "go_lint_config",
exclude_filter = [
"mock_",
".pb.go",
".connect.go",
".gen.go",
".pb.go",
"mock_",
],
visibility = [
"//visibility:public",
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ protobuf:
cp -r bazel-bin/pkg/proto/*/*/go_default_library_/github.com/scionproto/scion/pkg/proto/* pkg/proto
chmod 0644 pkg/proto/*/*.pb.go

bazel run //tools/buf

mocks:
tools/gomocks.py

Expand Down Expand Up @@ -141,7 +143,7 @@ lint-protobuf: lint-protobuf-buf

lint-protobuf-buf:
$(info ==> $@)
@tools/quiet bazel run --config=quiet @buf_bin//file:buf -- check lint
@tools/quiet bazel run --config=quiet @buf//:buf -- lint $(PWD) --path $(PWD)/proto

lint-openapi: lint-openapi-spectral

Expand Down
17 changes: 6 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace(
name = "com_github_scionproto_scion",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# linter rules
http_archive(
Expand Down Expand Up @@ -205,6 +205,11 @@ load("@tester_debian10_packages//:packages.bzl", tester_debian_packages_install_

tester_debian_packages_install_deps()

# Buf CLI to generate connect-go
load("//tools/buf:deps.bzl", "buf_dependencies")

buf_dependencies()

# protobuf/gRPC
http_archive(
name = "rules_proto_grpc",
Expand Down Expand Up @@ -237,16 +242,6 @@ http_archive(
],
)

http_file(
name = "buf_bin",
downloaded_file_path = "buf",
executable = True,
sha256 = "5faf15ed0a3cd4bd0919ba5fcb95334c1fd2ba32770df289d615138fa188d36a",
urls = [
"https://github.com/bufbuild/buf/releases/download/v0.20.5/buf-Linux-x86_64",
],
)

load("//tools/lint/python:deps.bzl", "python_lint_deps")

python_lint_deps(python_interpreter)
Expand Down
9 changes: 4 additions & 5 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
build:
roots:
- .
excludes:
- anapaya/protobuf
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/scionproto/scion

require (
connectrpc.com/connect v1.16.2
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9
github.com/bazelbuild/rules_go v0.47.1
github.com/buildkite/go-buildkite/v2 v2.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE=
connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
Expand Down
6 changes: 6 additions & 0 deletions go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def go_deps():
sum = "h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=",
version = "v0.4.5",
)
go_repository(
name = "com_connectrpc_connect",
importpath = "connectrpc.com/connect",
sum = "h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE=",
version = "v1.16.2",
)
go_repository(
name = "com_github_ajstarks_svgo",
importpath = "github.com/ajstarks/svgo",
Expand Down
17 changes: 17 additions & 0 deletions pkg/proto/control_plane/v1/control_planeconnect/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("//tools/lint:go.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"cppki.connect.go",
"drkey.connect.go",
"renewal.connect.go",
"seg.connect.go",
],
importpath = "github.com/scionproto/scion/pkg/proto/control_plane/v1/control_planeconnect",
visibility = ["//visibility:public"],
deps = [
"//pkg/proto/control_plane:go_default_library",
"@com_connectrpc_connect//:go_default_library",
],
)
164 changes: 164 additions & 0 deletions pkg/proto/control_plane/v1/control_planeconnect/cppki.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1aa57f9

Please sign in to comment.