From d943d925f6affd460049135a529434aa27d48eb8 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 16 Jun 2024 20:42:33 -0700 Subject: [PATCH] rustc: fix building with llvm --- pkgs/development/compilers/rust/rustc.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index e00ba329ccdc4eb..f94124c0b2a1468 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -1,6 +1,6 @@ { lib, stdenv, removeReferencesTo, pkgsBuildBuild, pkgsBuildHost, pkgsBuildTarget, targetPackages , llvmShared, llvmSharedForBuild, llvmSharedForHost, llvmSharedForTarget, llvmPackages -, fetchurl, file, python3 +, runCommandLocal, fetchurl, file, python3 , darwin, cargo, cmake, rustc, rustfmt , pkg-config, openssl, xz , libiconv @@ -58,7 +58,7 @@ in stdenv.mkDerivation (finalAttrs: { NIX_LDFLAGS = toString ( # when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' - optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state" + optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ --pop-state" ++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++ -lc++abi" ++ optional stdenv.isDarwin "-rpath ${llvmSharedForHost}/lib"); @@ -158,6 +158,9 @@ in stdenv.mkDerivation (finalAttrs: { ] ++ optionals (stdenv.isDarwin && stdenv.isx86_64) [ # https://github.com/rust-lang/rust/issues/92173 "--set rust.jemalloc" + ] ++ optionals (stdenv.targetPlatform.useLLVM or false) [ + # https://github.com/NixOS/nixpkgs/issues/311930 + "--llvm-libunwind=${if withBundledLLVM then "in-tree" else "system"}" ]; # if we already have a rust compiler for build just compile the target std @@ -182,7 +185,7 @@ in stdenv.mkDerivation (finalAttrs: { python ./x.py --keep-stage=0 --stage=1 install library/std mkdir -v $out/bin $doc $man ln -s ${rustc.unwrapped}/bin/{rustc,rustdoc} $out/bin - ln -s ${rustc.unwrapped}/lib/rustlib/{manifest-rust-std-,}${stdenv.hostPlatform.rust.rustcTargetSpec} $out/lib/rustlib/ + ln -sf ${rustc.unwrapped}/lib/rustlib/{manifest-rust-std-,}${stdenv.hostPlatform.rust.rustcTargetSpec} $out/lib/rustlib/ echo rust-std-${stdenv.hostPlatform.rust.rustcTargetSpec} >> $out/lib/rustlib/components lndir ${rustc.doc} $doc lndir ${rustc.man} $man @@ -236,7 +239,17 @@ in stdenv.mkDerivation (finalAttrs: { buildInputs = [ openssl ] ++ optionals stdenv.isDarwin [ libiconv Security ] - ++ optional (!withBundledLLVM) llvmShared; + ++ optional (!withBundledLLVM) llvmShared + ++ optional (stdenv.targetPlatform.useLLVM or false && !withBundledLLVM) [ + llvmPackages.libunwind + llvmPackages.libcxx + # 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 + '') + ]; outputs = [ "out" "man" "doc" ]; setOutputFlags = false;