build: Set CGO_ENABLED=0 by default, except on specific platforms (#6768)
This commit is contained in:
@@ -451,9 +451,7 @@ func install(target target, tags []string) {
|
|||||||
}
|
}
|
||||||
os.Setenv("GOBIN", filepath.Join(cwd, "bin"))
|
os.Setenv("GOBIN", filepath.Join(cwd, "bin"))
|
||||||
|
|
||||||
os.Setenv("GOOS", goos)
|
setBuildEnvVars()
|
||||||
os.Setenv("GOARCH", goarch)
|
|
||||||
os.Setenv("CC", cc)
|
|
||||||
|
|
||||||
// On Windows generate a special file which the Go compiler will
|
// On Windows generate a special file which the Go compiler will
|
||||||
// automatically use when generating Windows binaries to set things like
|
// automatically use when generating Windows binaries to set things like
|
||||||
@@ -477,9 +475,7 @@ func build(target target, tags []string) {
|
|||||||
|
|
||||||
rmr(target.BinaryName())
|
rmr(target.BinaryName())
|
||||||
|
|
||||||
os.Setenv("GOOS", goos)
|
setBuildEnvVars()
|
||||||
os.Setenv("GOARCH", goarch)
|
|
||||||
os.Setenv("CC", cc)
|
|
||||||
|
|
||||||
// On Windows generate a special file which the Go compiler will
|
// On Windows generate a special file which the Go compiler will
|
||||||
// automatically use when generating Windows binaries to set things like
|
// automatically use when generating Windows binaries to set things like
|
||||||
@@ -501,6 +497,19 @@ func build(target target, tags []string) {
|
|||||||
runPrint(goCmd, args...)
|
runPrint(goCmd, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setBuildEnvVars() {
|
||||||
|
os.Setenv("GOOS", goos)
|
||||||
|
os.Setenv("GOARCH", goarch)
|
||||||
|
os.Setenv("CC", cc)
|
||||||
|
if os.Getenv("CGO_ENABLED") == "" {
|
||||||
|
switch goos {
|
||||||
|
case "darwin", "solaris":
|
||||||
|
default:
|
||||||
|
os.Setenv("CGO_ENABLED", "0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func appendParameters(args []string, tags []string, pkgs ...string) []string {
|
func appendParameters(args []string, tags []string, pkgs ...string) []string {
|
||||||
if pkgdir != "" {
|
if pkgdir != "" {
|
||||||
args = append(args, "-pkgdir", pkgdir)
|
args = append(args, "-pkgdir", pkgdir)
|
||||||
|
|||||||
Reference in New Issue
Block a user