Thanks to visit codestin.com
Credit goes to github.com

Skip to content

go/build: GOAMD64 in env file not setting subarch build tags #75452

@cookieo9

Description

@cookieo9

Go version

go version go1.25.1 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/gopher/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/gopher/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2805719706=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/gopher/amd64v3test/go.mod'
GOMODCACHE='/home/gopher/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/gopher/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/gopher/sdk/go1.25.1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/gopher/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/gopher/sdk/go1.25.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

  • Use go env -w GOAMD64=v3 to set the GOAMD64 env value user-wide.
  • Checked that go env GOAMD64 shows v3. (Also in full go env output)
  • Created a file requiring the amd64.v3 build constraint:
//go:build amd64.v3
// +build amd64.v3

package main

import "fmt"

func main() {
	fmt.Println("GOAMD64=v3: available")
}
  • Run go build (or any other command that respects build tags)

What did you see happen?

The toolchain acts as though the GOAMD64 variable wasn't set resulting in the amd64.v3 constraint not being satisfied, excluding the file from the build. When it's the only file:

$ go build
package amd64v3test: build constraints exclude all Go files in /home/gopher/amd64v3test

What did you expect to see?

I expected to see a successful build that includes the file. It does work if the GOAMD64 environment variable is set in the shell, suggesting I got the build constraint and syntax correct:

$ GOAMD64=v3 go build
// Successful build

Similarly looking at go list -json shows such files are ignored when the value is set using the config file, but not when set by the environment.

I only tested GOAMD64, but I suspect it may also affect other "subarch" style build constraints (like GOARM).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions