Skip to content

Commit

Permalink
Use buf.gen.yaml v2 (#46251)
Browse files Browse the repository at this point in the history
  • Loading branch information
espadolini authored Sep 4, 2024
1 parent a0423ae commit e21681b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 54 deletions.
22 changes: 14 additions & 8 deletions buf-connect-go.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- proto/prehog/

managed:
enabled: true
go_package_prefix:
default: github.com/gravitational/teleport/gen/proto/go
override:
- file_option: go_package_prefix
value: github.com/gravitational/teleport/gen/proto/go

plugins:
- name: go
strategy: all
path:
- local:
- go
- run
- google.golang.org/protobuf/cmd/protoc-gen-go
out: .
opt: module=github.com/gravitational/teleport
- name: connect-go
strategy: all
path:
- local:
- go
- run
- connectrpc.com/connect/cmd/protoc-gen-connect-go
out: .
opt: module=github.com/gravitational/teleport
strategy: all
32 changes: 24 additions & 8 deletions buf-go.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
version: v1
version: v2

inputs:
- directory: .
exclude_paths:
# generated by buf-gogo.gen.yaml
- api/proto/teleport/attestation/
- api/proto/teleport/legacy/
- api/proto/teleport/usageevents/
- proto/teleport/lib/web/terminal/envelope.proto
# generated by buf-connect-go.gen.yaml
- proto/prehog/
- directory: .
paths:
# excluded by buf-gogo.gen.yaml
- api/proto/teleport/legacy/client/proto/event.proto

plugins:
- name: go
strategy: all
path:
- local:
- go
- run
- google.golang.org/protobuf/cmd/protoc-gen-go
out: .
opt:
- module=github.com/gravitational/teleport
# needed by teleport/lib/teleterm/v1/usage_events.proto
# needed by teleport/lib/teleterm/v1/usage_events.proto because we use
# managed mode for the go package name there
- Mprehog/v1alpha/connect.proto=github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha;prehogv1alpha
- name: go-grpc
strategy: all
path:
- local:
- go
- run
- google.golang.org/grpc/cmd/protoc-gen-go-grpc
out: .
opt:
- module=github.com/gravitational/teleport
# needed by teleport/lib/teleterm/v1/usage_events.proto
# needed by teleport/lib/teleterm/v1/usage_events.proto because we use
# managed mode for the go package name there
- Mprehog/v1alpha/connect.proto=github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha;prehogv1alpha
strategy: all
16 changes: 14 additions & 2 deletions buf-gogo.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- api/proto/teleport/attestation/
- api/proto/teleport/legacy/
- api/proto/teleport/usageevents/
- proto/teleport/lib/web/terminal/envelope.proto
exclude_paths:
# generated by buf-go.gen.yaml
- api/proto/teleport/legacy/client/proto/event.proto

plugins:
- name: gogofast
- local: protoc-gen-gogofast
out: ./gogogen
opt:
- Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types
Expand Down
25 changes: 17 additions & 8 deletions buf-js.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- api/proto/teleport/accesslist/
- api/proto/teleport/header/
- api/proto/teleport/trait/
- proto/prehog/
- proto/teleport/lib/teleterm/

plugins:
# https://github.com/protocolbuffers/protobuf/tree/v3.20.1/js
- name: js
strategy: all
- protoc_builtin: js
out: gen/proto/js
opt:
- import_style=commonjs,binary
strategy: all

# https://github.com/grpc/grpc-node/tree/grpc-tools%401.12.4/packages/grpc-tools/
- name: grpc
strategy: all
- local: grpc_tools_node_protoc_plugin
out: gen/proto/js
opt: grpc_js
path: grpc_tools_node_protoc_plugin
strategy: all

# https://github.com/agreatfool/grpc_tools_node_protoc_ts/tree/v5.3.2
- name: ts
strategy: all
- local: protoc-gen-ts
out: gen/proto/js
opt: "service=grpc-node"
strategy: all
33 changes: 5 additions & 28 deletions build.assets/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,18 @@ main() {
# this for us (and which is what we use for the non-gogo protogen).
rm -fr gogogen
trap 'rm -fr gogogen' EXIT # don't leave files behind
echoed buf generate --template=buf-gogo.gen.yaml \
--path=api/proto/teleport/legacy/ \
--path=api/proto/teleport/attestation/ \
--path=api/proto/teleport/usageevents/ \
--path=proto/teleport/lib/web/terminal/envelope.proto \
--exclude-path=api/proto/teleport/legacy/client/proto/event.proto
echoed buf generate --template=buf-gogo.gen.yaml
cp -r gogogen/github.com/gravitational/teleport/. .
# error out if there's anything outside of github.com/gravitational/teleport
rm -fr gogogen/github.com/gravitational/teleport
rmdir gogogen/github.com/gravitational gogogen/github.com gogogen

# Generate protoc-gen-go protos (preferred).
echoed buf generate --template=buf-go.gen.yaml \
--exclude-path=api/proto/teleport/legacy/ \
--exclude-path=api/proto/teleport/attestation/ \
--exclude-path=api/proto/teleport/usageevents/ \
--exclude-path=proto/teleport/lib/web/terminal/envelope.proto \
--exclude-path=proto/prehog/

# Generate event.proto separately because we only want to run it on this
# one particular file in legacy.
echoed buf generate --template=buf-go.gen.yaml \
--path=api/proto/teleport/legacy/client/proto/event.proto

# Generate connect-go protos.
echoed buf generate --template=buf-connect-go.gen.yaml \
--path=proto/prehog/
# Generate go, go-grpc and connect-go protos (preferred).
echoed buf generate --template=buf-go.gen.yaml
echoed buf generate --template=buf-connect-go.gen.yaml

# Generate JS protos.
[[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-js.gen.yaml \
--path=proto/prehog/ \
--path=proto/teleport/lib/teleterm/ \
--path=api/proto/teleport/accesslist/ \
--path=api/proto/teleport/trait/ \
--path=api/proto/teleport/header/
[[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-js.gen.yaml
}

main "$@"

0 comments on commit e21681b

Please sign in to comment.