This commit is contained in:
a e r t h 2018-07-26 21:41:24 +00:00 committed by GitHub
commit 17a5ea75f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 10 deletions

View file

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

View file

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

View file

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