diff --git a/src/cmd/dist/buildruntime.go b/src/cmd/dist/buildruntime.go index 112326558a7..73f4d8eaf16 100644 --- a/src/cmd/dist/buildruntime.go +++ b/src/cmd/dist/buildruntime.go @@ -40,27 +40,38 @@ func mkzversion(dir, file string) { // const defaultGOROOT = // const defaultGO386 = // const defaultGOARM = -// const defaultGOOS = -// const defaultGOARCH = +// const defaultGOOS = runtime.GOOS +// const defaultGOARCH = runtime.GOARCH // const defaultGO_EXTLINK_ENABLED = // const version = // const goexperiment = // +// The use of runtime.GOOS and runtime.GOARCH makes sure that +// a cross-compiled compiler expects to compile for its own target +// system. That is, if on a Mac you do: +// +// GOOS=linux GOARCH=ppc64 go build cmd/9g +// +// the resulting compiler will default to generating linux/ppc64 object files. +// This is more useful than having it default to generating objects for the +// original target (in this example, a Mac). func mkzbootstrap(file string) { out := fmt.Sprintf( "// auto generated by go tool dist\n"+ "\n"+ "package obj\n"+ "\n"+ + "import \"runtime\"\n"+ + "\n"+ "const defaultGOROOT = `%s`\n"+ "const defaultGO386 = `%s`\n"+ "const defaultGOARM = `%s`\n"+ - "const defaultGOOS = `%s`\n"+ - "const defaultGOARCH = `%s`\n"+ + "const defaultGOOS = runtime.GOOS\n"+ + "const defaultGOARCH = runtime.GOARCH\n"+ "const defaultGO_EXTLINK_ENABLED = `%s`\n"+ "const version = `%s`\n"+ "const goexperiment = `%s`\n", - goroot_final, go386, goarm, gohostos, gohostarch, goextlinkenabled, findgoversion(), os.Getenv("GOEXPERIMENT")) + goroot_final, go386, goarm, goextlinkenabled, findgoversion(), os.Getenv("GOEXPERIMENT")) writefile(out, file, 0) }