bazel-contrib / bazel-contrib/rules_go

rules_go 0.40+ broke gopls resolving stdlib imports in VS code

Open
#3,741 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

Tested with 0.40.1 and 0.42

### What version of gazelle are you using?

0.31.1 and 0.33

### What version of Bazel are you using?

6.4.0

### Does this issue reproduce with the latest releases of all the above?

Yes

### What operating system and processor architecture are you using?

Linux amd64

### Any other potentially useful information about your toolchain?

Tested with gopls 0.13.2 and 0.14.1.

Using these settings in VS code:

```json
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk/",
"go.toolsEnvVars": {
"GOPROXY": "off",
"GOPACKAGESDRIVER": "${workspaceFolder}/scripts/gopackagesdriver.sh",
},
"gopls": {
"build.directoryFilters": [
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-bazel-${workspaceFolderBasename}"
],
[...]
},
```

and this `gopackagesdriver.sh`:

```shell
#!/bin/sh

bazel="$(command -v bazel || command -v bazelisk)"
# reset GOPROXY to default
unset GOPROXY

# don't fetch internal stuff
export GOPRIVATE="[...]*"

exec "${bazel}" run -- @io_bazel_rules_go//go/tools/gopackagesdriver "$@"
```

### What did you do?

Updated rules_go from 0.39.1 to 0.42 (and then later backtracked the problem to 0.40)

### What did you expect to see?

gopls is able to resolve stdlib imports in VS code as before.

### What did you see instead?

A lot of import errors in the format of `could not import $PKG (cannot find packge "$PKG" in GOROOT or GOPATH)`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the listed rules_go, Gazelle, Bazel, gopls, and VS Code versions using scripts/gopackagesdriver.sh and the @io_bazel_rules_go//go/tools/gopackagesdriver entry point. Compare behavior between rules_go 0.39.1 and 0.40+; done means gopls resolves standard-library imports without the reported GOROOT or GOPATH errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, shell, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.