go – Jay R. Wren – lazy dawg evarlast http://jrwren.wrenfam.com/blog babblings of a computer loving fool Wed, 15 Feb 2017 02:57:57 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.2 cross compiling go and go install v. go build and caching the results http://jrwren.wrenfam.com/blog/2017/01/26/cross-compiling-go-and-go-install-v-go-build-and-caching-the-results/ http://jrwren.wrenfam.com/blog/2017/01/26/cross-compiling-go-and-go-install-v-go-build-and-caching-the-results/#respond Thu, 26 Jan 2017 19:30:50 +0000 http://jrwren.wrenfam.com/blog/?p=1277 Continue reading "cross compiling go and go install v. go build and caching the results"]]> I am following Dave Chaney’s advice from here https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

I am on OSX using go installed from homebrew, so the writability of GOROOT in /usr/local/Cellar… is not an issue as stated in Dave’s post.

How can I reap the benefit of cached package builds when cross compiling?

`go install` uses the cache and places the resulting binary in $GOPATH/bin/$GOOS_$GOARCH/ instead of in $GOPATH/bin/

Of course, now that I’m writing this as a blog post, for myself, I see this is already mostly documented in the link from Dave’s post to medium: https://medium.com/@rakyll/go-1-5-cross-compilation-488092ba44ec#.6ue7ljf7v including a nice command to cross compile the std library in the system cache.

You can populate the stdlib cross compile pkg cache in GOROOT by running this command, changing env vars for each platform you wish to target:

GOOS=darwin GOARCH=amd64 sudo -E go install std

Now your cross compiles do not have to recompile the standard library packages.

]]>
http://jrwren.wrenfam.com/blog/2017/01/26/cross-compiling-go-and-go-install-v-go-build-and-caching-the-results/feed/ 0