]> Cypherpunks repositories - gostls13.git/commitdiff
misc/dist: support building statically linked toolchain.
authorShenghou Ma <minux.ma@gmail.com>
Thu, 3 Oct 2013 00:14:54 +0000 (20:14 -0400)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 3 Oct 2013 00:14:54 +0000 (20:14 -0400)
so that we don't need worry about specifying the required
libc version (note: as cmd/go will still be dynamically
linked to libc, we still need to perform the build on OSes
with an old enough libc. But as cmd/go doesn't rely on many
libc symbols, the situation should be significantly better).

Fixes #3564.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/14261043

misc/dist/bindist.go

index 0ed7afeb9c19605986c4c41f5ef8bf0d08c3b6e3..82898a59ba682c9dc10e5987346fe8b5b20c7e5d 100644 (file)
@@ -38,6 +38,7 @@ var (
        addLabel        = flag.String("label", "", "additional label to apply to file when uploading")
        includeRace     = flag.Bool("race", true, "build race detector packages")
        versionOverride = flag.String("version", "", "override version name")
+       staticToolchain = flag.Bool("static", true, "try to build statically linked toolchain (only supported on ELF targets)")
 
        username, password string // for Google Code upload
 )
@@ -106,6 +107,15 @@ var raceAvailable = []string{
        "windows-amd64",
 }
 
+// The OSes that support building statically linked toolchain
+// Only ELF platforms are supported.
+var staticLinkAvailable = []string{
+       "linux",
+       "freebsd",
+       "openbsd",
+       "netbsd",
+}
+
 var fileRe = regexp.MustCompile(
        `^(go[a-z0-9-.]+)\.(src|([a-z0-9]+)-([a-z0-9]+)(?:-([a-z0-9.]))?)\.`)
 
@@ -169,6 +179,13 @@ func main() {
                                        }
                                }
                        }
+                       if *staticToolchain {
+                               for _, os := range staticLinkAvailable {
+                                       if b.OS == os {
+                                               b.static = true
+                                       }
+                               }
+                       }
                }
                if err := b.Do(); err != nil {
                        log.Printf("%s: %v", targ, err)
@@ -184,6 +201,7 @@ type Build struct {
        Label  string
        root   string
        gopath string
+       static bool // if true, build statically linked toolchain
 }
 
 func (b *Build) Do() error {
@@ -582,6 +600,9 @@ func (b *Build) env() []string {
                "GOROOT_FINAL="+final,
                "GOPATH="+b.gopath,
        )
+       if b.static {
+               env = append(env, "GO_DISTFLAGS=-s")
+       }
        return env
 }