Skip to content
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

Go codegen doesn't work #21529

Open
rdeknijf opened this issue Oct 16, 2024 · 5 comments · May be fixed by #21614
Open

Go codegen doesn't work #21529

rdeknijf opened this issue Oct 16, 2024 · 5 comments · May be fixed by #21614
Labels
backend: Go Go backend-related issues bug

Comments

@rdeknijf
Copy link

Go codegen doesn't work

$ pants export-codegen ::

11:11:48.11 [ERROR] 1 Exception encountered:

Engine traceback:
in `export-codegen` goal

ProcessExecutionFailure: Process 'Build Go gRPC protobuf plugin for `protoc`.' failed with exit code 1.
stdout:

stderr:
go: google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0: loading deprecation for google.golang.org/grpc/cmd/protoc-gen-go-grpc: module lookup disabled by GOPROXY=off

So, export-codegen doesn't work. Also, the docs describe that Pants auto-regenerates any protobuf output. But it doesn't.
If you remove the pkg/person.pb.go file, and run

pants test :: tests fail. If you run protoc --go_out=. --go_opt=paths=source_relative person.proto` 

(in pkg), tests are good again.

So, about GOPROXY: I've tried setting it multiple ways, but Pants seems to ignore it all. I think there may be a relation with: #21527

Pants version
Tested on 2.22 and 2.23

OS
Both Linux and Mac.

Additional info
Here's a minimal reproduction repo: https://github.com/rdeknijf/pants-repro-protoc

@rdeknijf rdeknijf added the bug label Oct 16, 2024
@tdyas tdyas added the backend: Go Go backend-related issues label Oct 21, 2024
@tdyas
Copy link
Contributor

tdyas commented Oct 21, 2024

Based on my initial investigation, this seems to be caused by go wanting to check the latest version of the protoc-gen-go-grpc module's go.mod to see if it has any deprecation comments. Given the Go backend ordinarily sets GOPROXY=off to prevent networks calls to the Go module proxy, that setting will prevent go from being able to contact the Go module proxy to get deprecation information for the google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0 module.

The GOPROXY=off setting only makes sense though when the Go backend is building and linking Go code which has already been resolved to sources. The Go protobuf backend just invokes go install which does all the building and linking of a binary. In that case, it doesn't make sense to set GOPROXY=off.

See:

Get(
ProcessResult,
GoSdkProcess(
[
"install",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0",
],
input_digest=download_sources_result.output_digest,
output_files=["gopath/bin/protoc-gen-go-grpc"],
description="Build Go gRPC protobuf plugin for `protoc`.",
),
),

The rules for GoSdkProcess are what set GOPROXY=off. See

else FrozenDict({**(env or {}), "GOPROXY": "off"})
.

Probably just need to set allow_downloads=True on the use of GoSdkProcess and that will avoid setting GOPROXY=off.

@geoah
Copy link

geoah commented Nov 4, 2024

Are there any known workarounds to get export-codegen working with go at the moment?

@tdyas
Copy link
Contributor

tdyas commented Nov 5, 2024

Are there any known workarounds to get export-codegen working with go at the moment?

@geoah: Are you able to run Pants from sources and try out #21614 to see if it works for you?

@geoah
Copy link

geoah commented Nov 5, 2024

@tdyas I'll try to get this done in the next 24h and get back to you! Thank you for looking into this!

@tdyas
Copy link
Contributor

tdyas commented Nov 19, 2024

@geoah: Any word on whether this worked for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Go Go backend-related issues bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants