2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 22:27:35 +00:00

build.go: Add --enable-cgo

This commit is contained in:
Alexander Neumann 2017-05-25 11:03:29 +02:00
parent d1cc87ba28
commit c49da4c6f7

View File

@ -18,6 +18,7 @@ var (
verbose bool verbose bool
keepGopath bool keepGopath bool
runTests bool runTests bool
enableCGO bool
) )
var config = struct { var config = struct {
@ -165,6 +166,7 @@ func showUsage(output io.Writer) {
fmt.Fprintf(output, " -k --keep-gopath do not remove the GOPATH after build\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, " -T --test run tests\n")
fmt.Fprintf(output, " -o --output set output file name\n") fmt.Fprintf(output, " -o --output set output file name\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")
} }
@ -195,7 +197,11 @@ func cleanEnv() (env []string) {
func build(cwd, goos, goarch, gopath string, args ...string) error { func build(cwd, goos, goarch, gopath string, args ...string) error {
args = append([]string{"build"}, args...) args = append([]string{"build"}, args...)
cmd := exec.Command("go", args...) cmd := exec.Command("go", args...)
cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos, "CGO_ENABLED=0") cmd.Env = append(cleanEnv(), "GOPATH="+gopath, "GOARCH="+goarch, "GOOS="+goos)
if !enableCGO {
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
}
cmd.Dir = cwd cmd.Dir = cwd
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -319,6 +325,8 @@ func main() {
outputFilename = params[i+1] outputFilename = params[i+1]
case "-T", "--test": case "-T", "--test":
runTests = true runTests = true
case "--enable-cgo":
enableCGO = true
case "--goos": case "--goos":
skipNext = true skipNext = true
targetGOOS = params[i+1] targetGOOS = params[i+1]