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

x/tools/gopls: build tags not working #51111

Open
syncjuncture opened this issue Feb 9, 2022 · 6 comments
Open

x/tools/gopls: build tags not working #51111

syncjuncture opened this issue Feb 9, 2022 · 6 comments
Labels
gopls/metadata gopls Tools
Milestone

Comments

@syncjuncture
Copy link

@syncjuncture syncjuncture commented Feb 9, 2022

gopls version

Build info

golang.org/x/tools/gopls v0.7.5
golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
github.com/BurntSushi/toml@v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/mod@v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sys@v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd h1:lTnuArxJC+n54TyvWUPyHhrnGxYvhSi13/aM2Ndr4bs=
golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
honnef.co/go/tools@v0.2.1 h1:/EPr//+UMMXwMTkXvCCoaJDq8cpjMO80Ou+L4PDo2mY=
mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=


### go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sj/.cache/go-build"
GOENV="/home/sj/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/sj/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sj/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build2370694384=/tmp/go-build -gno-record-gcc-switches"


### What did you do?

- Create a new package with multiple build tags for different platforms.

  - Windows:
```go
//go:build windows

package pkgname
...
  • Linux:
//go:build linux

package pkgname
...
  • Darwin:
//go:build darwin

package pkgname
...
  • Main:
package pkgname
...

What did you expect to see?

The GOOS build tags are predefined by Go itself; therefore, gopls (go list) should not display this:

No packages found for open file /home/sj/proj/test/pkgname/pkgname_windows.go: <nil>.
If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlags" 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). go list

What did you see instead?

No packages found for open file /home/sj/proj/test/pkgname/pkgname_windows.go: <nil>.
If this file contains build tags, try adding "-tags=<build tag>" to your gopls "buildFlags" 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). go list

Editor and settings

None

Logs

@gopherbot gopherbot added Tools gopls labels Feb 9, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 9, 2022
@syncjuncture syncjuncture changed the title x/tools/gopls: x/tools/gopls: build tags not working Feb 9, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented Feb 10, 2022

Hi, thanks for filing. Build tags are certainly a pain point with gopls, but I'm not sure I understand the expectation here.

The GOOS build tags are predefined by Go itself; therefore, gopls (go list) should not display this:

Your GOOS is linux, not windows, which is why a file pkgname_windows.go is not contained in packages loaded with go list. Can you clarify what you expect to happen?

@suzmue suzmue added the WaitingForInfo label Feb 11, 2022
@syncjuncture syncjuncture reopened this Mar 20, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 20, 2022

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@syncjuncture
Copy link
Author

@syncjuncture syncjuncture commented Mar 20, 2022

Hi, thanks for filing. Build tags are certainly a pain point with gopls, but I'm not sure I understand the expectation here.

The GOOS build tags are predefined by Go itself; therefore, gopls (go list) should not display this:

Your GOOS is linux, not windows, which is why a file pkgname_windows.go is not contained in packages loaded with go list. Can you clarify what you expect to happen?

Is there any workaround to resolve this issue?

@syncjuncture
Copy link
Author

@syncjuncture syncjuncture commented Mar 20, 2022

I expect it to detect that pre-defined build constraints and not complain specifically about them. I have tried assigning go.buildTags to windows (same goes for windows,linux,darwin) in .vscode/settings.json, this seems to suppress the warning; however, multiple declarations for packages that contain build constraints seem to throw an error:

doSomething redeclared in this block

@syncjuncture
Copy link
Author

@syncjuncture syncjuncture commented Mar 20, 2022

@gopherbot @findleyr ping, the bot has closed the issue.

@findleyr findleyr removed the WaitingForInfo label Apr 1, 2022
@findleyr findleyr reopened this Apr 1, 2022
@suzmue suzmue removed this from the Unreleased milestone Apr 4, 2022
@suzmue suzmue added this to the gopls/on-deck milestone Apr 4, 2022
@findleyr findleyr added the gopls/metadata label Apr 11, 2022
@findleyr
Copy link
Contributor

@findleyr findleyr commented May 18, 2022

I think we need to improve our documentation for how to properly set GOOS, build tags, etc.
@hyangah is also working on making environment easier to edit in VS Code, which would align with this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/metadata gopls Tools
Projects
None yet
Development

No branches or pull requests

4 participants