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

Saving (with automatic build) a new .go file results in "/usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied" #568

Closed
andreagrandi opened this issue Aug 24, 2020 · 5 comments

Comments

@andreagrandi
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.15 darwin/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.48.1 3dd905126b34dcd4de81fa624eb3a8cbe7485f13 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.16.1
  • Run go env to get the go development environment details
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/andrea/Library/Caches/go-build"
GOENV="/Users/andrea/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/andrea/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andrea/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v7/p2rlmknn79g8l2772yyqnp6w0000gn/T/go-build964988215=/tmp/go-build -gno-record-gcc-switches -fno-common"

Share the Go related settings you have added/edited

"go.autocompleteUnimportedPackages": true,
"go.formatTool": "goimports"

Describe the bug

On MacOS, after having installed Go 1.15 from the official package and having configured PATH etc... if you try to create a new Go app with VSCode and auto build kick in (as it should), you get an error mentioning "/usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied"

I originally commented this bug golang/go#37962 but they mentioned this happens because VSCode Go extension still uses the -i option.

I was able to workaround the problem by running this sudo chown -R andrea /usr/local/go/pkg/darwin_amd64/ but I think it would be nice if this issue didn't happen at all.

Steps to reproduce the behavior:

  1. install Go 1.15 on MacOS using the official installer
  2. create a new project on VSCode with Go extension
  3. write any meaningful code that can compile
  4. you will see a red underlining below package main (note: if you go build . the code compiles just fine).

Screenshots or recordings

Screenshot 2020-08-22 at 15 46 26

Related issues

@jayconrod
Copy link

To explain what's going on here to anyone not following the related issues:

  • The official Go installers and systemwide package management systems like Homebrew install Go in a GOROOT directory that's owned by root.
  • This is fine unless you need to rebuild and reinstall std packages into GOROOT. Since Go 1.10, packages are built and stored in the user's build cache, so you almost never need to install them.
  • The go build -i flag specifically asks the go command to reinstall the named packages and their dependencies. That causes a permission error here because the user doesn't have permission to write to that directory.

I don't think there's a good reason for vscode-go to use the -i flag anymore. In microsoft/vscode-go#2836, it was decided to continue using it for compatibility with github.com/mdempsky/gocode in GOPATH mode. I think we should reconsider that, at least in module mode.

@hyangah
Copy link
Contributor

hyangah commented Aug 24, 2020

Available workaround is to set go.installDependenciesWhenBuilding to false.

But if the analysis in microsoft/vscode-go#2836 is still true, gocode will stop working without -i flag. Does it mean that gocode is completely broken even in GOPATH mode with the recent go releases? @jayconrod

@jayconrod
Copy link

I don't think anything has changed in recent Go releases that would make GOROOT read-only for users. As far as I know, that's always been the case when Go is installed with an installer or a systemwide package management system.

It's possible that we've gotten pickier about when cgo packages need to be rebuilt. They should be rebuilt whenever their cache key changes, and small things like upgrading the C compiler or changing flags could trigger that.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/251263 mentions this issue: package.json: disable go.installDependenciesWhenBuilding by default

@hyangah hyangah added this to the v0.17.0 milestone Sep 10, 2020
@squalsoft
Copy link

squalsoft commented Sep 14, 2020

Just set "go.installDependenciesWhenBuilding": false in VsCode settings. Will be fixed soon.

@golang golang locked and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants