1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Russ Cox 2016-10-17 13:29:31 -04:00
parent 1e28dce80a
commit 0ba3c607df
2 changed files with 8 additions and 2 deletions

View File

@ -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)
}

View File

@ -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":