From c9ab75a44c49fc44e663b571140d67ccf6a6d8c1 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 29 Jun 2016 09:36:40 +0200 Subject: [PATCH 1/5] Fix build tag in run_integration_tests.go --- run_integration_tests.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_integration_tests.go b/run_integration_tests.go index 709b39a2f..7c727d743 100644 --- a/run_integration_tests.go +++ b/run_integration_tests.go @@ -1,4 +1,4 @@ -// xbuild ignore +// +build ignore package main From 38d4522ea502423a888da28ac831e351d6ff9ee4 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 16 Jul 2016 09:42:02 +1200 Subject: [PATCH 2/5] build.go: Add go1.7 to list of linkers requiring `-Xfoo=bar` syntax --- build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.go b/build.go index d81b57dc7..70091fc66 100644 --- a/build.go +++ b/build.go @@ -263,7 +263,7 @@ func (cs Constants) LDFlags() string { l := make([]string, 0, len(cs)) v := runtime.Version() - if strings.HasPrefix(v, "go1.5") || strings.HasPrefix(v, "go1.6") { + if strings.HasPrefix(v, "go1.5") || strings.HasPrefix(v, "go1.6") || strings.HasPrefix(v, "go1.7") { for k, v := range cs { l = append(l, fmt.Sprintf(`-X "%s=%s"`, k, v)) } From f967e90a96e8d3dda13971252405daa7c168aae0 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 16 Jul 2016 09:42:22 +1200 Subject: [PATCH 3/5] build.go: Strip harder (add `-w` flag) --- build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.go b/build.go index 70091fc66..d8b7956f6 100644 --- a/build.go +++ b/build.go @@ -370,7 +370,7 @@ func main() { if version != "" { constants["main.version"] = version } - ldflags := "-s " + constants.LDFlags() + ldflags := "-s -w " + constants.LDFlags() verbosePrintf("ldflags: %s\n", ldflags) args := []string{ From c9400d5c61b47e1d8d1c9fe9179a30117f18e195 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 16 Jul 2016 09:42:41 +1200 Subject: [PATCH 4/5] build.go: Support cross-compilation via new `--goos` and `--goarch` flags --- build.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/build.go b/build.go index d8b7956f6..5526f33a2 100644 --- a/build.go +++ b/build.go @@ -152,10 +152,12 @@ func showUsage(output io.Writer) { fmt.Fprintf(output, "USAGE: go run build.go OPTIONS\n") fmt.Fprintf(output, "\n") fmt.Fprintf(output, "OPTIONS:\n") - fmt.Fprintf(output, " -v --verbose output more messages\n") - fmt.Fprintf(output, " -t --tags specify additional build tags\n") - fmt.Fprintf(output, " -k --keep-gopath do not remove the GOPATH after build\n") - fmt.Fprintf(output, " -T --test run tests\n") + fmt.Fprintf(output, " -v --verbose output more messages\n") + fmt.Fprintf(output, " -t --tags specify additional build tags\n") + fmt.Fprintf(output, " -k --keep-gopath do not remove the GOPATH after build\n") + fmt.Fprintf(output, " -T --test run tests\n") + fmt.Fprintf(output, " --goos value set GOOS for cross-compilation\n") + fmt.Fprintf(output, " --goarch value set GOARCH for cross-compilation\n") } func verbosePrintf(message string, args ...interface{}) { @@ -181,10 +183,10 @@ func cleanEnv() (env []string) { } // build runs "go build args..." with GOPATH set to gopath. -func build(cwd, gopath string, args ...string) error { +func build(cwd, goos, goarch, gopath string, args ...string) error { args = append([]string{"build"}, args...) cmd := exec.Command("go", args...) - cmd.Env = append(cleanEnv(), "GOPATH="+gopath) + cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos) cmd.Dir = cwd cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -281,6 +283,10 @@ func main() { skipNext := false params := os.Args[1:] + + targetGOOS := runtime.GOOS + targetGOARCH := runtime.GOARCH + for i, arg := range params { if skipNext { skipNext = false @@ -297,6 +303,12 @@ func main() { buildTags = strings.Split(params[i+1], " ") case "-T", "--test": runTests = true + case "--goos": + skipNext = true + targetGOOS = params[i+1] + case "--goarch": + skipNext = true + targetGOARCH = params[i+1] case "-h": showUsage(os.Stdout) return @@ -354,7 +366,7 @@ func main() { }() outputFilename := "restic" - if runtime.GOOS == "windows" { + if targetGOOS == "windows" { outputFilename = "restic.exe" } @@ -379,7 +391,7 @@ func main() { "-o", output, "cmds/restic", } - err = build(filepath.Join(gopath, "src"), gopath, args...) + err = build(filepath.Join(gopath, "src"), targetGOOS, targetGOARCH, gopath, args...) if err != nil { die("build failed: %v\n", err) } From 983e50938833a61e8cc0ddd2e6cfc94c0361829d Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 16 Jul 2016 10:14:41 +1200 Subject: [PATCH 5/5] build.go: gofmt --- build.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.go b/build.go index 5526f33a2..f66d7f255 100644 --- a/build.go +++ b/build.go @@ -283,10 +283,10 @@ func main() { skipNext := false params := os.Args[1:] - + targetGOOS := runtime.GOOS targetGOARCH := runtime.GOARCH - + for i, arg := range params { if skipNext { skipNext = false