Disable symbol table and DWARF generation by default.

Trimpath if compiling with Go >= 1.13
This commit is contained in:
Julian Yap 2019-12-26 01:55:13 -10:00
parent 2fc29f9272
commit 638f2a2dff

View file

@ -187,13 +187,13 @@ func doInstall(cmdline []string) {
flag.CommandLine.Parse(cmdline) flag.CommandLine.Parse(cmdline)
env := build.Env() env := build.Env()
// Figure out the minor version number since we can't textually compare (1.10 < 1.9)
var minor int
fmt.Sscanf(strings.TrimPrefix(runtime.Version(), "go1."), "%d", &minor)
// 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") {
// Figure out the minor version number since we can't textually compare (1.10 < 1.9)
var minor int
fmt.Sscanf(strings.TrimPrefix(runtime.Version(), "go1."), "%d", &minor)
if minor < 9 { if minor < 9 {
log.Println("You have Go version", runtime.Version()) log.Println("You have Go version", runtime.Version())
log.Println("go-ethereum requires at least Go version 1.9 and cannot") log.Println("go-ethereum requires at least Go version 1.9 and cannot")
@ -210,6 +210,9 @@ func doInstall(cmdline []string) {
if *arch == "" || *arch == runtime.GOARCH { if *arch == "" || *arch == runtime.GOARCH {
goinstall := goTool("install", buildFlags(env)...) goinstall := goTool("install", buildFlags(env)...)
if minor >= 13 {
goinstall.Args = append(goinstall.Args, "-trimpath")
}
goinstall.Args = append(goinstall.Args, "-v") goinstall.Args = append(goinstall.Args, "-v")
goinstall.Args = append(goinstall.Args, packages...) goinstall.Args = append(goinstall.Args, packages...)
build.MustRun(goinstall) build.MustRun(goinstall)
@ -224,6 +227,9 @@ func doInstall(cmdline []string) {
} }
// Seems we are cross compiling, work around forbidden GOBIN // Seems we are cross compiling, work around forbidden GOBIN
goinstall := goToolArch(*arch, *cc, "install", buildFlags(env)...) goinstall := goToolArch(*arch, *cc, "install", buildFlags(env)...)
if minor >= 13 {
goinstall.Args = append(goinstall.Args, "-trimpath")
}
goinstall.Args = append(goinstall.Args, "-v") goinstall.Args = append(goinstall.Args, "-v")
goinstall.Args = append(goinstall.Args, []string{"-buildmode", "archive"}...) goinstall.Args = append(goinstall.Args, []string{"-buildmode", "archive"}...)
goinstall.Args = append(goinstall.Args, packages...) goinstall.Args = append(goinstall.Args, packages...)
@ -253,9 +259,7 @@ func buildFlags(env build.Environment) (flags []string) {
var ld []string var ld []string
if env.Commit != "" { if env.Commit != "" {
ld = append(ld, "-X", "main.gitCommit="+env.Commit) ld = append(ld, "-X", "main.gitCommit="+env.Commit)
} ld = append(ld, "-s", "-w")
if runtime.GOOS == "darwin" {
ld = append(ld, "-s")
} }
if len(ld) > 0 { if len(ld) > 0 {