defaultpkgconfig string
defaultldso string
- rebuildall bool
- defaultclang bool
- noOpt bool
+ rebuildall bool
+ noOpt bool
vflag int // verbosity
)
gogcflags = os.Getenv("BOOT_GO_GCFLAGS")
goldflags = os.Getenv("BOOT_GO_LDFLAGS")
- cc, cxx := "gcc", "g++"
- if defaultclang {
- cc, cxx = "clang", "clang++"
- }
- defaultcc = compilerEnv("CC", cc)
- defaultcxx = compilerEnv("CXX", cxx)
+ defaultcc = compilerEnv("CC", "")
+ defaultcxx = compilerEnv("CXX", "")
b = os.Getenv("PKG_CONFIG")
if b == "" {
return m
}
+// clangos lists the operating systems where we prefer clang to gcc.
+var clangos = []string{
+ "darwin", // macOS 10.9 and later require clang
+ "freebsd", // FreeBSD 10 and later do not ship gcc
+ "openbsd", // OpenBSD ships with GCC 4.2, which is now quite old.
+}
+
// compilerEnvLookup returns the compiler settings for goos/goarch in map m.
-func compilerEnvLookup(m map[string]string, goos, goarch string) string {
+// kind is "CC" or "CXX".
+func compilerEnvLookup(kind string, m map[string]string, goos, goarch string) string {
if cc := m[goos+"/"+goarch]; cc != "" {
return cc
}
- return m[""]
+ if cc := m[""]; cc != "" {
+ return cc
+ }
+ for _, os := range clangos {
+ if goos == os {
+ if kind == "CXX" {
+ return "clang++"
+ }
+ return "clang"
+ }
+ }
+ if kind == "CXX" {
+ return "g++"
+ }
+ return "gcc"
}
// rmworkdir deletes the work directory.
xremove(pathf("%s/bin/%s", goroot, old))
}
- // For release, make sure excluded things are excluded.
+ // Special release-specific setup.
goversion := findgoversion()
- if strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta")) {
+ isRelease := strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta"))
+ if isRelease {
+ // Make sure release-excluded things are excluded.
for _, dir := range unreleased {
if p := pathf("%s/%s", goroot, dir); isdir(p) {
fatalf("%s should not exist in release build", p)
}
}
}
+ if isRelease || os.Getenv("GO_BUILDER_NAME") != "" {
+ // Add -trimpath for reproducible builds of releases.
+ // Include builders so that -trimpath is well-tested ahead of releases.
+ // Do not include local development, so that people working in the
+ // main branch for day-to-day work on the Go toolchain itself can
+ // still have full paths for stack traces for compiler crashes and the like.
+ // toolenv = append(toolenv, "GOFLAGS=-trimpath")
+ }
}
/*
if goldflags != "" {
link = append(link, goldflags)
}
- link = append(link, "-extld="+compilerEnvLookup(defaultcc, goos, goarch))
+ link = append(link, "-extld="+compilerEnvLookup("CC", defaultcc, goos, goarch))
link = append(link, "-L="+pathf("%s/pkg/obj/go-bootstrap/%s_%s", goroot, goos, goarch))
link = append(link, "-o", pathf("%s/%s%s", tooldir, elem, exe))
targ = len(link) - 1
fmt.Fprintf(timeLogFile, "%s %+.1fs %s %s\n", t.Format(time.UnixDate), t.Sub(timeLogStart).Seconds(), op, name)
}
+// toolenv is the environment to use when building cmd.
+// We disable cgo to get static binaries for cmd/go and cmd/pprof,
+// so that they work on systems without the same dynamic libraries
+// as the original build system.
+// In release branches, we add -trimpath for reproducible builds.
+// In the main branch we leave it off, so that compiler crashes and
+// the like have full path names for easier navigation to source files.
+var toolenv = []string{"CGO_ENABLED=0"}
+
var toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link"}
// The bootstrap command runs a build from scratch,
xprintf("\n")
}
xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n")
- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
+ os.Setenv("CC", compilerEnvLookup("CC", defaultcc, goos, goarch))
// Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
os.Setenv("GOEXPERIMENT", goexperiment)
- goInstall(goBootstrap, toolchain...)
+ goInstall(toolenv, goBootstrap, toolchain...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
copyfile(pathf("%s/compile2", tooldir), pathf("%s/compile", tooldir), writeExec)
xprintf("\n")
}
xprintf("Building Go toolchain3 using go_bootstrap and Go toolchain2.\n")
- goInstall(goBootstrap, append([]string{"-a"}, toolchain...)...)
+ goInstall(toolenv, goBootstrap, append([]string{"-a"}, toolchain...)...)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
xprintf("\n")
}
xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch)
- goInstall(goBootstrap, "std", "cmd")
- checkNotStale(goBootstrap, "std", "cmd")
- checkNotStale(cmdGo, "std", "cmd")
+ goInstall(nil, goBootstrap, "std")
+ goInstall(toolenv, goBootstrap, "cmd")
+ checkNotStale(nil, goBootstrap, "std")
+ checkNotStale(toolenv, goBootstrap, "cmd")
+ checkNotStale(nil, cmdGo, "std")
+ checkNotStale(toolenv, cmdGo, "cmd")
timelog("build", "target toolchain")
if vflag > 0 {
goarch = oldgoarch
os.Setenv("GOOS", goos)
os.Setenv("GOARCH", goarch)
- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
+ os.Setenv("CC", compilerEnvLookup("CC", defaultcc, goos, goarch))
xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
}
- targets := []string{"std", "cmd"}
- goInstall(goBootstrap, targets...)
- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
- checkNotStale(goBootstrap, targets...)
- checkNotStale(cmdGo, targets...)
+ goInstall(nil, goBootstrap, "std")
+ goInstall(toolenv, goBootstrap, "cmd")
+ checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
+ checkNotStale(nil, goBootstrap, "std")
+ checkNotStale(toolenv, goBootstrap, "cmd")
+ checkNotStale(nil, cmdGo, "std")
+ checkNotStale(toolenv, cmdGo, "cmd")
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
+ checkNotStale(toolenv, goBootstrap, append(toolchain, "runtime/internal/sys")...)
copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec)
}
oldcc := os.Getenv("CC")
os.Setenv("GOOS", gohostos)
os.Setenv("GOARCH", gohostarch)
- os.Setenv("CC", compilerEnvLookup(defaultcc, gohostos, gohostarch))
- goCmd(cmdGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath)
+ os.Setenv("CC", compilerEnvLookup("CC", defaultcc, gohostos, gohostarch))
+ goCmd(nil, cmdGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath)
// Restore environment.
// TODO(elias.naur): support environment variables in goCmd?
os.Setenv("GOOS", goos)
return ""
}
-func goInstall(goBinary string, args ...string) {
- goCmd(goBinary, "install", args...)
+func goInstall(env []string, goBinary string, args ...string) {
+ goCmd(env, goBinary, "install", args...)
}
func appendCompilerFlags(args []string) []string {
return args
}
-func goCmd(goBinary string, cmd string, args ...string) {
+func goCmd(env []string, goBinary string, cmd string, args ...string) {
goCmd := []string{goBinary, cmd}
if noOpt {
goCmd = append(goCmd, "-tags=noopt")
goCmd = append(goCmd, "-p=1")
}
- run(workdir, ShowOutput|CheckExit, append(goCmd, args...)...)
+ runEnv(workdir, ShowOutput|CheckExit, env, append(goCmd, args...)...)
}
-func checkNotStale(goBinary string, targets ...string) {
+func checkNotStale(env []string, goBinary string, targets ...string) {
goCmd := []string{goBinary, "list"}
if noOpt {
goCmd = append(goCmd, "-tags=noopt")
goCmd = appendCompilerFlags(goCmd)
goCmd = append(goCmd, "-f={{if .Stale}}\tSTALE {{.ImportPath}}: {{.StaleReason}}{{end}}")
- out := run(workdir, CheckExit, append(goCmd, targets...)...)
+ out := runEnv(workdir, CheckExit, env, append(goCmd, targets...)...)
if strings.Contains(out, "\tSTALE ") {
os.Setenv("GODEBUG", "gocachehash=1")
for _, target := range []string{"runtime/internal/sys", "cmd/dist", "cmd/link"} {
if !needCC() {
return
}
- cc, err := quotedSplit(defaultcc[""])
+ cc1 := defaultcc[""]
+ if cc1 == "" {
+ cc1 = "gcc"
+ for _, os := range clangos {
+ if gohostos == os {
+ cc1 = "clang"
+ break
+ }
+ }
+ }
+ cc, err := quotedSplit(cc1)
if err != nil {
fatalf("split CC: %v", err)
}
if t.rebuild {
t.out("Building packages and commands.")
// Force rebuild the whole toolchain.
- goInstall("go", append([]string{"-a"}, toolchain...)...)
+ goInstall(toolenv, "go", append([]string{"-a"}, toolchain...)...)
}
if !t.listMode {
// to break if we don't automatically refresh things here.
// Rebuilding is a shortened bootstrap.
// See cmdbootstrap for a description of the overall process.
- goInstall("go", toolchain...)
- goInstall("go", toolchain...)
- goInstall("go", "std", "cmd")
+ goInstall(toolenv, "go", toolchain...)
+ goInstall(toolenv, "go", toolchain...)
+ goInstall(toolenv, "go", "cmd")
+ goInstall(nil, "go", "std")
} else {
// The Go builder infrastructure should always begin running tests from a
// clean, non-stale state, so there is no need to rebuild the world.
// The cache used by dist when building is different from that used when
// running dist test, so rebuild (but don't install) std and cmd to make
// sure packages without install targets are cached so they are not stale.
- goCmd("go", "build", "std", "cmd") // make sure dependencies of targets are cached
- if builder == "aix-ppc64" {
+ goCmd(toolenv, "go", "build", "cmd") // make sure dependencies of targets are cached
+ goCmd(nil, "go", "build", "std")
+ checkNotStale(nil, "go", "std")
+ if builder != "aix-ppc64" {
// The aix-ppc64 builder for some reason does not have deterministic cgo
// builds, so "cmd" is stale. Fortunately, most of the tests don't care.
// TODO(#56896): remove this special case once the builder supports
// determistic cgo builds.
- checkNotStale("go", "std")
- } else {
- checkNotStale("go", "std", "cmd")
+ checkNotStale(toolenv, "go", "cmd")
}
}
}
// Check for static linking support
var staticCheck rtPreFunc
cmd := t.dirCmd("misc/cgo/test",
- compilerEnvLookup(defaultcc, goos, goarch), "-xc", "-o", "/dev/null", "-static", "-")
+ compilerEnvLookup("CC", defaultcc, goos, goarch), "-xc", "-o", "/dev/null", "-static", "-")
cmd.Stdin = strings.NewReader("int main() {}")
cmd.Stdout, cmd.Stderr = nil, nil // Discard output
if err := cmd.Run(); err != nil {
// running in parallel with earlier tests, or if it has some other reason
// for needing the earlier tests to be done.
func (t *tester) runPending(nextTest *distTest) {
- checkNotStale("go", "std")
+ checkNotStale(nil, "go", "std")
worklist := t.worklist
t.worklist = nil
for _, w := range worklist {
log.Printf("Failed: %v", w.err)
t.failed = true
}
- checkNotStale("go", "std")
+ checkNotStale(nil, "go", "std")
}
if t.failed && !t.keepGoing {
fatalf("FAILED")
}
func (t *tester) hasCxx() bool {
- cxx, _ := exec.LookPath(compilerEnvLookup(defaultcxx, goos, goarch))
+ cxx, _ := exec.LookPath(compilerEnvLookup("CXX", defaultcxx, goos, goarch))
return cxx != ""
}