Skip to content

Commit

Permalink
build: Set CGO_ENABLED=0 by default, except on specific platforms (#6768
Browse files Browse the repository at this point in the history
)
  • Loading branch information
imsodin committed Jun 21, 2020
1 parent 705710b commit 3d75819
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ func install(target target, tags []string) {
}
os.Setenv("GOBIN", filepath.Join(cwd, "bin"))

os.Setenv("GOOS", goos)
os.Setenv("GOARCH", goarch)
os.Setenv("CC", cc)
setBuildEnvVars()

// On Windows generate a special file which the Go compiler will
// automatically use when generating Windows binaries to set things like
Expand All @@ -477,9 +475,7 @@ func build(target target, tags []string) {

rmr(target.BinaryName())

os.Setenv("GOOS", goos)
os.Setenv("GOARCH", goarch)
os.Setenv("CC", cc)
setBuildEnvVars()

// On Windows generate a special file which the Go compiler will
// automatically use when generating Windows binaries to set things like
Expand All @@ -501,6 +497,19 @@ func build(target target, tags []string) {
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 {
if pkgdir != "" {
args = append(args, "-pkgdir", pkgdir)
Expand Down

0 comments on commit 3d75819

Please sign in to comment.