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: go related environment set explicitly in go tool #70544

Closed
seankhliao opened this issue Nov 24, 2024 · 3 comments
Closed

cmd/go: go related environment set explicitly in go tool #70544

seankhliao opened this issue Nov 24, 2024 · 3 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@seankhliao
Copy link
Member

seankhliao commented Nov 24, 2024

Go version

go version devel go1.24-8397de2241 2024-11-23 00:23:59 +0000 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='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS='-trimpath "-ldflags=-s -w" -vet=all'
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build303055721=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/user/tmp/testrepo0901/go.mod'
GOMODCACHE='/home/user/.data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/.data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='path'
GOTOOLDIR='/home/user/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-8397de2241 2024-11-23 00:23:59 +0000'
GOWORK=''
PKG_CONFIG='pkg-config'

Explicitly set environment with go env -changed:

CGO_ENABLED='0'
GOAMD64='v3'
GOFLAGS='-trimpath "-ldflags=-s -w" -vet=all'
GOTOOLCHAIN='path'

What did you do?

https://go.dev/play/p/Apul33WDA2L

With a tool that reads the environment, run it via run vs tool:

go run ./mytool > env.old
go tool mytool > env.new
diff env.old env.new

results:

1a2
> AR=ar
6a8
> CC=gcc
8a11
> CGO_ENABLED=0
12a16
> CXX=g++
20a25,26
> GCCGO=gccgo
> GCM_INTERACTIVE=never
22a29,30
> GIT_SSH_COMMAND=ssh -o ControlMaster=no -o BatchMode=yes
> GIT_TERMINAL_PROMPT=0
23a32,42
> GOAMD64=v3
> GOARCH=amd64
> GOAUTH=netrc
> GOCACHE=/home/user/.cache/go-build
> GOENV=/home/user/.config/go/env
> GOFIPS140=off
> GOFLAGS=-trimpath "-ldflags=-s -w" -vet=all
> GOHOSTARCH=amd64
> GOHOSTOS=linux
> GOMODCACHE=/home/user/.data/go/pkg/mod
> GOOS=linux
24a44
> GOPROXY=https://proxy.golang.org,direct
25a46,51
> GOSUMDB=sum.golang.org
> GOTELEMETRY=on
> GOTELEMETRYDIR=/home/user/.config/go/telemetry
> GOTOOLCHAIN=path
> GOTOOLDIR=/home/user/sdk/gotip/pkg/tool/linux_amd64
> GOVERSION=devel go1.24-8397de2241 2024-11-23 00:23:59 +0000

What did you see happen?

go related environment variables are all explicitly set

What did you expect to see?

go envs aren't set.

For context, I wanted to use https://github.com/ko-build/ko for building multi platform container images, however, it refuses to run due to conflicting configuration of single vs multiple target platforms:

$ go tool ko apply ./cmd/moo
Error: error creating builder: error setting up builder options: cannot use --platform or defaultPlatforms in .ko.yaml or env KO_DEFAULTPLATFORMS combined with GOOS="linux"
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Nov 24, 2024
@seankhliao seankhliao added this to the Go1.24 milestone Nov 24, 2024
@seankhliao
Copy link
Member Author

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/631836 mentions this issue: cmd/go: use AppendPath(OrigEnv) as env for tool executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants