https://pantsbuild.org/ logo
#development
Title
# development
h

hundreds-father-404

04/21/2022, 12:27 AM
@fast-nail-55400 one awkward edge w/ Go Protobuf.
go mod tidy
will fail:
Copy code
❯ 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"
Are we expecting users to use
export-codegen
?
f

fast-nail-55400

04/21/2022, 12:29 AM
they might if they want to make the generated sources visible to their IDE
h

hundreds-father-404

04/21/2022, 12:30 AM
or run
go mod tidy
, right?
n

narrow-vegetable-37489

04/21/2022, 8:55 PM
I've been trying to get generated Go protobufs to play nicely with IDEs and "non-Pants usage" as well (like
go 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.
πŸ‘ 1
h

hundreds-father-404

04/21/2022, 9:14 PM
That's good to know that it's tricky outside of pants too… How much of a dealbreaker do you think this is Jonas? It sounds like there is a workaround, only very awkward
n

narrow-vegetable-37489

04/21/2022, 9:47 PM
I think it's very user specific if it's a dealbreaker or not. Personally I could live with my IDE complaining about missing imports since in exchange I stop having generated Go code in the repository.
go 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 πŸ™ˆ).
πŸ‘ 1
f

fast-nail-55400

04/22/2022, 5:45 PM
(Asked generally:) how does Bazel handle this?
πŸ‘ 1
(Or doesn't handle this? I'd like to get a sense of how other tools may have solved this.)
n

narrow-vegetable-37489

04/23/2022, 11:16 AM
Relevant issue for Bazel: https://github.com/bazelbuild/rules_go/issues/512 Sounds like Go has added some
GOPACKAGESDRIVER
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.
Seems like Go is phasing it out though: https://go-review.googlesource.com/c/tools/+/268977/
πŸ‘ 1
πŸ‘€ 1
s

silly-spring-18687

07/23/2023, 12:50 PM
Hey @narrow-vegetable-37489 - any luck with setting this up? I’m struggling to get something working in vscode myself
n

narrow-vegetable-37489

07/23/2023, 9:19 PM
I ended up "solving" it by creating a symlink where Go expects the generated protobufs to be located that points to the relative path of the output of
export-codegen
. Pants is happy,
go mod
is happy, my IDE is happy, so good enough for me πŸ™‚
πŸŽ‰ 1
s

silly-spring-18687

07/25/2023, 11:21 PM
Thanks so much! I was pulling my hair out over this πŸ™‚
πŸ™Œ 1