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
Enable cross compilation on buildGoPackage #63603
Enable cross compilation on buildGoPackage #63603
Conversation
046d14d
to
07a3d7d
Compare
This pull request has been mentioned on Nix community. There might be relevant details there: https://discourse.nixos.org/t/kubernetes-on-arm-raspberry-pi/3182/2 |
GOHOSTARCH = go.GOHOSTARCH or null; | ||
GOHOSTOS = go.GOHOSTOS or null; | ||
CC_FOR_TARGET = go.CC_FOR_TARGET or null; | ||
CXX_FOR_TARGET = go.CXX_FOR_TARGET or null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the build use CC_FOR_TARGET
or CXX_FOR_TARGET
in this case at all or is it just a helper for $CC
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I highly doubt you want the actual CC_FOR_TARGET
, which is only used for building compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the names are totally overloaded and I am using these as a helper for setting $CC
below like @Mic92 said.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying it here, makes it an environment variable in the build, which is not needed.
@@ -130,7 +137,7 @@ let | |||
echo "$d" | grep -q "\(/_\|examples\|Godeps\)" && return 0 | |||
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0 | |||
local OUT | |||
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" -v -p $NIX_BUILD_CORES $d 2>&1)"; then | |||
if ! OUT="$(CC=$CC_FOR_TARGET CXX=$CXX_FOR_TARGET go $cmd $buildFlags "''${buildFlagsArray[@]}" -v -p $NIX_BUILD_CORES $d 2>&1)"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if stdenv.buildPlatform != stdenv.targetPlatform
then CC_FOR_TARGET
becomes null
. This would lead to CC not being set at all. Should $CC
not have the correct value anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I will add checking for this corner case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check how this is different from the current value $CC
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mic92 I notice the following. Take pkgsCross.aarch64-multiplatform.ws
as an example. If you inspect pkgsCross.aarch64-multiplatform.ws.stdenv.hostPlatform.config
, you get x86_64-unknown-linux-gnu
on a Linux machine. This platform triple looks wrong. The reason could be cause buildGoPackage
actually uses go.stdenv.mkDerivation
instead of just stdenv
.
For reference here is the documentation for all environment variables used by the go compiler: https://golang.org/doc/install/source#environment |
This seems to fixed the build of |
3bd14e8
to
b82df87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better now
b82df87
to
6a27d63
Compare
@Mic92 A merge conflict was just resolved |
@Mic92 Since this PR induces a mass rebuild, is it a good idea to target |
Should be fine on master. go packages can be rebuild fast. |
Motivation for this change
Current
buildGoPackage
family of functors does not set necessary cross-compilation flags togo
calls. This PR will enable true cross-compilation by inheriting the necessary flags from thego
derivation, such asGOARCH
,GOOS
,CC
andCXX
.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)