Merge pull request #1603 from jfparis/master
Add support for GOARM parameter when cross compiling
This commit is contained in:
commit
54c0794cf3
2 changed files with 12 additions and 2 deletions
12
build.go
12
build.go
|
@ -227,6 +227,7 @@ func showUsage(output io.Writer) {
|
||||||
fmt.Fprintf(output, " --enable-cgo use CGO to link against libc\n")
|
fmt.Fprintf(output, " --enable-cgo use CGO to link against libc\n")
|
||||||
fmt.Fprintf(output, " --goos value set GOOS for cross-compilation\n")
|
fmt.Fprintf(output, " --goos value set GOOS for cross-compilation\n")
|
||||||
fmt.Fprintf(output, " --goarch value set GOARCH for cross-compilation\n")
|
fmt.Fprintf(output, " --goarch value set GOARCH for cross-compilation\n")
|
||||||
|
fmt.Fprintf(output, " --goarm value set GOARM for cross-compilation\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func verbosePrintf(message string, args ...interface{}) {
|
func verbosePrintf(message string, args ...interface{}) {
|
||||||
|
@ -252,13 +253,16 @@ func cleanEnv() (env []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// build runs "go build args..." with GOPATH set to gopath.
|
// build runs "go build args..." with GOPATH set to gopath.
|
||||||
func build(cwd, goos, goarch, gopath string, args ...string) error {
|
func build(cwd, goos, goarch, goarm, gopath string, args ...string) error {
|
||||||
a := []string{"build"}
|
a := []string{"build"}
|
||||||
a = append(a, "-asmflags", fmt.Sprintf("-trimpath=%s", gopath))
|
a = append(a, "-asmflags", fmt.Sprintf("-trimpath=%s", gopath))
|
||||||
a = append(a, "-gcflags", fmt.Sprintf("-trimpath=%s", gopath))
|
a = append(a, "-gcflags", fmt.Sprintf("-trimpath=%s", gopath))
|
||||||
a = append(a, args...)
|
a = append(a, args...)
|
||||||
cmd := exec.Command("go", a...)
|
cmd := exec.Command("go", a...)
|
||||||
cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos)
|
cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos)
|
||||||
|
if goarm != "" {
|
||||||
|
cmd.Env = append(cmd.Env, "GOARM="+goarm)
|
||||||
|
}
|
||||||
if !enableCGO {
|
if !enableCGO {
|
||||||
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
|
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
|
||||||
}
|
}
|
||||||
|
@ -431,6 +435,7 @@ func main() {
|
||||||
|
|
||||||
targetGOOS := runtime.GOOS
|
targetGOOS := runtime.GOOS
|
||||||
targetGOARCH := runtime.GOARCH
|
targetGOARCH := runtime.GOARCH
|
||||||
|
targetGOARM := ""
|
||||||
|
|
||||||
var outputFilename string
|
var outputFilename string
|
||||||
|
|
||||||
|
@ -464,6 +469,9 @@ func main() {
|
||||||
case "--goarch":
|
case "--goarch":
|
||||||
skipNext = true
|
skipNext = true
|
||||||
targetGOARCH = params[i+1]
|
targetGOARCH = params[i+1]
|
||||||
|
case "--goarm":
|
||||||
|
skipNext = true
|
||||||
|
targetGOARM = params[i+1]
|
||||||
case "-h":
|
case "-h":
|
||||||
showUsage(os.Stdout)
|
showUsage(os.Stdout)
|
||||||
return
|
return
|
||||||
|
@ -548,7 +556,7 @@ func main() {
|
||||||
"-o", output, config.Main,
|
"-o", output, config.Main,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = build(filepath.Join(gopath, "src"), targetGOOS, targetGOARCH, gopath, args...)
|
err = build(filepath.Join(gopath, "src"), targetGOOS, targetGOARCH, targetGOARM, gopath, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die("build failed: %v\n", err)
|
die("build failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,8 @@ supply the target OS and platform via the command-line options like this
|
||||||
|
|
||||||
$ go run build.go --goos freebsd --goarch 386
|
$ go run build.go --goos freebsd --goarch 386
|
||||||
|
|
||||||
|
$ go run build.go --goos linux --goarch arm --goarm 6
|
||||||
|
|
||||||
The resulting binary is statically linked and does not require any
|
The resulting binary is statically linked and does not require any
|
||||||
libraries.
|
libraries.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue