Skip to content

Commit

Permalink
rustc: fix building with llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Jun 23, 2024
1 parent 483a8dc commit d943d92
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d943d92

Please sign in to comment.