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

settings: go.goroot does not override GOROOT environment variable #776

Closed
zhiqiangxu opened this issue Oct 13, 2020 · 8 comments
Closed
Assignees
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@zhiqiangxu
Copy link

zhiqiangxu commented Oct 13, 2020

In my settings.json, I've to manually set the PATH in go.toolsEnvVars:

    "go.gopath": "/Users/xuzhiqiang/.gvm/pkgsets/go1.15/global",
    "go.goroot": "/Users/xuzhiqiang/.gvm/gos/go1.15",
    "go.toolsEnvVars": {
        "PATH": "/Users/xuzhiqiang/.gvm/gos/go1.15/bin/"
    },

otherwise vscode will report:

cannot find module providing package crypto/ed25519

which is caused by selecting my default go version of go1.12(crypto/ed25519 is introduced in go1.13)

It's should automatically infer the correct go path( in my case /Users/xuzhiqiang/.gvm/gos/go1.15/bin/ ) based on go.gopath and go.goroot

@hyangah
Copy link
Contributor

hyangah commented Oct 13, 2020

@zhiqiangxu thanks for the report. What's the extension version? The extension should choose go from /Users/xuzhiqiang/.gvm/gos/go1.15/bin and "go.toolsEnvVars.PATH" shouldn't affect the extension's choice of Go at all.

I am wildly guessing the extension passed a wrong PATH when invoking other tools.

  1. Do you know what activities trigger the error message? (e.g. tools installation, running go build or test, debug, ...?)
  2. What does Go: Locate Configured Go Tools report without "go.toolsEnvVars" setting?
  3. Does the go version shown in the status bar (bottom of the window) correctly show 1.15?

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 13, 2020
@zhiqiangxu
Copy link
Author

zhiqiangxu commented Oct 14, 2020

Sorry for late response!

  1. I don't know what triggers, I see this message when mouse hover over module xxx in go.mod
  2. here is what's reported:
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/xuzhiqiang/.gvm/pkgsets/go1.15/global
GOROOT: /Users/xuzhiqiang/.gvm/gos/go1.12
PATH: /Users/xuzhiqiang/.gvm/gos/go1.12/bin:/Users/xuzhiqiang/.wasmtime/bin:/Users/xuzhiqiang/.cargo/bin:/usr/local/opt/mysql-client/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party/cocos2d-x/templates:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party:/Users/xuzhiqiang/.gvm/pkgsets/go1.10/global/src/github.com/zhiqiangxu/client2/third_party/cocos2d-x/tools/cocos2d-console/bin:/Users/xuzhiqiang/.cargo/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin:/Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/overlay/bin:/Users/xuzhiqiang/.gvm/bin:/Users/xuzhiqiang/.gvm/bin:/Users/xuzhiqiang/.cargo/bin:/Users/xuzhiqiang/.rvm/gems/ruby-2.3.0/bin:/Users/xuzhiqiang/.rvm/gems/ruby-2.3.0@global/bin:/Users/xuzhiqiang/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/.rvm/bin:/Users/xuzhiqiang/Downloads/flutter/bin:/Users/xuzhiqiang/Desktop/workspace/vagrant/java/build/apache-maven-3.5.0/bin/:/Users/xuzhiqiang/bin/:/usr/local/Cellar/protobuf/3.3.0/bin:/Users/xuzhiqiang/bin/dex2jar-2.1-SNAPSHOT:/Users/xuzhiqiang/Library/Android/sdk/platform-tools:/Users/xuzhiqiang/.luarocks/bin/:/Users/xuzhiqiang/Downloads/flutter/bin/cache/dart-sdk/bin

   gocode: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gocode installed
   gopkgs: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gopkgs installed
   go-outline: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/go-outline installed
   go-symbols: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/go-symbols installed
   guru: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/guru installed
   gorename: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gorename installed
   gotests: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gotests installed
   gomodifytags: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gomodifytags installed
   impl: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/impl installed
   fillstruct: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/fillstruct installed
   goplay: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/goplay installed
   godoctor: godoctor not installed
   dlv: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/dlv installed
   gocode-gomod: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/gocode-gomod installed
   godef: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/godef installed
   goimports: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/goimports installed
   golint: /Users/xuzhiqiang/.gvm/pkgsets/go1.12/global/bin/golint installed
   gopls: /Users/xuzhiqiang/.gvm/pkgsets/go1.15/global/bin/gopls installed

