diff options
author | Simon Frei <freisim93@gmail.com> | 2020-06-21 17:32:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 17:32:55 +0200 |
commit | 3d75819cdbc61e97b7a6e919ff7f751cc6bb03b5 (patch) | |
tree | cd1e811a87f9ecdd00a96b9d1ce35007e9d43f21 /build.go | |
parent | 705710b1a13d7a4646a2052076f92bf65c3a77f1 (diff) | |
download | syncthing-3d75819cdbc61e97b7a6e919ff7f751cc6bb03b5.tar.gz syncthing-3d75819cdbc61e97b7a6e919ff7f751cc6bb03b5.zip |
build: Set CGO_ENABLED=0 by default, except on specific platforms (#6768)
Diffstat (limited to 'build.go')
-rw-r--r-- | build.go | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -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 @@ -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 @@ -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) |