mirror of
https://github.com/golang/go
synced 2024-11-19 11:14:47 -07:00
cmd/dist: fix default GOOS/GOARCH for cross-compile
Before this CL, if you are on a darwin/amd64 machine and cross-compile 9g for a linux/ppc64 machine, when you copy 9g over to that kind of machine and run it, you'll find it thinks the default object target is darwin/amd64. Not useful. Make the default target linux/ppc64 in this case. More useful. Change-Id: I62f2e9cb5f60b3077a922b31cd023a9cb7a6cfda Reviewed-on: https://go-review.googlesource.com/6407 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
5324cf2d45
commit
86a7c85f83
21
src/cmd/dist/buildruntime.go
vendored
21
src/cmd/dist/buildruntime.go
vendored
@ -40,27 +40,38 @@ func mkzversion(dir, file string) {
|
|||||||
// const defaultGOROOT = <goroot>
|
// const defaultGOROOT = <goroot>
|
||||||
// const defaultGO386 = <go386>
|
// const defaultGO386 = <go386>
|
||||||
// const defaultGOARM = <goarm>
|
// const defaultGOARM = <goarm>
|
||||||
// const defaultGOOS = <goos>
|
// const defaultGOOS = runtime.GOOS
|
||||||
// const defaultGOARCH = <goarch>
|
// const defaultGOARCH = runtime.GOARCH
|
||||||
// const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
|
// const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
|
||||||
// const version = <version>
|
// const version = <version>
|
||||||
// const goexperiment = <goexperiment>
|
// const goexperiment = <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) {
|
func mkzbootstrap(file string) {
|
||||||
out := fmt.Sprintf(
|
out := fmt.Sprintf(
|
||||||
"// auto generated by go tool dist\n"+
|
"// auto generated by go tool dist\n"+
|
||||||
"\n"+
|
"\n"+
|
||||||
"package obj\n"+
|
"package obj\n"+
|
||||||
"\n"+
|
"\n"+
|
||||||
|
"import \"runtime\"\n"+
|
||||||
|
"\n"+
|
||||||
"const defaultGOROOT = `%s`\n"+
|
"const defaultGOROOT = `%s`\n"+
|
||||||
"const defaultGO386 = `%s`\n"+
|
"const defaultGO386 = `%s`\n"+
|
||||||
"const defaultGOARM = `%s`\n"+
|
"const defaultGOARM = `%s`\n"+
|
||||||
"const defaultGOOS = `%s`\n"+
|
"const defaultGOOS = runtime.GOOS\n"+
|
||||||
"const defaultGOARCH = `%s`\n"+
|
"const defaultGOARCH = runtime.GOARCH\n"+
|
||||||
"const defaultGO_EXTLINK_ENABLED = `%s`\n"+
|
"const defaultGO_EXTLINK_ENABLED = `%s`\n"+
|
||||||
"const version = `%s`\n"+
|
"const version = `%s`\n"+
|
||||||
"const goexperiment = `%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)
|
writefile(out, file, 0)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user