From: Russ Cox Date: Mon, 17 Oct 2016 17:29:31 +0000 (-0400) Subject: cmd/dist, go/build: make CGO_ENABLED during make.bash sticky X-Git-Tag: go1.8beta1~834 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0ba3c607dfcc90072191375d57c4059be1ae96c7;p=gostls13.git cmd/dist, go/build: make CGO_ENABLED during make.bash sticky 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/dist/buildgo.go b/src/cmd/dist/buildgo.go index dc478f87fe..27976fb820 100644 --- a/src/cmd/dist/buildgo.go +++ b/src/cmd/dist/buildgo.go @@ -7,6 +7,7 @@ package main import ( "bytes" "fmt" + "os" "sort" ) @@ -85,7 +86,8 @@ func mkzcgo(dir, file string) { "\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) } diff --git a/src/go/build/build.go b/src/go/build/build.go index 5d87d9fb9e..9bd211521d 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -272,7 +272,11 @@ func defaultContext() Context { // (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":