Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: docs need section on cross-compiling #17620

Closed
networkimprov opened this issue Oct 26, 2016 · 7 comments
Closed

cmd/go: docs need section on cross-compiling #17620

networkimprov opened this issue Oct 26, 2016 · 7 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@networkimprov
Copy link

networkimprov commented Oct 26, 2016

I got OK to post this issue from:
https://groups.google.com/d/msg/golang-nuts/IW4FiCclZTw/45wa1V9UBwAJ

Add a new section to docs for cmd/go: "Cross Compiling"

Instructions to rebuild Go source for new platform:

sudo GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install -v -a std
sudo GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go install -v -a cmd

sudo is required if Go was installed via system package manager
CGO_ENABLED and CC are only required for cross-compiling with C source
CC varies for the toolchain installed

Instructions for cross compiling packages:

GOOS=linux GOARCH=arm go install -v github.com/id/package # .go only
GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=... go install -v github.com/id/package # .go & .c

GOARM=5|6|7 may be included to generate optimized code for that family

Output lands in:
$GOPATH/pkg/$GOOS_$GOARCH/github.com/id/package
$GOPATH/bin/$GOOS_$GOARCH/package

Also need instructions for Windows, OS X, etc.

@minux
Copy link
Member

minux commented Oct 27, 2016 via email

@networkimprov
Copy link
Author

Sudo is usually required to rebuild std & cmd. Dave Cheney has been saying:

Unless you have built Go from source and/or your user owns the path Go is installed in, [cross compiling] is one of the few cases where go build is recommended over go install.

The go package for my system installs the following; one must have root privs to modify it.

$ ls -la /lib/go/pkg/linux_amd64/
total 6632
drwxr-xr-x 30 root root    4096 Oct 12 22:57 .
drwxr-xr-x  7 root root    4096 Oct 12 23:13 ..
drwxr-xr-x  2 root root    4096 Oct 12 22:57 archive
-rw-r--r--  1 root root   98084 Sep  8 00:12 bufio.a
...

@davecheney
Copy link
Contributor

That is why I recommend go build.

For the record, I do not think we should document this on godoc.org. I
think it should be documented on the wiki because this documentation is
fragile, baroque, and all the things which combine the ease of use of a
cross target gcc toolchain, with the ease of use of cgo.

On Fri, Oct 28, 2016 at 3:04 AM, Liam notifications@github.com wrote:

Sudo is usually required to rebuild std & cmd. Dave Cheney has been saying:

Unless you have built Go from source and/or your user owns the path Go is
installed in, [cross compiling] is one of the few cases where go build is
recommended over go install.

The go package for my system installs the following; one must have root
privs to modify it.

$ ls -la /lib/go/pkg/linux_amd64/
total 6632
drwxr-xr-x 30 root root 4096 Oct 12 22:57 .
drwxr-xr-x 7 root root 4096 Oct 12 23:13 ..
drwxr-xr-x 2 root root 4096 Oct 12 22:57 archive
-rw-r--r-- 1 root root 98084 Sep 8 00:12 bufio.a
...


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#17620 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAcA3xnLdZAp8znXh2lnaB1qgDiD0znks5q4MuqgaJpZM4Khrn8
.

@networkimprov
Copy link
Author

All of the cross-compiling environment variables are documented in cmd/go, but not how to use them for practical purposes. It's an omission which generates recurring questions.

To my eye, the only arcane aspect is the value for CC, which can be left out of the command line examples and discussed in a separate paragraph.

@quentinmit quentinmit added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Oct 28, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Oct 28, 2016
@rsc
Copy link
Contributor

rsc commented Nov 11, 2016

@davecheney Thanks so much for the constructive, actionable feedback about our documentation!

@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 11, 2016
@networkimprov
Copy link
Author

@rsc I'm the one who posted the constructive, actionable feedback :-)

@rsc
Copy link
Contributor

rsc commented Apr 18, 2018

None of this setup is necessary anymore.

@rsc rsc closed this as completed Apr 18, 2018
@golang golang locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants