]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: diagnose lack of gcc earlier in build
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 02:27:10 +0000 (22:27 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 05:33:55 +0000 (05:33 +0000)
Fixes #10731.

Change-Id: I105629b03fd3323c0a2ca5b6b0fd35ee92b7fd2e
Reviewed-on: https://go-review.googlesource.com/12146
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/dist/build.go
src/go/build/build.go

index f557238e5962271e0dd522505e61bcad8981ba3d..0616be804c06030e1490ae906f20d91076040d95 100644 (file)
@@ -9,6 +9,7 @@ import (
        "flag"
        "fmt"
        "os"
+       "os/exec"
        "path/filepath"
        "strings"
 )
@@ -1022,6 +1023,7 @@ func cmdbootstrap() {
 
        setup()
 
+       checkCC()
        bootstrapBuildTools()
 
        // For the main bootstrap, building for host os/arch.
@@ -1067,6 +1069,57 @@ func cmdbootstrap() {
        }
 }
 
+// Copied from go/build/build.go.
+// Cannot use go/build directly because cmd/dist for a new release
+// builds against an old release's go/build, which may be out of sync.
+var cgoEnabled = map[string]bool{
+       "darwin/386":      true,
+       "darwin/amd64":    true,
+       "darwin/arm":      true,
+       "darwin/arm64":    true,
+       "dragonfly/amd64": true,
+       "freebsd/386":     true,
+       "freebsd/amd64":   true,
+       "linux/386":       true,
+       "linux/amd64":     true,
+       "linux/arm":       true,
+       "linux/arm64":     true,
+       "linux/ppc64le":   true,
+       "android/386":     true,
+       "android/amd64":   true,
+       "android/arm":     true,
+       "netbsd/386":      true,
+       "netbsd/amd64":    true,
+       "netbsd/arm":      true,
+       "openbsd/386":     true,
+       "openbsd/amd64":   true,
+       "solaris/amd64":   true,
+       "windows/386":     true,
+       "windows/amd64":   true,
+}
+
+func needCC() bool {
+       switch os.Getenv("CGO_ENABLED") {
+       case "1":
+               return true
+       case "0":
+               return false
+       }
+       return cgoEnabled[gohostos+"/"+gohostarch]
+}
+
+func checkCC() {
+       if !needCC() {
+               return
+       }
+       if _, err := exec.Command(defaultcc, "--help").Output(); err != nil {
+               fatal("cannot invoke C compiler %q: %v\n\n"+
+                       "Go needs a system C compiler for use with cgo.\n"+
+                       "To set a C compiler, export CC=the-compiler.\n"+
+                       "To disable cgo, export CGO_ENABLED=0.\n", defaultcc, err)
+       }
+}
+
 func defaulttarg() string {
        // xgetwd might return a path with symlinks fully resolved, and if
        // there happens to be symlinks in goroot, then the hasprefix test
index bd84c57a4a60ae112897d62bddb19a94fa5ef99a..6496414f26659fc578a114032a6f70be1576726b 100644 (file)
@@ -256,6 +256,7 @@ func (ctxt *Context) SrcDirs() []string {
 // if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
 var Default Context = defaultContext()
 
+// Also known to cmd/dist/build.go.
 var cgoEnabled = map[string]bool{
        "darwin/386":      true,
        "darwin/amd64":    true,