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
Allow using LLVM for cross compilation toolchain #55750
Conversation
Regarding crtbegin/crtend bits: https://reviews.llvm.org/D28791 . We may want to start looking at using LLVM utilities for binutils, there's a build-time option and they act like the gnu binutils if symlink'd over I think. No idea how well they'd be suited to our needs but something to keep in mind. And of course optionally using LLD as default linker :). Looking at these changes presently! :) |
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.
Generally looks very good! I haven't been able to look at it more hands-on so as to help catch some more subtle problems, sorry. Offhand I remember something like if we don't specify --gcc-toolchain
and clang was built with gcc, it will try to find the path of the compiler that built it-- which can cause some painfully subtle problems re:staging if that's not what you expect. I'm not sure what the behavior is with recent clang, and haven't really dug into this for a while :). Will be looking into this again "soon" but not sure when that'll be so nevermind that :). Exciting!!
ln -sf $prog $out/bin/${prefix}$(basename $prog) | ||
done | ||
rm -f $out/bin/${prefix}cat | ||
ln -s ${lld}/bin/lld $out/bin/${prefix}ld |
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.
LOL I see my comment re:using llvm bits symlinked over ... is not news to you! 🗡️
FWIW this might be a great deal simpler and more predictable if instead of shell globs and loops it used linkFarm
or whichever over in trivial-builders.nix
. I think enumerating what we intend/expect to symlink is reasonable- the number shouldn't grow much higher than it is and this way nothing sneaks in as part of a bump :).
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 that probably would be better. Even just listing out all of the utilities here like we do in https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/darwin/binutils/default.nix would be helpful. This is actually originally from wasm-cross here:
https://github.com/WebGHC/wasm-cross/blob/master/llvm-head/default.nix#L58-L82
but I think that change would be a good idea.
@GrahamcOfBorg test.hello |
@GrahamcOfBorg test hello |
It looks like the built binaries aren't actually working! I get it to hang on the qemu-user emulator. @GrahamcOfBorg build tests.cross.hello.aarch64-multiplatform-musl |
Instead of |
@@ -92,7 +92,7 @@ stdenv.mkDerivation rec { | |||
outputs = [ "out" "dev" ]; | |||
|
|||
dontDisableStatic = true; | |||
separateDebugInfo = true; | |||
separateDebugInfo = !(stdenv.hostPlatform.useLLVM or false); |
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 should be set for everything - separate-debug-info relies on gcc binutils
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.
I believe you, but am a bit surprised by this. Is this because of the way we do things or do LLVM bits not support split debug info? Or is "split"/"separate" an important difference? O:)
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.
I looked into it and it looks like there are no build ids produced:
$CC test.c -o test
$READELF -n test
Probably configurable?
cc = tools.clang-unwrapped; | ||
bintools = wrapBintoolsWith { | ||
inherit (tools) bintools; | ||
libc = 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.
should set isLLVM or similar
c741414
to
364dfdc
Compare
@GrahamcOfBorg build tests.cross.file-llvm.aarch64-multiplatform-musl tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.musl64 tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.musl64 tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.mingwW64 tests.cross.file-llvm.musl-power |
4c6db19
to
35a0d37
Compare
@GrahamcOfBorg build tests.cross.file-llvm.aarch64-multiplatform-musl tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.musl64 tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.musl64 tests.cross.file-llvm.armv7l-unknown-linux-gnueabihf tests.cross.file-llvm.mingwW64 tests.cross.file-llvm.musl-power |
}); | ||
|
||
libraries = stdenv.lib.makeExtensible (libraries: let | ||
callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python isl release_version version fetch; }); | ||
in { | ||
|
||
compiler-rt = callPackage ./compiler-rt.nix {}; | ||
compiler-rt = callPackage ./compiler-rt.nix { | ||
stdenv = if stdenv.hostPlatform.useLLVM or false |
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.
Oh can do you do the stdenv.hostPlatform.cc = "llvm"
thing?
35a0d37
to
8c273d6
Compare
LLVM should be target independent because it will work with all machine types. This is different from GCC where it needs to know what target to build ahead of time.
(cherry picked from commit 08f5b419b9efc77db044f8c1d725632552617966)
You can build (partially) with LLVM toolchain using the useLLVM flag. This works like so: nix-build -A hello --arg crossSystem '{ system = "aarch64-unknown-linux-musl"; useLLVM = true }' also don’t separate debug info in lldClang It doesn’t work currently with that setup hook. Missing build-id?
8c273d6
to
8e25da0
Compare
@matthewbauer This is awesome! Is there an example of how to make a nixpkgs instance using this and musl for stdenv? |
This comment has been minimized.
This comment has been minimized.
@matthewbauer Sweet! And the musl will be buillt with Clang? |
The command provided doesn't seem to work,
and switching `config` to `localSystem` evaluates
but perhaps unsurprisingly we don't have the means to bootstrap an LLVM
stdenv just yet.
Using `crossSystem` seems to work, at least looking at the proposed
list of derivations it prints. Haven't finished building yet, so not
sure, but here's what might work:
```
$ nix-build -A hello --arg crossSystem '{ config = "x86_64-unknown-linux-musl"; useLLVM = true; }'
```
~Will
…On Wed, 27 Feb 2019 17:09:18 -0800, Will Fancher ***@***.***> wrote:
@matthewbauer Sweet! And the musl will be buillt with Clang?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#55750 (comment) part: text/html
|
This PR seems to have broken compiler-rt on x86_64 (which breaks stuff like chromium). https://hydra.nixos.org/eval/1507125
|
Sent a fix in #56502. |
Oops yeah meant crossSystem |
On Wed, 27 Feb 2019 19:49:16 -0800, Matthew Bauer ***@***.***> wrote:
Oops yeah meant crossSystem
Okay, figured you did! And can confirm it works!
Aw man, this is amazing to have working in nixpkgs proper
and especially as cleanly as all this ends up being!
Thanks for all your work on this front! :D
…
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#55750 (comment) part: text/html
|
Yeah it’s a lot cheaper than having to recompile the whooe gcc each time too. |
Motivation for this change
The idea is to allow you to build with LLVM by passing something like this in Nixpkgs:
Lots of this is based on the approach taking in wasm-cross repo:
https://github.com/WebGHC/wasm-cross
Unfortunately I haven't gotten libc to cross compile without using GCC.