Cross-compiled packages not being cached in Go 1.5?

203 views
Skip to first unread message

Jon Valdés

unread,
Apr 20, 2015, 3:49:31 AM4/20/15
to golan...@googlegroups.com
Hi there,

I'm working on a project where I'm cross compiling on every build (for linux amd64 and linux arm6, while working on a mac), and I've noticed compilation times are much much longer when cross-compiling than when building for my native platform. On my project, they go from ~3 seconds to ~25 seconds. I'm using go 1.5 from git, downloaded 2 days ago (go version output: "go version devel +f06795d Sat Apr 18 05:29:19 2015 +0000 darwin/amd64")

Example:

$ time go build -o rasp rasp_server.go

real 0m3.065s
user 0m2.222s
sys 0m0.611s

$ time GOOS=linux go build -o rasp rasp_server.go

real 0m24.909s
user 0m29.414s
sys 0m5.629s

$ time GOOS=linux go build -o rasp rasp_server.go

real 0m25.119s
user 0m29.788s
sys 0m5.566s


After using "go build -v", I noticed a big list of standard library packages is being recompiled on each "go build" call, but only when cross-compiling. Is this the expected behavior? I would have expected cross-compiled packages to be cached just like native ones are?

Thanks in advance!

Kind regards,
   Jon Valdes

Dave Cheney

unread,
Apr 20, 2015, 4:20:58 AM4/20/15
to golan...@googlegroups.com
remember the rule, go build builds, then discards, go install installs a copy.

the caviet to this is, dependig on where you have built go, you may encounter a permission error.

Jon Valdés

unread,
Apr 20, 2015, 6:28:04 AM4/20/15
to golan...@googlegroups.com
Hi Dave,

Not very intuitive I'd say, but that did indeed solve it.
Thanks a bunch!

Carlos Castillo

unread,
Apr 20, 2015, 11:59:17 AM4/20/15
to golan...@googlegroups.com
Despite Dave's usual (and correct) suggestion to use go install more often, I think for cross-compiling (especially to multiple targets) it is less useful. The -i flag to go build will do the equivalent of running go install on the dependencies (which you want for "caching" purposes), but let you install the final binary where you want under the name you want (as go build lets you do):

GOARCH=amd64 GOOS=linux go build -i -v -o myapp-linux-amd64
GOARCH=386 GOOS=linux go build -i -v -o myapp-linux-386
GOARCH=amd64 GOOS=darwin go build -i -v -o myapp-darwin-amd64
GOARCH=386 GOOS=darwin go build -i -v -o myapp-darwin-386

Obviously, you run into the same permission issues as go install if the stdlib is in a read-only location, and the cross-compiled packages are out of date (needing to be compiled and installed).

Jon Valdés

unread,
Apr 20, 2015, 1:25:32 PM4/20/15
to Carlos Castillo, golang-nuts
Oh, that's a nice feature I didn't know about!
Thanks a lot, Carlos!

Kind regards,
   Jon Valdes

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/9KyV77UZPlc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages