[go] cmd/go/internal/cfg: pass arch specific envs as build tags

2 views
Skip to first unread message

Sean Liao (Gerrit)

unread,
May 16, 2026, 6:06:00 PMMay 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Sean Liao has uploaded the change for review

Commit message

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
Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964

Change diff

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() {}

Change information

Files:
  • M src/cmd/go/internal/cfg/cfg.go
  • A src/cmd/go/testdata/script/list_goarch.txt
Change size: S
Delta: 2 files changed, 34 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
Gerrit-Change-Number: 778622
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
May 16, 2026, 6:40:27 PMMay 16
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Keith Randall, Michael Matloob and Sean Liao

Sean Liao uploaded new patchset

Sean Liao uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • Michael Matloob
  • Sean Liao
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
Gerrit-Change-Number: 778622
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: Michael Matloob <mat...@golang.org>
Gerrit-Attention: Sean Liao <se...@liao.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Matloob (Gerrit)

unread,
Jul 18, 2026, 2:01:26 PM (3 days ago) Jul 18
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
Attention needed from Keith Randall and Sean Liao

Michael Matloob added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Michael Matloob . resolved

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?

Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • Sean Liao
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
    Gerrit-Change-Number: 778622
    Gerrit-PatchSet: 2
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Comment-Date: Sat, 18 Jul 2026 18:01:22 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Michael Matloob (Gerrit)

    unread,
    2:46 PM (8 hours ago) 2:46 PM
    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Sean Liao

    Michael Matloob voted Code-Review+2

    Code-Review+2
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Sean Liao
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
    Gerrit-Change-Number: 778622
    Gerrit-PatchSet: 2
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Comment-Date: Tue, 21 Jul 2026 18:46:17 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Carlos Amedee (Gerrit)

    unread,
    5:28 PM (5 hours ago) 5:28 PM
    to goph...@pubsubhelper.golang.org, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Sean Liao

    Carlos Amedee voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Sean Liao
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
    Gerrit-Change-Number: 778622
    Gerrit-PatchSet: 2
    Gerrit-Owner: Sean Liao <se...@liao.dev>
    Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Sean Liao <se...@liao.dev>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Sean Liao <se...@liao.dev>
    Gerrit-Comment-Date: Tue, 21 Jul 2026 21:28:19 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Cherry Mui (Gerrit)

    unread,
    7:28 PM (3 hours ago) 7:28 PM
    to goph...@pubsubhelper.golang.org, Carlos Amedee, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Sean Liao

    Cherry Mui voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Sean Liao
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
      Gerrit-Change-Number: 778622
      Gerrit-PatchSet: 2
      Gerrit-Owner: Sean Liao <se...@liao.dev>
      Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Sean Liao <se...@liao.dev>
      Gerrit-Comment-Date: Tue, 21 Jul 2026 23:28:17 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      open
      diffy

      Sean Liao (Gerrit)

      unread,
      7:41 PM (3 hours ago) 7:41 PM
      to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Cherry Mui, Carlos Amedee, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com

      Sean Liao submitted the change

      Change information

      Commit message:
      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
      Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
      Files:
      • M src/cmd/go/internal/cfg/cfg.go
      • A src/cmd/go/testdata/script/list_goarch.txt
      Change size: S
      Delta: 2 files changed, 34 insertions(+), 0 deletions(-)
      Branch: refs/heads/master
      Submit Requirements:
      Open in Gerrit
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: merged
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ib1dd4c1d18c49d12de1a6c99d1a15be96a6a6964
      Gerrit-Change-Number: 778622
      Gerrit-PatchSet: 3
      open
      diffy
      satisfied_requirement
      Reply all
      Reply to author
      Forward
      0 new messages