For $WORK reasons, I want an up-to-date Go cross compiler for OpenEmbedded. Taking a look at existing efforts I ended up forking dodgerblue’s repository in order to fix a couple of issues, most notably, the fact that in order to bootstrap 1.5, the recipe goes behind bitbake’s back and downloads 1.4 source.

I was working with Fido’s core-image-minimal just to make sure that everything compiled ok in a cross-build environment (more on that later). I ran into a weird issue that I haven’t been able to track down, which causes one step of the 1.5 build process to fail because it ignores arguments passed as part of the CC_FOR_TARGET environment variable. If I create a wrapper that calls the correct compiler with the correct flags (--sysroot being the important one), everything works, so for now that’s what’s present in the layer.

The other issue that I ran into is that OpenSwitch builds on x86_64 for x86_64. Strictly speaking it’s still cross-compilation because it builds for a different environment. The issue I’m running into is that I need a compiler to run on the host (x86_64linux_amd64) and a compiler to produce binaries for the target (genericx86-64linux_amd64). Go’s almost magical cross-compilation support works perfectly when building for a different OS/architecture combination, and breaks appart when building for two targets that have the same combination. Since I need to have CGO_ENABLED=1, this is where things stop workingi (binaries built for genericx86-64 don’t work in x86_64). I suspect it’s simply a matter of setting up the correct CC_FOR_TARGET values, but I still need to figure it out. If that doesn’t work, I will need to produce two sets of compilers, one native and one running on the host building images for the target.

I will probably rework the recipe some more, because I’d prefer to have a go-bootstrap dependency on go-cross for 1.5 onwards, just to avoid compiling 1.4 over and over again every single time I make a change. The next step after that is providing a class that other recipes can use to build Go projects, and probably providing a recipe for gb.

Enjoy!