Skip to content

Commit 0bd3073

Browse files
prattmicgopherbot
authored andcommitted
sweet: don't build tsgo on go1.23
tsgo requires 1.24, so don't attempt to build it if the test toolchain is older than 1.24. To do this, we extract the version from the toolchain and check that it is new enough, which is more difficult than it should be due to #73369. I suspect generally there is a way to do this with go list, but 1.23 fails to even parse go.mod due to a tool directive before it can decide it is too old to build. Fixes golang/go#73052. Fixes golang/go#73049. Fixes golang/go#73047. Change-Id: I6a6a636c495b52cff1a6196ffee79b44aaa687ba Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/665355 Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent 7fda962 commit 0bd3073

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

sweet/harnesses/go-build.go

+59-10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
package harnesses
66

77
import (
8+
"debug/buildinfo"
89
"fmt"
10+
"go/version"
911
"os/exec"
1012
"path/filepath"
13+
"strings"
1114

1215
"golang.org/x/benchmarks/sweet/common"
1316
"golang.org/x/benchmarks/sweet/common/fileutil"
@@ -17,6 +20,7 @@ import (
1720
type buildBenchmark struct {
1821
name string
1922
pkg string
23+
minGo string // skip if toolchain is older than this
2024
clone func(outDir string) error
2125
}
2226

@@ -60,8 +64,9 @@ var (
6064
// Added for #72815. This codebase has at least a few packages
6165
// that are difficult for the Go compiler to handle, performance-wise,
6266
// as of Mar. 13 2025.
63-
name: "tsgo",
64-
pkg: "cmd/tsgo",
67+
name: "tsgo",
68+
pkg: "cmd/tsgo",
69+
minGo: "go1.24",
6570
clone: func(outDir string) error {
6671
return gitCloneToCommit(
6772
outDir,
@@ -85,8 +90,13 @@ func (h GoBuild) CheckPrerequisites() error {
8590
}
8691

8792
func (h GoBuild) Get(gcfg *common.GetConfig) error {
93+
benchmarks, err := goBuildBenchmarks(nil, gcfg.Short)
94+
if err != nil {
95+
return fmt.Errorf("error getting benchmark list: %v", err)
96+
}
97+
8898
// Clone the sources that we're going to build.
89-
for _, bench := range goBuildBenchmarks(gcfg.Short) {
99+
for _, bench := range benchmarks {
90100
if err := bench.clone(filepath.Join(gcfg.SrcDir, bench.name)); err != nil {
91101
return err
92102
}
@@ -98,9 +108,6 @@ func (h GoBuild) Build(pcfg *common.Config, bcfg *common.BuildConfig) error {
98108
// Local copy of config for updating GOROOT.
99109
cfg := pcfg.Copy()
100110

101-
// Get the benchmarks we're going to build.
102-
benchmarks := goBuildBenchmarks(bcfg.Short)
103-
104111
// cfg.GoRoot is our source toolchain. We need to rebuild cmd/compile
105112
// and cmd/link with cfg.BuildEnv to apply any configured build options
106113
// (e.g., PGO).
@@ -115,6 +122,12 @@ func (h GoBuild) Build(pcfg *common.Config, bcfg *common.BuildConfig) error {
115122
return fmt.Errorf("error building cmd/compile and cmd/link: %v", err)
116123
}
117124

125+
// Get the benchmarks we're going to build.
126+
benchmarks, err := goBuildBenchmarks(cfg, bcfg.Short)
127+
if err != nil {
128+
return fmt.Errorf("error getting benchmark list: %v", err)
129+
}
130+
118131
for _, bench := range benchmarks {
119132
// Generate a symlink to the repository and put it in bin.
120133
// It's not a binary, but it's the only place we can put it
@@ -153,7 +166,11 @@ func (h GoBuild) Run(pcfg *common.Config, rcfg *common.RunConfig) error {
153166
cfg := pcfg.Copy()
154167
cfg.GoRoot = filepath.Join(rcfg.BinDir, "goroot") // see Build, above.
155168

156-
benchmarks := goBuildBenchmarks(rcfg.Short)
169+
benchmarks, err := goBuildBenchmarks(cfg, rcfg.Short)
170+
if err != nil {
171+
return fmt.Errorf("error getting benchmark list: %v", err)
172+
}
173+
157174
for _, bench := range benchmarks {
158175
cmd := exec.Command(
159176
filepath.Join(rcfg.BinDir, "go-build-bench"),
@@ -174,9 +191,41 @@ func (h GoBuild) Run(pcfg *common.Config, rcfg *common.RunConfig) error {
174191
return nil
175192
}
176193

177-
func goBuildBenchmarks(short bool) []*buildBenchmark {
194+
// goBuildBenchmarks returns the set of benchmarks to run for this
195+
// configuration.
196+
//
197+
// cfg may be nil if the build configuration isn't known yet. In that case, it
198+
// returns the set of benchmarks that may run.
199+
func goBuildBenchmarks(cfg *common.Config, short bool) ([]*buildBenchmark, error) {
200+
var bi *buildinfo.BuildInfo
201+
if cfg != nil {
202+
var err error
203+
bi, err = buildinfo.ReadFile(cfg.GoTool().Tool)
204+
if err != nil {
205+
return nil, fmt.Errorf("error reading build info from Go toolchain: %v", err)
206+
}
207+
208+
// NOTE(go.dev/issue/73369): Tip toolchain versions look like
209+
// "devel go1.25-9ce47e66e8 Wed Mar 26 03:48:50 2025 -0700".
210+
// This is not a valid go/version version, so it sorts before
211+
// every valid version. If we strip "devel", then the remainder
212+
// is valid.
213+
bi.GoVersion = strings.TrimPrefix(bi.GoVersion, "devel ")
214+
}
215+
216+
base := buildBenchmarks
178217
if short {
179-
return buildBenchmarksShort
218+
base = buildBenchmarksShort
180219
}
181-
return buildBenchmarks
220+
221+
var out []*buildBenchmark
222+
for _, bench := range base {
223+
if bench.minGo != "" && bi != nil && version.Compare(bi.GoVersion, bench.minGo) < 0 {
224+
log.Printf("Skipping go-build on %s: toolchain version %s less than required %s", bench.name, bi.GoVersion, bench.minGo)
225+
continue
226+
}
227+
out = append(out, bench)
228+
}
229+
230+
return out, nil
182231
}

0 commit comments

Comments
 (0)