hundreds-father-404
04/21/2022, 12:27 AMgo mod tidy
will fail:hundreds-father-404
04/21/2022, 12:28 AM❯ go mod tidy
go: finding module for package <http://github.com/pantsbuild/example-codegen/gen|github.com/pantsbuild/example-codegen/gen>
<http://github.com/pantsbuild/example-codegen/examples|github.com/pantsbuild/example-codegen/examples> tested by
<http://github.com/pantsbuild/example-codegen/examples.test|github.com/pantsbuild/example-codegen/examples.test> imports
<http://github.com/pantsbuild/example-codegen/gen|github.com/pantsbuild/example-codegen/gen>: no matching versions for query "latest"
hundreds-father-404
04/21/2022, 12:28 AMexport-codegen
?fast-nail-55400
04/21/2022, 12:29 AMhundreds-father-404
04/21/2022, 12:30 AMgo mod tidy
, right?narrow-vegetable-37489
04/21/2022, 8:55 PMgo mod tidy
) - it's tricky to say the least. A replace
in go.mod
pointing towards the result of export-codegen
makes go mod tidy
aware of the code at least, but then it complains about a missing go.mod
in that export dir instead.hundreds-father-404
04/21/2022, 9:14 PMnarrow-vegetable-37489
04/21/2022, 9:47 PMgo mod tidy
(and possibly other commands) not working would be a bit more annoying though.
But that's just me - I don't think I'd get away with migrating my work project's Go proto code to Pants without at least figuring out a workaround first. Having generated code in the repo isn't pretty, but at least everything works as my co-workers expects it to (except they keep forgetting to regenerate the Go code when they add things to the protobufs 🙈).fast-nail-55400
04/22/2022, 5:45 PMfast-nail-55400
04/22/2022, 5:56 PMnarrow-vegetable-37489
04/23/2022, 11:16 AMGOPACKAGESDRIVER
environment variable that points to a binary that will read requests on its stdin, and output the Package struct as JSON on stdout. There's not too much documentation about it, but Bazel added some sort of support for it here. They also explain how it works in Bazel a bit more here.narrow-vegetable-37489
04/23/2022, 11:20 AMsilly-spring-18687
07/23/2023, 12:50 PMnarrow-vegetable-37489
07/23/2023, 9:19 PMexport-codegen
. Pants is happy, go mod
is happy, my IDE is happy, so good enough for me 🙂silly-spring-18687
07/25/2023, 11:21 PMnumerous-pizza-15735
05/14/2024, 5:17 PMnarrow-vegetable-37489
05/23/2024, 3:07 PM<repo root>/golang/
and our go.mod
in that folder defines the root module as module <http://git.example.com/group/project/golang|git.example.com/group/project/golang>
.
Our protobufs are in <repo root>/protobuf/
, and in each .proto file we set package
and go_package
. For protobuf/foo/bar.proto
it’d be:
package foo;
option go_package = git.example.com/group/project/golang/protobuf/foo";
Then we’ve simply created a symlink in golang
that points to the protobufs generated by pants export-codegen
with ln -s protobuf ../dist/codegen/protobuf
In Go we can then import the generated protobufs from <http://git.example.com/group/project/golang/protobuf/foo|git.example.com/group/project/golang/protobuf/foo>
. It’s not perfect, but works good enough for the relatively little Go code we have.