/src/go/build/zcgo.go
/src/go/doc/headscan
/src/internal/buildcfg/zbootstrap.go
+/src/internal/platform/zosarch.go
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/src/time/tzdata/zzipdata.go
}{
{"cmd/go/internal/cfg", []string{
"zdefaultcc.go",
+ }},
+ {"go/build", []string{
+ "zcgo.go",
+ }},
+ {"internal/platform", []string{
"zosarch.go",
}},
{"runtime/internal/sys", []string{
"zversion.go",
}},
- {"go/build", []string{
- "zcgo.go",
- }},
{"time/tzdata", []string{
"zzipdata.go",
}},
nameprefix string
gen func(string, string)
}{
+ {"zcgo.go", mkzcgo},
{"zdefaultcc.go", mkzdefaultcc},
{"zosarch.go", mkzosarch},
{"zversion.go", mkzversion},
- {"zcgo.go", mkzcgo},
{"zzipdata.go", mktzdata},
// not generated anymore, but delete the file if we see it
"runtime/internal/sys",
"cmd/cgo",
"cmd/go/internal/cfg",
+ "internal/platform",
"go/build",
}
return buf.String()
}
-// mkzosarch writes zosarch.go for cmd/go.
-func mkzosarch(dir, file string) {
- // sort for deterministic zosarch.go file
- var list []string
- for plat := range cgoEnabled {
- list = append(list, plat)
- }
- sort.Strings(list)
-
- var buf strings.Builder
- fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n\n")
- fmt.Fprintf(&buf, "package cfg\n\n")
- fmt.Fprintf(&buf, "var OSArchSupportsCgo = map[string]bool{\n")
- for _, plat := range list {
- fmt.Fprintf(&buf, "\t%s: %v,\n", quote(plat), cgoEnabled[plat])
- }
- fmt.Fprintf(&buf, "}\n")
-
- writefile(buf.String(), file, writeSkipSame)
-}
-
// mkzcgo writes zcgo.go for the go/build package:
//
// package build
-// var cgoEnabled = map[string]bool{}
+// const defaultCGO_ENABLED = <CGO_ENABLED>
//
// It is invoked to write go/build/zcgo.go.
func mkzcgo(dir, file string) {
- // sort for deterministic zcgo.go file
- var list []string
- for plat, hasCgo := range cgoEnabled {
- if hasCgo {
- list = append(list, plat)
- }
- }
- sort.Strings(list)
-
var buf strings.Builder
fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package build\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "const defaultCGO_ENABLED = %s\n", quote(os.Getenv("CGO_ENABLED")))
- fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "var cgoEnabled = map[string]bool{\n")
- for _, plat := range list {
- fmt.Fprintf(&buf, "\t%s: true,\n", quote(plat))
- }
- fmt.Fprintf(&buf, "}\n")
writefile(buf.String(), file, writeSkipSame)
}
import (
"fmt"
+ "sort"
"strings"
)
writefile(buf.String(), file, writeSkipSame)
}
+
+// mkzosarch writes zosarch.go for internal/platform.
+func mkzosarch(dir, file string) {
+ // sort for deterministic file contents.
+ var list []string
+ for plat := range cgoEnabled {
+ list = append(list, plat)
+ }
+ sort.Strings(list)
+
+ var buf strings.Builder
+ fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
+ fmt.Fprintln(&buf)
+ fmt.Fprintf(&buf, "package platform\n")
+ fmt.Fprintln(&buf)
+ fmt.Fprintf(&buf, "var osArchSupportsCgo = map[string]bool{\n")
+ for _, plat := range list {
+ fmt.Fprintf(&buf, "\t\t%s: %v,\n", quote(plat), cgoEnabled[plat])
+ }
+ fmt.Fprintf(&buf, "}\n")
+
+ writefile(buf.String(), file, writeSkipSame)
+}
mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot))
mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot))
+ mkzosarch("", pathf("%s/src/internal/platform/zosarch.go", goroot))
// Use $GOROOT/pkg/bootstrap as the bootstrap workspace root.
// We use a subdirectory of $GOROOT/pkg because that's the
// (1) environment, (2) go/env file, (3) runtime constants,
// while go/build.Default.GOOS/GOARCH are derived from the preference list
// (1) environment, (2) runtime constants.
+ //
// We know ctxt.GOOS/GOARCH == runtime.GOOS/GOARCH;
// no matter how that happened, go/build.Default will make the
// same decision (either the environment variables are set explicitly
"debug/elf"
"encoding/json"
"fmt"
+ "internal/platform"
"os"
"path/filepath"
"strings"
}
func CheckGOOSARCHPair(goos, goarch string) error {
- if _, ok := cfg.OSArchSupportsCgo[goos+"/"+goarch]; !ok && cfg.BuildContext.Compiler == "gc" {
+ if !platform.BuildModeSupported(cfg.BuildContext.Compiler, "default", goos, goarch) {
return fmt.Errorf("unsupported GOOS/GOARCH pair %s/%s", goos, goarch)
}
return nil
base.Fatalf("buildmode=%s not supported", cfg.BuildBuildmode)
}
- if !platform.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
+ if cfg.BuildBuildmode != "default" && !platform.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
base.Fatalf("-buildmode=%s not supported on %s/%s\n", cfg.BuildBuildmode, cfg.Goos, cfg.Goarch)
}
package main_test
import (
- "go/build"
+ "internal/testenv"
"runtime"
"testing"
}
switch {
- case !build.Default.CgoEnabled:
+ case !testenv.HasCGO():
t.Skipf("skipping - no cgo, so assuming external linking not available")
case runtime.GOOS == "plan9":
t.Skipf("skipping - external linking not supported")
# go list all should work with GOOS=linux because all packages build on Linux
env GOOS=linux
+env GOARCH=amd64
go list all
# go list all should work with GOOS=darwin, but it used to fail because
+env GOOS=linux
+
env GOARCH=amd64
env GOAMD64=v3
go list -f '{{context.ToolTags}}'
"cmd/internal/notsha256"
"flag"
"fmt"
- "go/build"
"internal/platform"
"internal/testenv"
"os"
func testGoAndCgoDisasm(t *testing.T, printCode bool, printGnuAsm bool) {
t.Parallel()
testDisasm(t, "fmthello.go", printCode, printGnuAsm)
- if build.Default.CgoEnabled {
+ if testenv.HasCGO() {
testDisasm(t, "fmthellocgo.go", printCode, printGnuAsm)
}
}
"internal/godebug"
"internal/goroot"
"internal/goversion"
+ "internal/platform"
"io"
"io/fs"
"os"
default:
// cgo must be explicitly enabled for cross compilation builds
if runtime.GOARCH == c.GOARCH && runtime.GOOS == c.GOOS {
- c.CgoEnabled = cgoEnabled[c.GOOS+"/"+c.GOARCH]
+ c.CgoEnabled = platform.CgoSupported(c.GOOS, c.GOARCH)
break
}
c.CgoEnabled = false
FMT, internal/goexperiment
< internal/buildcfg;
- go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion
+ go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform
< go/build;
# databases
}
platform := goos + "/" + goarch
+ if _, ok := osArchSupportsCgo[platform]; !ok {
+ return false // platform unrecognized
+ }
switch buildmode {
case "archive":
}
return false
}
+
+// CgoSupported reports whether goos/goarch supports cgo.\n")
+func CgoSupported(goos, goarch string) bool {
+ return osArchSupportsCgo[goos+"/"+goarch]
+}