golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.84k stars 735 forks source link

Install gopls with CGO disabled #3088

Closed hyangah closed 8 months ago

hyangah commented 8 months ago

Cgo is unnecessary to build gopls (and probably some of other tools). Disable cgo (CGO_ENABLED=0), to avoid crashes (https://github.com/golang/vscode-go/issues/3085, https://github.com/golang/vscode-go/issues/3039, https://github.com/golang/go/issues/63997) caused by misconfigured C toolchain.

hyangah commented 8 months ago

I think most tools VS Code Go depends on don't need CGO. (@derekparker @aarzilli Is it ok to use dlv compiled with CGO_ENABLED=0?)

hyangah commented 8 months ago

From my mac,

$ go list -f '{{if .CgoFiles}}{{.ImportPath}}{{end}}' -deps ./cmd/dlv
runtime/cgo
net

I think disabling CGO will be ok.

aarzilli commented 8 months ago

It should be fine everywhere except freebsd.

gopherbot commented 8 months ago

Change https://go.dev/cl/549245 mentions this issue: src/goEnv: disable Cgo when building tools

hyangah commented 8 months ago

According to @findleyr, gopls's CGO dependency was real (fastwalk). The dependency is removed from the dev branch so once gopls v0.15 is released next year, this problem will go away. Delve and other tools don't have CGO dependency, so the go command won't rely on the CGO and we don't need to worry about it.

I will abandon the cl.