cmd/go/internal/cfg: pass arch specific envs as build tags
cmd/compile uses internal/buildcfg directly for reading the
arch specific envs, which only reads from the environment
and not cmd/go's GOENV config file.
Setting the build context build tag allows both build and list
operations to select the right files.
Fixes #73294
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index a4edd85..d7405d4 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -133,6 +133,11 @@
}
ctxt.ToolTags = save
+ _, archEnv, _ := GetArchEnv()
+ if archEnv != "" {
+ ctxt.BuildTags = append(ctxt.BuildTags, Goarch+"."+archEnv)
+ }
+
// The go/build rule for whether cgo is enabled is:
// 1. If $CGO_ENABLED is set, respect it.
// 2. Otherwise, if this is a cross-compile, disable cgo.
diff --git a/src/cmd/go/testdata/script/list_goarch.txt b/src/cmd/go/testdata/script/list_goarch.txt
new file mode 100644
index 0000000..96169d6
--- /dev/null
+++ b/src/cmd/go/testdata/script/list_goarch.txt
@@ -0,0 +1,29 @@
+
+# default GOAMD64=v1
+env GOARCH=amd64
+! go list -f '{{ range $f := .GoFiles }}{{ $f }}{{ end }}'
+! go build
+
+# settable from the environment
+env GOAMD64=v3
+go list -f '{{ range $f := .GoFiles }}{{ $f }}{{ end }}'
+stdout main.go
+go build
+
+# settable from the config file
+env GOAMD64=
+env GOENV=$WORK/env
+go env -w GOAMD64=v3
+go list -f '{{ range $f := .GoFiles }}{{ $f }}{{ end }}'
+stdout main.go
+go build
+
+-- go.mod --
+module test
+
+-- main.go --
+//go:build amd64.v3
+
+package main
+
+func main() {}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Added a comment to the issue. Do we have the format of the build tags documented somewhere or do we pass them in other cases?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
cmd/go/internal/cfg: pass arch specific envs as build tags
cmd/compile uses internal/buildcfg directly for reading the
arch specific envs, which only reads from the environment
and not cmd/go's GOENV config file.
Setting the build context build tag allows both build and list
operations to select the right files.
Fixes #73294
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |