build: add targets for static linking

This commit is contained in:
aerth 2018-07-25 20:15:28 -07:00
parent dcdd57df62
commit 316fddfd23
No known key found for this signature in database
GPG key ID: EBC461F686385D5C
3 changed files with 23 additions and 10 deletions

View file

@ -16,6 +16,13 @@ geth:
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."
geth-static:
build/env.sh go run build/ci.go install -static ./cmd/geth
@echo "Done building."
@echo "Run \"$(GOBIN)/geth\" to launch geth."
static: geth-static
swarm:
build/env.sh go run build/ci.go install ./cmd/swarm
@echo "Done building."
@ -24,6 +31,9 @@ swarm:
all:
build/env.sh go run build/ci.go install
all-static:
build/env.sh go run build/ci.go install -static
android:
build/env.sh go run build/ci.go aar --local
@echo "Done building."

View file

@ -175,10 +175,11 @@ func doInstall(cmdline []string) {
var (
arch = flag.String("arch", "", "Architecture to cross build for")
cc = flag.String("cc", "", "C compiler to cross build with")
static = flag.Bool("static", false, "Build a static linked binary")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()
env.Static = *static
// Check Go version. People regularly open issues about compilation
// failure with outdated Go. This should save them the trouble.
if !strings.Contains(runtime.Version(), "devel") {
@ -246,13 +247,14 @@ func buildFlags(env build.Environment) (flags []string) {
if env.Commit != "" {
ld = append(ld, "-X", "main.gitCommit="+env.Commit)
}
if runtime.GOOS == "darwin" {
ld = append(ld, "-s")
ld = append(ld, "-w")
if env.Static {
ld = append(ld, "-extldflags -static")
}
if len(ld) > 0 {
flags = append(flags, "-ldflags", strings.Join(ld, " "))
}
return flags
}

View file

@ -41,11 +41,12 @@ type Environment struct {
Buildnum string
IsPullRequest bool
IsCronJob bool
Static bool
}
func (env Environment) String() string {
return fmt.Sprintf("%s env (commit:%s branch:%s tag:%s buildnum:%s pr:%t)",
env.Name, env.Commit, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest)
return fmt.Sprintf("%s env (commit:%s branch:%s tag:%s buildnum:%s pr:%t static:%t)",
env.Name, env.Commit, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest, env.Static)
}
// Env returns metadata about the current CI environment, falling back to LocalEnv