-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use one Buf workspace instead of three #19774
Conversation
@@ -1044,7 +1040,7 @@ grpc-teleterm: | |||
# Unlike grpc-teleterm, this target runs locally. | |||
.PHONY: grpc-teleterm/host | |||
grpc-teleterm/host: protos/all | |||
cd lib/teleterm && $(BUF) generate | |||
$(BUF) generate --template=lib/teleterm/buf.gen.yaml lib/teleterm/api/proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but I think I should move those buf.gen.yaml
files into the directories defined in buf.work.yaml
.
buf.gen.yaml
files used to be defined on the same level as the old buf.work.yaml
. Since we removed those extra workspaces, it'd probably make more sense to have buf.gen.yaml
on the same level as buf.yaml
. https://docs.buf.build/configuration/v1/buf-gen-yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2c is to keep buf.gens besides the workspace file, as it is the same path were we expect codegen commands to start from.
I suggest doing away with all the additional buf.gen files and using go_package to control the output location, like we do for for everything under proto/ today. We can control whether to use protoc-gen-go or gogo in genproto.sh. (FYI @timothyb89 for prehog.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest doing away with all the additional buf.gen files and using go_package to control the output location, like we do for for everything under proto/ today. We can control whether to use protoc-gen-go or gogo in genproto.sh.
I forgot to mention that in this PR explicitly but we'll need to generate JS files from lib/prehog protos. For now I planned to maintain a separate lib/prehog/buf-teleterm.gen.yaml
file.
But I suppose once we get rid of grpc-teleterm
, we could have a buf-js.gen.yaml
file which we'd execute for lib/prehog and lib/teleterm, right?
I'm not sure how to control the output path for the JS files without configuring that in buf.gen.yaml
yet but I can tackle that once I get to it.
On top of that, lib/prehog seems to use connect-go on top of protoc-gen-go.
For now though I'd probably just keep them as they are and clean it up while removing grpc-teleterm
. Does that sound good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I suppose once we get rid of grpc-teleterm, we could have a buf-js.gen.yaml file which we'd execute for lib/prehog and lib/teleterm, right?
That would be ideal, yes. :)
I'm not sure how to control the output path for the JS files without configuring that in buf.gen.yaml yet but I can tackle that once I get to it.
I'm not sure either. If there's no .proto option, then we might be stuck with multiple files, but that isn't that terrible. We could output both under gen/proto/js/
, following suite from api/ (which I based on Buf examples), which tbh I think is even better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could output both under
gen/proto/js/
, following suite from api/ (which I based on Buf examples), which tbh I think is even better.
Ah, that's right. For some reason I was super focus on outputting them to the existing locations. But having them both under the same path might be even better due to how the generated import paths look like in JS files.
@@ -986,21 +986,17 @@ protos/all: protos/build protos/lint protos/format | |||
.PHONY: protos/build | |||
protos/build: buf/installed | |||
$(BUF) build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If run with no additional arguments, buf commands run across all modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, Rafal.
I think we've solved, little by little, most of the issues we had with making a single workspace, so I see no problems in merging the workspaces.
A next step could be to generate both Go and Js/Typescript in a single step, so we don't need a separate target for Teleterm. WDYT?
@@ -1044,7 +1040,7 @@ grpc-teleterm: | |||
# Unlike grpc-teleterm, this target runs locally. | |||
.PHONY: grpc-teleterm/host | |||
grpc-teleterm/host: protos/all | |||
cd lib/teleterm && $(BUF) generate | |||
$(BUF) generate --template=lib/teleterm/buf.gen.yaml lib/teleterm/api/proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2c is to keep buf.gens besides the workspace file, as it is the same path were we expect codegen commands to start from.
I suggest doing away with all the additional buf.gen files and using go_package to control the output location, like we do for for everything under proto/ today. We can control whether to use protoc-gen-go or gogo in genproto.sh. (FYI @timothyb89 for prehog.)
build.assets/genproto.sh
Outdated
@@ -26,7 +27,7 @@ main() { | |||
cp -r github.com/gravitational/teleport/* . | |||
|
|||
# Generate prehog protos. | |||
cd lib/prehog && buf generate | |||
buf generate --template=lib/prehog/buf.gen.yaml lib/prehog/proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we fit prehog in one of the categories above? As in, gogo or plain protoc-gen-go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we fit prehog in one of the categories above? As in, gogo or plain protoc-gen-go?
I'm going to move it to the protoc-gen-go section since it does use protoc-gen-go, but it also uses connect-go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'm not stoked to add a 3rd proto compiler, but I won't meddle with this one either.
I think we might need a separate config - IIUC, protoc-gen-connect-go replaces protoc-gen-grpc-go.
The new path looks correct to me - buf.yaml sits at the root of the intended proto import path. |
Also, would you mind backporting this as far as possible, so we have consistent toolchains in all active releases? I'll tentatively add the labels here. |
Definitely, I want to work on removing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I would prefer to see prehog explicitly set go_package and rely on it for the output paths, as we do with other protos. I would also prefer to not jump in on a 3rd proto compiler (connect-go) without strong reason to use it, but I understand that's how it is now. (FYI @timothyb89)
As it stands this is a good improvement over out setup, so happy to see it land.
|
||
# Generate protoc-gen-go protos (preferred). | ||
# Add your protos to the list if you can. | ||
buf generate --template=buf-go.gen.yaml \ | ||
--path=api/proto/teleport/devicetrust/ \ | ||
--path=api/proto/teleport/loginrule/ \ | ||
--path=proto/teleport/lib/multiplexer/ | ||
buf generate --template=lib/prehog/buf.gen.yaml lib/prehog/proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly?
Because this is Go it still follows go_package, so we should be able to control the output path through that and have a single gen file.
buf generate --template=lib/prehog/buf.gen.yaml lib/prehog/proto | |
# Generate connect-go protos. | |
buf generate --template=buf-connectgo.gen.yaml lib/prehog/proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move lib/prehog/buf.gen.yaml
in the PR that gets rid of make grpc-teleterm
.
We just used connect-go to match prehog's reference implementation, I imagine we can swap that out easily enough if it simplifies things. |
@ravicious See the table below for backport results.
|
At the moment we have three different Buf workspaces, signified by
buf.work.yaml
files. This PR makes it so that there's only one Buf workspace with a singlebuf.work.yaml
in the root directory.Why
Telemetry in Connect will need to send gRPC messages that will go from the Electron app through tsh daemon to prehog. Instead of redefining each message type from lib/prehog protos in lib/teleterm, we want to import protos from lib/prehog in lib/teleterm protos.
However, in order to import protos from one module to another, both packages need to live in the same workspace.
We currently have three different
buf.work.yaml
files. I looked at their history and I think creating three separate workspaces wasn't a conscious choice, they just ended up this way because we never had to share stuff between them.How
For the most part, I just had to remove those extra
buf.work.yaml
files and then change args tobuf
calls a little bit. I used bufbuild/buf-examples as the template.I also moved
lib/prehog/proto/prehog/buf.yaml
tolib/prehog/proto/buf.yaml
to match other modules.There are some additional requirements Buf workspaces must meet but ours do meet them without any additional changes.
I verified that linting and formatting still works as expected across all modules. I also verified that making changes in proto files results in changes in the generated code, even for the files for which we use
protoc-gen-go
.