Per discussion on #12808, it's a bit odd that if you do
CGO_ENABLED=0 ./make.bash
then you get a toolchain that still tries to use cgo.
So make the CGO_ENABLED setting propagate into
the resulting toolchain as the default setting for that
environment variable, like we do with other variables
like CC and GOROOT.
No reasonable way to test automatically, but I did
test by hand that after the above command, 'go env'
shows CGO_ENABLED=0; before it showed CGO_ENABLED=1.
Fixes #12808.
Change-Id: I26a2fa6cc00e73bde8af7469270b27293392ed71
Reviewed-on: https://go-review.googlesource.com/31141
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
import (
"bytes"
"fmt"
+ "os"
"sort"
)
"\n"+
"package build\n"+
"\n"+
- "var cgoEnabled = map[string]bool{\n")
+ "const defaultCGO_ENABLED = %q\n\n"+
+ "var cgoEnabled = map[string]bool{\n", os.Getenv("CGO_ENABLED"))
for _, plat := range list {
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
}
// (perhaps it is the stub to use in that case) should say "+build !go1.x".
c.ReleaseTags = []string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7", "go1.8"}
- switch os.Getenv("CGO_ENABLED") {
+ env := os.Getenv("CGO_ENABLED")
+ if env == "" {
+ env = defaultCGO_ENABLED
+ }
+ switch env {
case "1":
c.CgoEnabled = true
case "0":