]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist, go/build: make CGO_ENABLED during make.bash sticky
authorRuss Cox <rsc@golang.org>
Mon, 17 Oct 2016 17:29:31 +0000 (13:29 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 17 Oct 2016 18:53:22 +0000 (18:53 +0000)
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>
src/cmd/dist/buildgo.go
src/go/build/build.go

index dc478f87fec72250ea58fa8c788a6297186b736e..27976fb82017350f1ccaadd65471fb4dce246064 100644 (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)
        }
index 5d87d9fb9e02b952c08b960bddce9a7570be2158..9bd211521dbb9f8103182e2d04f231e5ff17aded 100644 (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":