[go] cmd/dist: fix default GOOS/GOARCH for cross-compile

85 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
Mar 1, 2015, 9:51:16 PM3/1/15
to Rob Pike, Ian Lance Taylor, Russ Cox, golang-co...@googlegroups.com
Reviewers: Rob Pike

Russ Cox uploaded a change:
https://go-review.googlesource.com/6407

cmd/dist: fix default GOOS/GOARCH for cross-compile

Change-Id: I62f2e9cb5f60b3077a922b31cd023a9cb7a6cfda
---
M src/cmd/dist/buildruntime.go
1 file changed, 16 insertions(+), 5 deletions(-)



diff --git a/src/cmd/dist/buildruntime.go b/src/cmd/dist/buildruntime.go
index 1123265..73f4d8e 100644
--- a/src/cmd/dist/buildruntime.go
+++ b/src/cmd/dist/buildruntime.go
@@ -40,27 +40,38 @@
// const defaultGOROOT = <goroot>
// const defaultGO386 = <go386>
// const defaultGOARM = <goarm>
-// const defaultGOOS = <goos>
-// const defaultGOARCH = <goarch>
+// const defaultGOOS = runtime.GOOS
+// const defaultGOARCH = runtime.GOARCH
// const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
// const version = <version>
// 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) {
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)
}

--
https://go-review.googlesource.com/6407
Gerrit-Reviewer: Rob Pike <r...@golang.org>

Mikio Hara (Gerrit)

unread,
Mar 1, 2015, 10:07:21 PM3/1/15
to Russ Cox, Rob Pike, golang-co...@googlegroups.com
Mikio Hara has posted comments on this change.

cmd/dist: fix default GOOS/GOARCH for cross-compile

Patch Set 1: Code-Review+1

aha

--
https://go-review.googlesource.com/6407
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-HasComments: No

Dave Cheney (Gerrit)

unread,
Mar 2, 2015, 12:46:21 AM3/2/15
to Russ Cox, Rob Pike, Mikio Hara, golang-co...@googlegroups.com
Dave Cheney has posted comments on this change.

cmd/dist: fix default GOOS/GOARCH for cross-compile

Patch Set 1: Code-Review+1 Run-TryBot+1

--
https://go-review.googlesource.com/6407
Gerrit-Reviewer: Dave Cheney <da...@cheney.net>

Gobot Gobot (Gerrit)

unread,
Mar 2, 2015, 12:47:09 AM3/2/15
to Russ Cox, Rob Pike, Mikio Hara, Dave Cheney, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

cmd/dist: fix default GOOS/GOARCH for cross-compile

Patch Set 1:

TryBots beginning. Status page: http://farmer.golang.org/try?commit=d665bf91

--
https://go-review.googlesource.com/6407
Gerrit-Reviewer: Dave Cheney <da...@cheney.net>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>

Gobot Gobot (Gerrit)

unread,
Mar 2, 2015, 1:08:26 AM3/2/15
to Russ Cox, Rob Pike, Mikio Hara, Dave Cheney, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

cmd/dist: fix default GOOS/GOARCH for cross-compile

Patch Set 1: TryBot-Result+1

TryBots are happy.

Rob Pike (Gerrit)

unread,
Mar 2, 2015, 8:38:42 AM3/2/15
to Russ Cox, Rob Pike, Mikio Hara, Dave Cheney, Gobot Gobot, golang-co...@googlegroups.com
Rob Pike has posted comments on this change.

cmd/dist: fix default GOOS/GOARCH for cross-compile

Patch Set 1: Code-Review+2

the CL description could be more explanatory

Russ Cox (Gerrit)

unread,
Mar 2, 2015, 12:51:46 PM3/2/15
to Russ Cox, Gobot Gobot, Dave Cheney, Rob Pike, Mikio Hara, golang-co...@googlegroups.com
Reviewers: Gobot Gobot, Dave Cheney, Rob Pike, Mikio Hara

Russ Cox uploaded a new patch set:
https://go-review.googlesource.com/6407

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
---
M src/cmd/dist/buildruntime.go
1 file changed, 16 insertions(+), 5 deletions(-)


Russ Cox (Gerrit)

unread,
Mar 2, 2015, 12:51:51 PM3/2/15
to Russ Cox, golang-...@googlegroups.com, Rob Pike, Mikio Hara, Dave Cheney, Gobot Gobot, golang-co...@googlegroups.com
Russ Cox has submitted this change and it was merged.

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>
---
M src/cmd/dist/buildruntime.go
1 file changed, 16 insertions(+), 5 deletions(-)

Approvals:
Rob Pike: Looks good to me, approved


--
https://go-review.googlesource.com/6407
Gerrit-Reviewer: Dave Cheney <da...@cheney.net>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Mikio Hara <mikioh...@gmail.com>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Reply all
Reply to author
Forward
0 new messages