go env
Workspace Folder (flash-pool): /Users/xuzhiqiang/Desktop/workspace/opensource/rust_exp/flash-pool
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/Users/xuzhiqiang/Library/Caches/go-build"
	GOENV="/Users/xuzhiqiang/Library/Application Support/go/env"
	GOEXE=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="darwin"
	GOINSECURE=""
	GOMODCACHE="/Users/xuzhiqiang/.gvm/pkgsets/go1.15/global/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="darwin"
	GOPATH="/Users/xuzhiqiang/.gvm/pkgsets/go1.15/global"
	GOPRIVATE=""
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/Users/xuzhiqiang/.gvm/gos/go1.12"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/Users/xuzhiqiang/.gvm/gos/go1.12/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/ym/c42xcdhn78g0s97z3ycj2yw00000gn/T/go-build491264557=/tmp/go-build -gno-record-gcc-switches -fno-common"
	
  1. go version seems file.

Seems GOROOT isn't changed somehow.

UPDATE

I found another issue: if the go project is embedded into a sub directory of a rust project, .vscode/settings.json seems not taking effect at all.

@hyangah
Copy link
Contributor

hyangah commented Oct 14, 2020

@zhiqiangxu thanks for the updates. Based on the log, VSCode Go is seeing GOROOT: /Users/xuzhiqiang/.gvm/gos/go1.12 as the GOROOT. You said the go version displayed in the status bar is still 1.15, right? That's puzzling.
I wonder if VSCode ran with the GOROOT environment variable that points to go1.12. (The extension changes the go binary search path but does not change the GOROOT env var even with go.goroot :-()

Can you open the developer tools and check the environment variables from there to make sure GOROOT is not set?

Command Palette -> Developer: Toggle Developer Tools -> this will open the developer tools window.
-> Select Console tab -> enter process.env["GOROOT"]

This should be undefined.

(Nightly version](https://github.com/golang/vscode-go/blob/master/docs/nightly.md) has an option to enable more logging ("go.logging.level": "verbose" in settings.json) that prints how the extension mutates the current GOROOT and chooses the binary.

Re: .vscode/settings.json location - .vscode directory must be under the project root directory (the directory you opened with vscode) and that's working as intended.

@zhiqiangxu
Copy link
Author

zhiqiangxu commented Oct 15, 2020

Ah , process.env["GOROOT"] is /Users/xuzhiqiang/.gvm/gos/go1.12 in my PC.

Shouldn't the go.goroot in settings.json override the process.env["GOROOT"](just like go.gopath overrides $GOPATH env)?

About the embeded case, the .vscode/settings.json is under the project root directory, but the root project is rust, and the go.mod lies under a sub directory of the root project, in this case, .vscode/settings.json is not working as expected.

@hyangah hyangah changed the title vscode-go not choosing the correct path settings: go.goroot does not override GOROOT environment variable Oct 15, 2020
@hyangah
Copy link
Contributor

hyangah commented Oct 15, 2020

@zhiqiangxu Yes, go.goroot does not override the GOROOT environment variable any more but we choose the go command from the specified goroot directory. The reasoning was that setting GOROOT env var isn't a good idea in most cases, and the real GOROOT should be chosen by the go command itself. (Mismatching the go's GOROOT and GOROOT env var historically caused many issues). But it looks like we should revisit this decision and evaluate more use cases.

Can you please tell us why you needed to set GOROOT environment variable?

Re: .vscode/settings.json, yeah, that's unfortunate - gopls team is currently working on addressing the limitation so users can open the workspace from the true project root directory. Until then, either create .vscode/settings.json under the go directory, or consider moving go.mod to the project root.

@zhiqiangxu
Copy link
Author

zhiqiangxu commented Oct 15, 2020

I'm using gvm to manage multiple go versions, and it internally sets GOROOT environment variable.

UPDATE

This is the tool I'm using: https://github.com/moovweb/gvm

@hyangah
Copy link
Contributor

hyangah commented Apr 14, 2021

Thanks @zhiqiangxu

We were trying to deprecate go.goroot and recommend setting through go.toolsEnvVars.GOROOT. But soon realized that go.toolsEnvVars is resource-scoped - so env vars like CGO_CFLAGS can be sharable. But for GOROOT, machine-overridable scope is more suitable than resource scope. It's unfortunate that there are many different ways to configure GOROOT, especially messing with GOROOT isn't recommended any more. (I think gvm should stop using/setting GOROOT).

I will try to resurrect GOROOT setting through go.goroot, but with a description of discouraging its use.

@hyangah hyangah added NeedsFix The path to resolution is known, but the work has not been done. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 14, 2021
@hyangah hyangah self-assigned this Apr 14, 2021
@hyangah
Copy link
Contributor

hyangah commented May 14, 2021

It was released as part of v0.25.0. I forgot to link the change
https://go-review.googlesource.com/c/vscode-go/+/310853
commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants