Skip to content

Commit

Permalink
wrapRustcWith: fix linking with libgcc_s with llvm
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Jan 2, 2025
1 parent a67efac commit 20ff4c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkgs/build-support/rust/rustc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}"
defaultArgs = lib.optionalString (
with rustc-unwrapped.stdenv.targetPlatform; isMusl && !isStatic
) "-C target-feature=-crt-static";

ldflags =
lib.optionalString (rustc-unwrapped.stdenv.targetPlatform.useLLVM or false)
"-rpath ${rustc-unwrapped.llvmPackages.libunwind}/lib -L ${
runCommand "libunwind-libgcc" { } ''
mkdir -p $out/lib
ln -s ${rustc-unwrapped.llvmPackages.libunwind}/lib/libunwind.so $out/lib/libgcc_s.so
ln -s ${rustc-unwrapped.llvmPackages.libunwind}/lib/libunwind.so $out/lib/libgcc_s.so.1
''
}/lib";
};

passthru = {
Expand All @@ -59,9 +69,11 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}"
ln -s ${rustc-unwrapped}/bin/* $out/bin
rm $out/bin/{rustc,rustdoc}
prog=${rustc-unwrapped}/bin/rustc extraFlagsVar=NIX_RUSTFLAGS \
substituteAll ${./rustc-wrapper.sh} $out/bin/rustc
substituteAll ${./rustc-wrapper.sh} $out/bin/rustc \
--subst-var ldflags
prog=${rustc-unwrapped}/bin/rustdoc extraFlagsVar=NIX_RUSTDOCFLAGS \
substituteAll ${./rustc-wrapper.sh} $out/bin/rustdoc
substituteAll ${./rustc-wrapper.sh} $out/bin/rustdoc \
--subst-var ldflags
chmod +x $out/bin/{rustc,rustdoc}
${lib.concatMapStrings (output: "ln -s ${rustc-unwrapped.${output}} \$${output}\n") (
lib.remove "out" rustc-unwrapped.outputs
Expand Down
1 change: 1 addition & 0 deletions pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ if (( "${NIX_DEBUG:-0}" >= 1 )); then
printf " %q\n" "${extraAfter[@]}" >&2
fi

export NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS"
exec @prog@ "${extraBefore[@]}" "$@" "${extraAfter[@]}"

0 comments on commit 20ff4c0

Please sign in to comment.