I don't really understand how this approach would work well with IDEs/autocompletion though.
For example, suppose I'm writing some mocked unit tests in Go and want to use mockgen to generate some mocks on an interface...
//go:generate mockgen (N.B. This generation is done by Bazel)
type Object interface {
Thing() string
}
Then I need to use the generated mocked type in my test:
mockThing := NewMockObject(ctrl)
mockThing.EXPECT().Thing().Return("Foo")
But NewMockObject doesn't exist as far as my IDE knows, because the generated code is only generated at build-time and only exists in the Bazel sandbox.
The code will compile and run successfully, but the developer experience is terrible because you lose the ability to use your IDE's code lens, syntax checks, autocompletion. Everything that's generated shows a red squiggly this-doesnt-exist line.
Maybe I'm just fundamentally misunderstanding how Bazel is supposed to be used. My setup is pretty typical. I develop in VS Code, and build using Bazel, but I do not allow Bazel to automate code generation because the generated sources do not appear in my local environment - just in the bazel sandbox.
Maybe someone can suggest a better approach?