Skip to content

Commit 6543df4

Browse files
n
Change-Id: I23851c3d47c5727fe9ccf6b318693ca30c872409
1 parent 4ece9ce commit 6543df4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/cmd/go/internal/cfg/cfg.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"go/build"
1414
"internal/buildcfg"
1515
"internal/cfg"
16-
"internal/platform"
1716
"io"
1817
"os"
1918
"path/filepath"
@@ -128,14 +127,16 @@ func defaultContext() build.Context {
128127
ctxt.ToolTags = save
129128

130129
// The go/build rule for whether cgo is enabled is:
131-
// 1. If $CGO_ENABLED is set, respect it.
132-
// 2. Otherwise, if this is a cross-compile, disable cgo.
133-
// 3. Otherwise, use built-in default for GOOS/GOARCH.
130+
// 1. If $CGO_ENABLED is set, respect it.
131+
// 2. Otherwise, if this is a cross-compile, disable cgo.
132+
// 3. Otherwise, use built-in default for GOOS/GOARCH.
133+
//
134134
// Recreate that logic here with the new GOOS/GOARCH setting.
135-
if v := Getenv("CGO_ENABLED"); v == "0" || v == "1" {
136-
ctxt.CgoEnabled = v[0] == '1'
137-
} else if ctxt.GOOS != runtime.GOOS || ctxt.GOARCH != runtime.GOARCH {
138-
ctxt.CgoEnabled = false
135+
// We need to run steps 2 and 3 to determine what the default value
136+
// of CgoEnabled would be for computing CGOChanged.
137+
defaultCgoEnabled := ctxt.CgoEnabled
138+
if ctxt.GOOS != runtime.GOOS || ctxt.GOARCH != runtime.GOARCH {
139+
defaultCgoEnabled = false
139140
} else {
140141
// Use built-in default cgo setting for GOOS/GOARCH.
141142
// Note that ctxt.GOOS/GOARCH are derived from the preference list
@@ -162,17 +163,16 @@ func defaultContext() build.Context {
162163
if os.Getenv("CC") == "" {
163164
cc := DefaultCC(ctxt.GOOS, ctxt.GOARCH)
164165
if _, err := LookPath(cc); err != nil {
165-
ctxt.CgoEnabled = false
166+
defaultCgoEnabled = false
166167
}
167168
}
168169
}
169170
}
170-
CGOChanged = ctxt.CgoEnabled != func() bool {
171-
if runtime.GOARCH == ctxt.GOARCH && runtime.GOOS == ctxt.GOOS {
172-
return platform.CgoSupported(ctxt.GOOS, ctxt.GOARCH)
173-
}
174-
return false
175-
}()
171+
ctxt.CgoEnabled = defaultCgoEnabled
172+
if v := Getenv("CGO_ENABLED"); v == "0" || v == "1" {
173+
ctxt.CgoEnabled = v[0] == '1'
174+
}
175+
CGOChanged = ctxt.CgoEnabled != defaultCgoEnabled
176176

177177
ctxt.OpenFile = func(path string) (io.ReadCloser, error) {
178178
return fsys.Open(path)

0 commit comments

Comments
 (0)