rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Add support for cross cc compilers

Open layus opened this issue 3 years ago • 2 comments

In the current state, cc.nix is not compatible with crossPkgs and cross compilers.

This PR makes some progress by using buildPackages instead of pkgs where needed (everywhere, except stdenv.cc).

To get a cross toolchain one still needs to provide a nixpkgs with an hard-coded cross config. Alternatively, an expression that provides a cross compiler should also work without modifying the nixpkgs argument to nixpkgs_cc_configure.

But providing such an expression is difficult because the wrapper (the buildEnv call) needs to be duplicated. Any reason why we do not always apply it ? Worst case the user expression needs to be coaxed a bit to provide binutils, isClang and targetPrefix. Not really hard.

A tricky one is also wrapCCWith. Not sure how it works in mixed setups.

Finally, I could use some help writing tests in this new repo layout.

layus avatar Jun 28 '22 13:06 layus

Nice! You beat me to it... :smile:

Note, that this is not only useful for cross-compilation, but also when using a static CC based on musl for example (think pkgs.pkgsStatic.clangStdenv.cc for example).

I'll have a deeper look when I found some time later...

avdv avatar Jun 29 '22 07:06 avdv

Nice! Thank you for looking into this!

But providing such an expression is difficult because the wrapper (the buildEnv call) needs to be duplicated. Any reason why we do not always apply it?

Mainly, when we created this, we didn't know how much liberty users would need to override the details of the toolchain, e.g. see here. However, looking at the shape this is taking, and how things like binutils can be bundled with cc, it may well be fine to hard-code the buildEnv and only take the cc as a parameter.

Finally, I could use some help writing tests in this new repo layout.

Where are you encountering difficulties? The tests for the cc-toolchain have been moved here.

aherrmann avatar Jul 01 '22 13:07 aherrmann

@layus What's the status on this one? What do you need to push it over the finish line?

aherrmann avatar Nov 28 '22 12:11 aherrmann

@layus @avdv I think I resolved the merge conflict between this PR and Pass the unwrapped cc to wrapCCWith appropriately, but let me know if I made a mistake.

benradf avatar Aug 09 '23 09:08 benradf