Skip to content

x/tools/gopls: support multiple sets of GOOS/GOARCH/build tags #42028

@BenLubar

Description

@BenLubar

What version of Go are you using (go version)?

$ go version
go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

Yes (this is a feature request, not a bug report)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/ben/go/bin"
GOCACHE="/home/ben/.cache/go-build"
GOENV="/home/ben/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ben/.golang-path/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ben/.golang-path"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.15"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.15/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ben/src/games/spy-cards/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build868210400=/tmp/go-build -gno-record-gcc-switches"

Explanation

My program has multiple implementations of certain functions, separated by build tags. For example, a function might have implementations for js && wasm && !headless, (!js || !wasm) && !headless, and headless.

Right now, I need to define GOOS, GOARCH, and a set of build tags for the entire project, which results in files that don't match those tags giving this message:

No packages found for open file /home/ben/src/games/spy-cards/room/render_app.go: <nil>. If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlag" configuration (see (https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string). Otherwise, see the troubleshooting guidelines for help investigating (https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md).

Additionally, linter errors (and possibly also compiler errors?) are not reported for files that don't match the project-wide build tags.

It would be nice to be able to define multiple build contexts for live error reporting and have the "no packages found" error be ignored if any of the build contexts included the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions