nixpkgs/pkgs/development/compilers/llvm/common/bintools.nix
Sergei Trofimovich 88f8b20419 llvmPackages.bintools.bintools: expose targetPrefix attribute to match binutils
Before the change `llvmPackages.bintools.bintools.targetPrefix` was not
present. This exposed as a discrepansy between `binutils` and `llvm`:

`binutils`:

    nix-repl> stdenv.cc.bintools.bintools.targetPrefix
    ""
    nix-repl> stdenv.cc.bintools.targetPrefix
    ""

`llvm`:

    nix-repl> pkgsLLVM.stdenv.cc.bintools.targetPrefix
    "x86_64-unknown-linux-gnu-"

    nix-repl> pkgsLLVM.stdenv.cc.bintools.bintools.targetPrefix
    error:
       error: attribute 'targetPrefix' missing

As a result some attributes like `pkgsLLVM.actionlint` failed to
evaluate:

    $ nix build --no-link -f. pkgsLLVM.actionlint
    ...
          error: attribute 'targetPrefix' missing
       at pkgs/development/compilers/ghc/9.4.8.nix:232:46:

          231|     export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
          232|     export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip"
             |                                              ^

The change exposes binary prefix the same way as `binutils` does.
2024-01-07 14:47:22 +00:00

50 lines
1.8 KiB
Nix

{ lib, runCommand, stdenv, llvm, lld, version, release_version }:
let
targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
in
runCommand "llvm-binutils-${version}"
{
preferLocalBuild = true;
passthru = {
isLLVM = true;
inherit targetPrefix;
};
}
(''
mkdir -p $out/bin
for prog in ${lld}/bin/*; do
ln -s $prog $out/bin/${targetPrefix}$(basename $prog)
done
for prog in ${llvm}/bin/*; do
ln -sf $prog $out/bin/${targetPrefix}$(basename $prog)
done
llvmBin="${llvm}/bin"
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib
ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt
ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp
ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip
ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump
ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf
ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size
ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings
ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line
if [ -e "$llvmBin/llvm-debuginfod" ]; then
ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod
ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find
fi
ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld
# Only >=13 show GNU windres compatible in help
'' + lib.optionalString (lib.versionAtLeast release_version "13") ''
ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres
'')