Skip to content

Commit fefac44

Browse files
rscgopherbot
authored andcommitted
go/build: add GO$GOARCH-based ToolTags
Implement proposal #45454, providing build tags based on the sub-architecture information in the GO$GOARCH variable (for example, GOARM for GOARCH=arm). For example, when GOAMD64=v2, the additional build tags amd64.v1 and amd64.v2 are defined to be true. Fixes #45454. Change-Id: I7be56060d47fc61843b97fd8a78498e8202c1ee7 Reviewed-on: https://go-review.googlesource.com/c/go/+/421434 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 0063b9b commit fefac44

File tree

4 files changed

+114
-12
lines changed

4 files changed

+114
-12
lines changed

src/cmd/go/internal/cfg/cfg.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ func defaultContext() build.Context {
9393
ctxt.GOOS = Goos
9494
ctxt.GOARCH = Goarch
9595

96-
// ToolTags are based on GOEXPERIMENT, which we will parse and
97-
// initialize later.
98-
ctxt.ToolTags = nil
96+
// Clear the GOEXPERIMENT-based tool tags, which we will recompute later.
97+
var save []string
98+
for _, tag := range ctxt.ToolTags {
99+
if !strings.HasPrefix(tag, "goexperiment.") {
100+
save = append(save, tag)
101+
}
102+
}
103+
ctxt.ToolTags = save
99104

100105
// The go/build rule for whether cgo is enabled is:
101106
// 1. If $CGO_ENABLED is set, respect it.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
env GOARCH=amd64
2+
env GOAMD64=v3
3+
go list -f '{{context.ToolTags}}'
4+
stdout 'amd64.v1 amd64.v2 amd64.v3'
5+
6+
env GOARCH=arm
7+
env GOARM=6
8+
go list -f '{{context.ToolTags}}'
9+
stdout 'arm.5 arm.6'
10+
11+
env GOARCH=mips
12+
env GOMIPS=hardfloat
13+
go list -f '{{context.ToolTags}}'
14+
stdout 'mips.hardfloat'
15+
16+
env GOARCH=mips64
17+
env GOMIPS=hardfloat
18+
go list -f '{{context.ToolTags}}'
19+
stdout 'mips64.hardfloat'
20+
21+
env GOARCH=ppc64
22+
env GOPPC64=power9
23+
go list -f '{{context.ToolTags}}'
24+
stdout 'ppc64.power8 ppc64.power9'
25+
26+
env GOARCH=ppc64le
27+
env GOPPC64=power9
28+
go list -f '{{context.ToolTags}}'
29+
stdout 'ppc64le.power8 ppc64le.power9'
30+
31+
env GOARCH=386
32+
env GO386=sse2
33+
go list -f '{{context.ToolTags}}'
34+
stdout '386.sse2'
35+
36+
env GOARCH=wasm
37+
env GOWASM=satconv
38+
go list -f '{{context.ToolTags}}'
39+
stdout 'wasm.satconv'
40+
41+
-- go.mod --
42+
module m
43+
44+
-- p.go --
45+
package p

src/go/build/build.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,8 @@ func defaultContext() Context {
314314
}
315315
c.GOPATH = envOr("GOPATH", defaultGOPATH())
316316
c.Compiler = runtime.Compiler
317+
c.ToolTags = append(c.ToolTags, buildcfg.ToolTags...)
317318

318-
// For each experiment that has been enabled in the toolchain, define a
319-
// build tag with the same name but prefixed by "goexperiment." which can be
320-
// used for compiling alternative files for the experiment. This allows
321-
// changes for the experiment, like extra struct fields in the runtime,
322-
// without affecting the base non-experiment code at all.
323-
for _, exp := range buildcfg.Experiment.Enabled() {
324-
c.ToolTags = append(c.ToolTags, "goexperiment."+exp)
325-
}
326319
defaultToolTags = append([]string{}, c.ToolTags...) // our own private copy
327320

328321
// Each major Go release in the Go 1.x series adds a new

src/internal/buildcfg/cfg.go

+60-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
GOMIPS64 = gomips64()
3131
GOPPC64 = goppc64()
3232
GOWASM = gowasm()
33+
ToolTags = toolTags()
3334
GO_LDSO = defaultGO_LDSO
3435
Version = version
3536
)
@@ -115,8 +116,8 @@ func goppc64() int {
115116
}
116117

117118
type gowasmFeatures struct {
118-
SignExt bool
119119
SatConv bool
120+
SignExt bool
120121
}
121122

122123
func (f gowasmFeatures) String() string {
@@ -149,3 +150,61 @@ func gowasm() (f gowasmFeatures) {
149150
func Getgoextlinkenabled() string {
150151
return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED)
151152
}
153+
154+
func toolTags() []string {
155+
tags := experimentTags()
156+
tags = append(tags, gogoarchTags()...)
157+
return tags
158+
}
159+
160+
func experimentTags() []string {
161+
var list []string
162+
// For each experiment that has been enabled in the toolchain, define a
163+
// build tag with the same name but prefixed by "goexperiment." which can be
164+
// used for compiling alternative files for the experiment. This allows
165+
// changes for the experiment, like extra struct fields in the runtime,
166+
// without affecting the base non-experiment code at all.
167+
for _, exp := range Experiment.Enabled() {
168+
list = append(list, "goexperiment."+exp)
169+
}
170+
return list
171+
}
172+
173+
func gogoarchTags() []string {
174+
switch GOARCH {
175+
case "386":
176+
return []string{GOARCH + "." + GO386}
177+
case "amd64":
178+
var list []string
179+
for i := 1; i <= GOAMD64; i++ {
180+
list = append(list, fmt.Sprintf("%s.v%d", GOARCH, i))
181+
}
182+
return list
183+
case "arm":
184+
var list []string
185+
for i := 5; i <= GOARM; i++ {
186+
list = append(list, fmt.Sprintf("%s.%d", GOARCH, i))
187+
}
188+
return list
189+
case "mips", "mipsle":
190+
return []string{GOARCH + "." + GOMIPS}
191+
case "mips64", "mips64le":
192+
return []string{GOARCH + "." + GOMIPS64}
193+
case "ppc64", "ppc64le":
194+
var list []string
195+
for i := 8; i <= GOPPC64; i++ {
196+
list = append(list, fmt.Sprintf("%s.power%d", GOARCH, i))
197+
}
198+
return list
199+
case "wasm":
200+
var list []string
201+
if GOWASM.SatConv {
202+
list = append(list, GOARCH+".satconv")
203+
}
204+
if GOWASM.SignExt {
205+
list = append(list, GOARCH+".signext")
206+
}
207+
return list
208+
}
209+
return nil
210+
}

0 commit comments

Comments
 (0)