diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 7f2f75341fa..8ef73e7a89b 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -463,6 +463,9 @@ var deptab = []struct { {"runtime/internal/sys", []string{ "zversion.go", }}, + {"go/build", []string{ + "zcgo.go", + }}, } // depsuffix records the allowed suffixes for source files. @@ -478,6 +481,7 @@ var gentab = []struct { }{ {"zdefaultcc.go", mkzdefaultcc}, {"zversion.go", mkzversion}, + {"zcgo.go", mkzcgo}, // not generated anymore, but delete the file if we see it {"enam.c", nil}, @@ -1061,9 +1065,9 @@ func cmdbootstrap() { } } -// Copied from go/build/build.go. // Cannot use go/build directly because cmd/dist for a new release // builds against an old release's go/build, which may be out of sync. +// To reduce duplication, we generate the list for go/build from this. var cgoEnabled = map[string]bool{ "darwin/386": true, "darwin/amd64": true, diff --git a/src/cmd/dist/buildgo.go b/src/cmd/dist/buildgo.go index 437e9dd9a0f..3dc9ff0dde3 100644 --- a/src/cmd/dist/buildgo.go +++ b/src/cmd/dist/buildgo.go @@ -4,7 +4,10 @@ package main -import "fmt" +import ( + "bytes" + "fmt" +) /* * Helpers for building cmd/go and cmd/cgo. @@ -37,3 +40,26 @@ func mkzdefaultcc(dir, file string) { file = file[:i] + "c" + file[i:] writefile(out, file, writeSkipSame) } + +// mkzcgo writes zcgo.go for go/build package: +// +// package build +// var cgoEnabled = map[string]bool{} +// +// It is invoked to write go/build/zcgo.go. +func mkzcgo(dir, file string) { + var buf bytes.Buffer + + fmt.Fprintf(&buf, + "// auto generated by go tool dist\n"+ + "\n"+ + "package build\n"+ + "\n"+ + "var cgoEnabled = map[string]bool{\n") + for plat := range cgoEnabled { + fmt.Fprintf(&buf, "\t%q: true,\n", plat) + } + fmt.Fprintf(&buf, "}") + + writefile(buf.String(), file, writeSkipSame) +} diff --git a/src/go/build/build.go b/src/go/build/build.go index c1b70bcdd75..e524925d0dc 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -256,34 +256,6 @@ func (ctxt *Context) SrcDirs() []string { // if set, or else the compiled code's GOARCH, GOOS, and GOROOT. var Default Context = defaultContext() -// Also known to cmd/dist/build.go. -var cgoEnabled = map[string]bool{ - "darwin/386": true, - "darwin/amd64": true, - "darwin/arm": true, - "darwin/arm64": true, - "dragonfly/amd64": true, - "freebsd/386": true, - "freebsd/amd64": true, - "freebsd/arm": true, - "linux/386": true, - "linux/amd64": true, - "linux/arm": true, - "linux/arm64": true, - "linux/ppc64le": true, - "android/386": true, - "android/amd64": true, - "android/arm": true, - "netbsd/386": true, - "netbsd/amd64": true, - "netbsd/arm": true, - "openbsd/386": true, - "openbsd/amd64": true, - "solaris/amd64": true, - "windows/386": true, - "windows/amd64": true, -} - func defaultContext() Context { var c Context