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
buildGoModule: fix cross-compilation with CGO_ENABLED=1 #107553
Conversation
Is there a reason why the cc-wrapper setup hook isn't setting it? |
Before that line introduced in this PR, things are set as follows:
The change sets
I'm not really sure where that previous |
Ah the issue is that it's using If you make it |
IIRC I copied it from the buildGoPackage function without giving it much thought. I'm not sure why it's this way either. |
That sounds like the preferred way. It would also fix |
c00dabf
to
aa8ac67
Compare
I updated the PR. Do we also need some of the |
I think we do. |
When building a go binary that's linking against some .so/.a, while cross-compiling, we need to pass the correct compiler, otherwise `go build` will fail with the not-so helpful error message: ``` gcc_arm64.S: Assembler messages: gcc_arm64.S:28: Error: no such instruction: `stp x29,x30,[sp,' gcc_arm64.S:32: Error: too many memory references for `mov' gcc_arm64.S:34: Error: no such instruction: `stp x19,x20,[sp,' gcc_arm64.S:37: Error: no such instruction: `stp x21,x22,[sp,' gcc_arm64.S:40: Error: no such instruction: `stp x23,x24,[sp,' gcc_arm64.S:43: Error: no such instruction: `stp x25,x26,[sp,' gcc_arm64.S:46: Error: no such instruction: `stp x27,x28,[sp,' gcc_arm64.S:50: Error: too many memory references for `mov' gcc_arm64.S:51: Error: too many memory references for `mov' gcc_arm64.S:52: Error: too many memory references for `mov' gcc_arm64.S:54: Error: no such instruction: `blr x20' gcc_arm64.S:55: Error: no such instruction: `blr x19' gcc_arm64.S:57: Error: no such instruction: `ldp x27,x28,[sp,' gcc_arm64.S:60: Error: no such instruction: `ldp x25,x26,[sp,' gcc_arm64.S:63: Error: no such instruction: `ldp x23,x24,[sp,' gcc_arm64.S:66: Error: no such instruction: `ldp x21,x22,[sp,' gcc_arm64.S:69: Error: no such instruction: `ldp x19,x20,[sp,' gcc_arm64.S:72: Error: no such instruction: `ldp x29,x30,[sp],' ```
aa8ac67
to
3c8981e
Compare
I decided to keep this out of this PR - this might already be autodetected properly, and we can even remove it from the other derivation: https://binx.io/blog/2018/11/25/go-cross-compilation/ Also, I managed to produce some binaries with this that did run, and failed to build at all before this PR. |
When building a go binary that's linking against some .so/.a, while
cross-compiling, we need to pass the correct compiler, otherwise
go build
will fail with the not-so helpful error message:Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)