// deptab lists changes to the default dependencies for a given prefix.
// deps ending in /* read the whole directory; deps beginning with -
// exclude files with that prefix.
+// Note that this table applies only to the build of cmd/go,
+// after the main compiler bootstrap.
var deptab = []struct {
prefix string // prefix of target
dep []string // dependency tweaks for targets with that prefix
// It is invoked to write cmd/go/internal/cfg/zdefaultcc.go
// but we also write cmd/cgo/zdefaultcc.go
func mkzdefaultcc(dir, file string) {
- var buf bytes.Buffer
- fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
- fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "package cfg\n")
- fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "const DefaultCC = `%s`\n", defaultcctarget)
- fmt.Fprintf(&buf, "const DefaultCXX = `%s`\n", defaultcxxtarget)
- fmt.Fprintf(&buf, "const DefaultPkgConfig = `%s`\n", defaultpkgconfigtarget)
-
- writefile(buf.String(), file, writeSkipSame)
- buf.Reset()
+ if strings.Contains(file, filepath.FromSlash("go/internal/cfg")) {
+ var buf bytes.Buffer
+ fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
+ fmt.Fprintln(&buf)
+ fmt.Fprintf(&buf, "package cfg\n")
+ fmt.Fprintln(&buf)
+ fmt.Fprintf(&buf, "const DefaultCC = `%s`\n", defaultcctarget)
+ fmt.Fprintf(&buf, "const DefaultCXX = `%s`\n", defaultcxxtarget)
+ fmt.Fprintf(&buf, "const DefaultPkgConfig = `%s`\n", defaultpkgconfigtarget)
+ writefile(buf.String(), file, writeSkipSame)
+ return
+ }
+ var buf bytes.Buffer
fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package main\n")
fmt.Fprintf(&buf, "const defaultCC = `%s`\n", defaultcctarget)
fmt.Fprintf(&buf, "const defaultCXX = `%s`\n", defaultcxxtarget)
fmt.Fprintf(&buf, "const defaultPkgConfig = `%s`\n", defaultpkgconfigtarget)
-
- // Convert file name.
- file = strings.Replace(file, filepath.FromSlash("go/internal/cfg"), "cgo", 1)
writefile(buf.String(), file, writeSkipSame)
}
"cmd/asm/internal/asm",
"cmd/asm/internal/flags",
"cmd/asm/internal/lex",
+ "cmd/cgo",
"cmd/compile",
"cmd/compile/internal/amd64",
"cmd/compile/internal/arm",
"cmd/link/internal/s390x",
"cmd/link/internal/sym",
"cmd/link/internal/x86",
+ "debug/dwarf",
+ "debug/elf",
+ "debug/macho",
"debug/pe",
"math/big",
"math/bits",
src := pathf("%s/src/%s", goroot, dir)
dst := pathf("%s/%s", base, dir)
xmkdirall(dst)
+ if dir == "cmd/cgo" {
+ // Write to src because we need the file both for bootstrap
+ // and for later in the main build.
+ mkzdefaultcc("", pathf("%s/zdefaultcc.go", src))
+ }
Dir:
for _, name := range xreaddirfiles(src) {
for _, pre := range ignorePrefixes {
var deps []string
// External linking mode forces an import of runtime/cgo.
+ // TODO(rsc): The GOROOT exception here is mainly to avoid a circular
+ // dependency when building cmd/cgo, which the build of
+ // runtime/cgo needs, but as of CL 68338 we now build
+ // cmd/cgo during cmd/dist, so that exception is no longer
+ // needed. At some point it may be worthwhile to remove the
+ // GOROOT exception here.
+ // Note that the condition here should also match the condition
+ // in ../work/build.go's gcToolchain.ld that controls disabling
+ // external linking during the link step.
if cfg.ExternalLinkingForced(p.Goroot) {
deps = append(deps, "runtime/cgo")
}
"path"
"path/filepath"
"regexp"
- "runtime"
"sort"
"strings"
"text/template"
if deps["C"] {
delete(deps, "C")
deps["runtime/cgo"] = true
- if cfg.Goos == runtime.GOOS && cfg.Goarch == runtime.GOARCH && !cfg.BuildRace && !cfg.BuildMSan {
- deps["cmd/cgo"] = true
- }
}
// Ignore pseudo-packages.
delete(deps, "unsafe")
// If p is a tool, delay the installation until the end of the build.
// This avoids installing assemblers/compilers that are being executed
// by other steps in the build.
- // cmd/cgo is handled specially in b.Action, so that we can
- // both build and use it in the same 'go install'.
Action := b.Action(ModeInstall, ModeInstall, p)
- if load.GoTools[p.ImportPath] == load.ToTool && p.ImportPath != "cmd/cgo" {
+ if load.GoTools[p.ImportPath] == load.ToTool {
a.Deps = append(a.Deps, Action.Deps...)
Action.Deps = append(Action.Deps, a)
tools = append(tools, Action)
Args []string // additional args for runProgram
triggers []*Action // inverse of deps
- cgo *Action // action for cgo binary if needed
// Generated files, directories.
Link bool // target is executable, not just package
}
}
- // If we are not doing a cross-build, then record the binary we'll
- // generate for cgo as a dependency of the build of any package
- // using cgo, to make sure we do not overwrite the binary while
- // a package is using it. If this is a cross-build, then the cgo we
- // are writing is not the cgo we need to use.
- if cfg.Goos == runtime.GOOS && cfg.Goarch == runtime.GOARCH && !cfg.BuildRace && !cfg.BuildMSan {
- if (len(p.CgoFiles) > 0 || p.Standard && p.ImportPath == "runtime/cgo") && !cfg.BuildLinkshared && cfg.BuildBuildmode != "shared" {
- var stk load.ImportStack
- p1 := load.LoadPackage("cmd/cgo", &stk)
- if p1.Error != nil {
- base.Fatalf("load cmd/cgo: %v", p1.Error)
- }
- a.cgo = b.Action(depMode, depMode, p1)
- a.Deps = append(a.Deps, a.cgo)
- }
- }
-
if p.Standard {
switch p.ImportPath {
case "builtin", "unsafe":
// external linking mode forces an import of runtime/cgo (and
// math on arm). So if it was not passed on the command line and
// it is not present in another shared library, add it here.
+ // TODO(rsc): This should probably be changed to use load.LinkerDeps(p).
gccgo := cfg.BuildToolchainName == "gccgo"
if !gccgo {
seencgo := false
sfiles = nil
}
- var cgoExe string
- if a.cgo != nil && a.cgo.Target != "" {
- cgoExe = a.cgo.Target
- } else {
- cgoExe = base.Tool("cgo")
- }
- outGo, outObj, err := b.cgo(a, cgoExe, objdir, pcCFLAGS, pcLDFLAGS, cgofiles, objdirCgofiles, gccfiles, cxxfiles, a.Package.MFiles, a.Package.FFiles)
+ outGo, outObj, err := b.cgo(a, base.Tool("cgo"), objdir, pcCFLAGS, pcLDFLAGS, cgofiles, objdirCgofiles, gccfiles, cxxfiles, a.Package.MFiles, a.Package.FFiles)
if err != nil {
return err
}
// but the whole-GOROOT prohibition matches the similar
// logic in ../load/pkg.go that decides whether to add an
// implicit runtime/cgo dependency.
+ // TODO(rsc): We may be able to remove this exception
+ // now that CL 68338 has made cmd/cgo not a special case.
+ // See the longer comment in ../load/pkg.go.
ldflags = removeLinkmodeExternal(ldflags)
}
ldflags = setextld(ldflags, compiler)