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

cmd/go: cannot find package when importing dependencies with the unix build constraint #54712

Closed
wizardishungry opened this issue Aug 28, 2022 · 6 comments
Assignees
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wizardishungry
Copy link

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

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

I don't know if this reproduces in gotip.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/tmp/go-build-jon"
GOENV="/home/jon/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jon/.asdf/installs/golang/1.19/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jon/.asdf/installs/golang/1.19/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jon/.asdf/installs/golang/1.19/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jon/.asdf/installs/golang/1.19/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jon/src/tmp/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2789217673=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://go.dev/play/p/vhnTI8FhFJE
Doesn't reproduce in the playground.

What did you expect to see?

My program runs.

What did you see instead?

main.go:6:2: cannot find package

If I change unix to linux, it works.
If I remove the build constraint, it works.
If I remove the references to golang.org/x/sync/singleflight, it works.

Per go help buildconstraint:

During a particular build, the following build tags are satisfied:

   - the target operating system, as spelled by runtime.GOOS, set with the
     GOOS environment variable.
   - the target architecture, as spelled by runtime.GOARCH, set with the
     GOARCH environment variable.
   - "unix", if GOOS is a Unix or Unix-like system.
@gopherbot
Copy link

Change https://go.dev/cl/426296 mentions this issue: cmd/go/internal/imports: recognize "unix" build tag

@ZekeLu
Copy link
Contributor

ZekeLu commented Aug 28, 2022

It seems that https://go.dev/cl/389934 forgot to change src/cmd/go/internal/imports/build.go, which is copied from src/go/build/build.go, src/go/build/syslist.go. I have sent https://go.dev/cl/426296 to change that file and add a regression test.

@bcmills bcmills added the GoCommand cmd/go label Aug 29, 2022
@bcmills
Copy link
Contributor

bcmills commented Aug 29, 2022

Doesn't reproduce in the playground.

It does if you add a go.mod file with an explicit dependency and a recent go version! 🙂

https://go.dev/play/p/A9PbFemDPD-?v=gotip

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 29, 2022
@bcmills bcmills added this to the Go1.20 milestone Aug 29, 2022
@bcmills bcmills changed the title build: problem importing go modules when using "unix" build constraint cmd/go: cannot find package when importing dependencies with the unix build constraint Aug 29, 2022
@bcmills
Copy link
Contributor

bcmills commented Aug 29, 2022

@gopherbot, please backport to Go 1.19. This is a subtle bug in a feature introduced in Go 1.19, and the fix in Go 1.20 will mask spurious build failures that users on Go 1.19 will run into.

@gopherbot
Copy link

Backport issue(s) opened: #54736 (for 1.19), #54737 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link

Change https://go.dev/cl/426814 mentions this issue: [release-branch.go1.19] cmd/go/internal/imports: recognize "unix" build tag

gopherbot pushed a commit that referenced this issue Aug 30, 2022
…ld tag

For #20322
For #51572
Updates #54712
Fixes #54736

Change-Id: I22fcfa820e83323bfdf1a40deee7286240f02b3e
GitHub-Last-Rev: cd2c653
GitHub-Pull-Request: #54716
Reviewed-on: https://go-review.googlesource.com/c/go/+/426296
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
(cherry picked from commit 3c6a5cd)
Reviewed-on: https://go-review.googlesource.com/c/go/+/426814
Run-TryBot: Bryan Mills <bcmills@google.com>
bradfitz pushed a commit to tailscale/go that referenced this issue Sep 8, 2022
…ld tag

For golang#20322
For golang#51572
Updates golang#54712
Fixes golang#54736

Change-Id: I22fcfa820e83323bfdf1a40deee7286240f02b3e
GitHub-Last-Rev: cd2c653
GitHub-Pull-Request: golang#54716
Reviewed-on: https://go-review.googlesource.com/c/go/+/426296
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
(cherry picked from commit 3c6a5cd)
Reviewed-on: https://go-review.googlesource.com/c/go/+/426814
Run-TryBot: Bryan Mills <bcmills@google.com>
@golang golang locked and limited conversation to collaborators Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants