-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
rustc: fix building with llvm #320432
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
rustc: fix building with llvm #320432
Conversation
e05dbb6
to
8f443be
Compare
I still get this on x86_64-linux:
|
@tomberek Yes, this seems to still occur on aarch64-linux as well. Not entirely sure why we are still facing this issue. Looking at the documentation comments in |
8f443be
to
b966a22
Compare
@ofborg build pkgsLLVM.rustc |
On x86_64-linux I'm getting:
|
@jopejoe1 Thank you for testing, I marked it as a draft and will continue figuring out why rustc still doesn't compile tonight. |
perhaps we should be compiling the pkgsLLVM clang so that it translates the alternatively, adding the flag -stdlib=libc++ should also work |
e73636c
to
1108be3
Compare
8394848
to
8b96d40
Compare
8b96d40
to
0c3cbd2
Compare
@@ -66,14 +67,14 @@ in stdenv.mkDerivation (finalAttrs: { | |||
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' | |||
# This doesn't apply to cross-building for FreeBSD because the host | |||
# uses libstdc++, but the target (used for building std) uses libc++ | |||
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) "--push-state --as-needed -lstdc++ --pop-state" | |||
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state" | |||
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) "--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state" |
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.
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) "--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state" | |
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) | |
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state" |
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.
Done
@@ -66,14 +67,14 @@ in stdenv.mkDerivation (finalAttrs: { | |||
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' | |||
# This doesn't apply to cross-building for FreeBSD because the host | |||
# uses libstdc++, but the target (used for building std) uses libc++ | |||
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) "--push-state --as-needed -lstdc++ --pop-state" | |||
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state" |
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.
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state" | |
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) | |
"--push-state --as-needed -lstdc++ --pop-state" |
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.
Done
0c3cbd2
to
f9d3bb5
Compare
f9d3bb5
to
36219b4
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/4278 |
For aarch64-darwin:
|
36219b4
to
2c03b10
Compare
@tomberek I've pushed a change which I believe might fix it, if it doesn't then I'll do some more diagnosing tonight. |
Builds on x86_64-linux. |
Bisect says 6a163e2
|
@trofi Will take a look at it tonight. Tbf, it probably wouldn't even have built anyway so it's not like we totally broke everything. |
My concern is the eval only (I usually scan for things in treewide evals). It used to eval successfully and does not anymore. |
Heh yeah, I'll take a look tonight after work to try fixing this. Unless someone else wants to touch this. |
The PR which fixed `useLLVM` native rustc builds (NixOS#320432) also broke cross builds. The C compiler it used for `llvmShared` and `llvmPackages`, `llvmPackages.clangUseLLVM`, was built to run on the host and create binaries for the target (`pkgsHostTarget`). Instead, the compiler should be built to run on the build machine and produce binaries for the build machine (`pkgsBuildHost`). Replace the overridden compilers with ones from `pkgsBuildHost` Co-Authored-By: Artemis Tosini <me@artem.ist>
The PR which fixed `useLLVM` native rustc builds (NixOS#320432) also broke cross builds. The C compiler it used to produce `llvmShared` and `llvmPackages`, `llvmPackages.clangUseLLVM`, was built to run on the host and create binaries for the target (`pkgsHostTarget`). Instead, the compiler should be built to run on the build machine and produce binaries for the host machine (`pkgsBuildHost`). Replace the overridden compilers with ones from `pkgsBuildHost` Co-Authored-By: Artemis Tosini <me@artem.ist>
The PR which fixed `useLLVM` native rustc builds (NixOS#320432) also broke cross builds. The C compiler it used to produce `llvmShared` and `llvmPackages`, `llvmPackages.clangUseLLVM`, was built to run on the host and create binaries for the target (`pkgsHostTarget`). Instead, the compiler should be built to run on the build machine and produce binaries for the host machine (`pkgsBuildHost`). Replace the overridden compilers with ones from `pkgsBuildHost` Co-Authored-By: Artemis Tosini <me@artem.ist>
@@ -24,6 +24,7 @@ | |||
let | |||
inherit (lib) optionals optional optionalString concatStringsSep; | |||
inherit (darwin.apple_sdk.frameworks) Security; | |||
useLLVM = stdenv.targetPlatform.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.
@RossComputerGuy why is this looking at the target platform? I'm possibly missing something but as far as I can see, useLLVM
is only used to control aspects during the build, not at runtime (these would be covered by #330037) so shouldn't it be hostPlatform
?
example of a build that fails (when ran on a non-LLVM localSystem):
nix-build --arg crossSystem '{ config = "x86_64-unknown-linux-gnu"; useLLVM = true; }' -A buildPackages.rustc.unwrapped
(note the buildPackages
)
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.
pkgsLLVM.buildPackages.stdenv.targetPlatform.useLLVM
evaluates to true while pkgsLLVM.buildPackages.stdenv.hostPlatform.useLLVM
evaluates to 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.
yes, that's what I'm saying. in the setup above, because pkgsLLVM.buildPackages.stdenv.targetPlatform.useLLVM
evaluates to true, the tweaks are enabled when it looks like they shouldn't (because you are building binaries for a gcc-based platform so you should be using libgcc rather than libunwind, even if the target is LLVM). is my reasoning correct?
@@ -248,7 +256,16 @@ in stdenv.mkDerivation (finalAttrs: { | |||
|
|||
buildInputs = [ openssl ] | |||
++ optionals stdenv.isDarwin [ libiconv Security ] | |||
++ optional (!withBundledLLVM) llvmShared; | |||
++ optional (!withBundledLLVM) llvmShared.lib | |||
++ optional (useLLVM && !withBundledLLVM) [ |
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, no. Should be optionals
here.
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.
It doesn't matter that much since it gets flattened
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.
It doesn't matter that much since it gets flattened
I don't think so. I applied the patch below, and the build failure was resolved.
--- a/pkgs/development/compilers/rust/rustc.nix
+++ b/pkgs/development/compilers/rust/rustc.nix
@@ -391,15 +391,9 @@ stdenv.mkDerivation (finalAttrs: {
zlib
]
++ optional (!withBundledLLVM) llvmShared.lib
- ++ optional (useLLVM && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) [
- llvmPackages.libunwind
- # Hack which is used upstream https://github.com/gentoo/gentoo/blob/master/dev-lang/rust/rust-1.78.0.ebuild#L284
- (runCommandLocal "libunwind-libgcc" { } ''
- mkdir -p $out/lib
- ln -s ${llvmPackages.libunwind}/lib/libunwind.so $out/lib/libgcc_s.so
- ln -s ${llvmPackages.libunwind}/lib/libunwind.so $out/lib/libgcc_s.so.1
- '')
- ];
+ ++ optional (
+ useLLVM && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD
+ ) llvmPackages.libunwind;
outputs = [
"out"
Description of changes
Fixes #311930
Can be tested / reproduced by building
pkgsLLVM.rustc
. Fix was tested under the Nixpkgs LLVM Workspace project.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.