From a978b1e049268cd2726c521fa3526976c7af7351 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 2 Oct 2013 20:14:54 -0400 Subject: [PATCH] misc/dist: support building statically linked toolchain. 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/misc/dist/bindist.go b/misc/dist/bindist.go index 0ed7afeb9c..82898a59ba 100644 --- a/misc/dist/bindist.go +++ b/misc/dist/bindist.go @@ -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 } -- 2.50.0