From: Austin Clements Date: Mon, 15 Mar 2021 19:53:21 +0000 (-0400) Subject: cmd/dist: build bootstrap without GOEXPERIMENT X-Git-Tag: go1.17beta1~1063 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6461d74bf2;p=gostls13.git cmd/dist: build bootstrap without GOEXPERIMENT Currently, dist attempts to build the bootstrap with the GOEXPERIMENT set in the environment. However, the logic is incomplete and notably requires a hack to enable the appropriate build tags for GOEXPERIMENT=regabi. Without this hack, the build becomes skewed between a compiler that uses regabi and a runtime that doesn't when building toolchain2. We could try to improve the GOEXPERIMENT processing in cmd/dist, but it will always chase cmd/internal/objabi and it's quite difficult to share the logic with objabi because of the constraints on building cmd/dist. Instead, we switch to building go_bootstrap without any GOEXPERIMENT and only start using GOEXPERIMENT once we have a working, modern cmd/go (which has all the GOEXPERIMENT logic in it). We also build toolchain1 without any GOEXPERIMENT set, in case the bootstrap toolchain is recent enough to understand build-time GOEXPERIMENT settings. As part of this, we make GOEXPERIMENT=none mean "no experiments". This is necessary since, now that we support setting GOEXPERIMENT at build time, we need an explicit way to say "ignore all baked-in experiments". For #40724. Change-Id: I115399579b766a7a8b2f352f7e5efea5305666cd Reviewed-on: https://go-review.googlesource.com/c/go/+/302050 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky Reviewed-by: David Chase Reviewed-by: Cherry Zhang --- diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index b2d13e7db4..acf38e3785 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -974,11 +974,6 @@ func matchtag(tag string) bool { } return !matchtag(tag[1:]) } - if os.Getenv("GOEXPERIMENT") == "regabi" && tag == "goexperiment.regabi" { - // TODO: maybe we can handle GOEXPERIMENT more generally. - // Or remove once we commit to regabi (#40724). - return true - } return tag == "gc" || tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || (goos == "android" && tag == "linux") || (goos == "illumos" && tag == "solaris") || @@ -1268,6 +1263,20 @@ func cmdbootstrap() { // go tool may complain. os.Setenv("GOPATH", pathf("%s/pkg/obj/gopath", goroot)) + // Disable GOEXPERIMENT when building toolchain1 and + // go_bootstrap. We don't need any experiments for the + // bootstrap toolchain, and this lets us avoid duplicating the + // GOEXPERIMENT-related build logic from cmd/go here. If the + // bootstrap toolchain is < Go 1.17, it will ignore this + // anyway since GOEXPERIMENT is baked in; otherwise it will + // pick it up from the environment we set here. Once we're + // using toolchain1 with dist as the build system, we need to + // override this to keep the experiments assumed by the + // toolchain and by dist consistent. Once go_bootstrap takes + // over the build process, we'll set this back to the original + // GOEXPERIMENT. + os.Setenv("GOEXPERIMENT", "none") + if debug { // cmd/buildid is used in debug mode. toolchain = append(toolchain, "cmd/buildid") @@ -1345,6 +1354,8 @@ func cmdbootstrap() { } xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n") os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) + // Now that cmd/go is in charge of the build process, enable GOEXPERIMENT. + os.Setenv("GOEXPERIMENT", goexperiment) goInstall(goBootstrap, append([]string{"-i"}, toolchain...)...) if debug { run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index 81e2b28600..9308a6d2eb 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -135,9 +135,12 @@ func init() { goexperiment := envOr("GOEXPERIMENT", defaultGOEXPERIMENT) - for _, f := range strings.Split(goexperiment, ",") { - if f != "" { - addexp(f) + // GOEXPERIMENT=none overrides all experiments enabled at dist time. + if goexperiment != "none" { + for _, f := range strings.Split(goexperiment, ",") { + if f != "" { + addexp(f) + } } }