2024-07-27 06:49:29 +00:00
|
|
|
|
{
|
|
|
|
|
lib,
|
|
|
|
|
stdenvNoCC,
|
|
|
|
|
cctools,
|
|
|
|
|
clang-unwrapped,
|
2024-07-31 10:19:44 +00:00
|
|
|
|
ld64,
|
2024-07-27 06:49:29 +00:00
|
|
|
|
llvm,
|
|
|
|
|
llvm-manpages,
|
|
|
|
|
makeWrapper,
|
|
|
|
|
enableManpages ? stdenvNoCC.targetPlatform == stdenvNoCC.hostPlatform,
|
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
let
|
2024-07-27 06:49:29 +00:00
|
|
|
|
inherit (stdenvNoCC) targetPlatform hostPlatform;
|
|
|
|
|
targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
|
|
|
|
|
|
|
|
|
|
llvm_cmds = [
|
|
|
|
|
"addr2line"
|
|
|
|
|
"ar"
|
|
|
|
|
"c++filt"
|
2024-07-31 10:19:44 +00:00
|
|
|
|
"dwarfdump"
|
2024-07-27 06:49:29 +00:00
|
|
|
|
"dsymutil"
|
|
|
|
|
"nm"
|
|
|
|
|
"objcopy"
|
|
|
|
|
"objdump"
|
|
|
|
|
"otool"
|
|
|
|
|
"size"
|
|
|
|
|
"strings"
|
|
|
|
|
"strip"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
cctools_cmds = [
|
2021-05-28 09:39:13 +00:00
|
|
|
|
"codesign_allocate"
|
2024-07-27 06:49:29 +00:00
|
|
|
|
"gprof"
|
|
|
|
|
"ranlib"
|
|
|
|
|
# Use the cctools versions because the LLVM ones can crash or fail when the cctools ones don’t.
|
|
|
|
|
# Revisit when LLVM is updated to LLVM 18 on Darwin.
|
|
|
|
|
"lipo"
|
|
|
|
|
"install_name_tool"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
];
|
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
|
linkManPages =
|
|
|
|
|
pkg: source: target:
|
|
|
|
|
lib.optionalString enableManpages ''
|
|
|
|
|
sourcePath=${pkg}/share/man/man1/${source}.1.gz
|
|
|
|
|
targetPath=''${!outputMan}/share/man/man1/${target}.1.gz
|
|
|
|
|
|
|
|
|
|
if [ -f "$sourcePath" ]; then
|
|
|
|
|
mkdir -p "$(dirname "$targetPath")"
|
|
|
|
|
ln -s "$sourcePath" "$targetPath"
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
in
|
|
|
|
|
stdenvNoCC.mkDerivation {
|
|
|
|
|
pname = "${targetPrefix}cctools-binutils-darwin";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
inherit (cctools) version;
|
2024-07-27 06:49:29 +00:00
|
|
|
|
|
|
|
|
|
outputs = [ "out" ] ++ lib.optional enableManpages "man";
|
|
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
buildCommand = ''
|
|
|
|
|
mkdir -p $out/bin $out/include
|
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
|
for tool in ${toString llvm_cmds}; do
|
|
|
|
|
# Translate between LLVM and traditional tool names (e.g., `c++filt` versus `cxxfilt`).
|
|
|
|
|
cctoolsTool=''${tool//-/_}
|
|
|
|
|
llvmTool=''${tool//++/xx}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
|
# Some tools aren’t prefixed (like `dsymutil`).
|
|
|
|
|
llvmPath="${lib.getBin llvm}/bin"
|
|
|
|
|
if [ -e "$llvmPath/llvm-$llvmTool" ]; then
|
|
|
|
|
llvmTool=llvm-$llvmTool
|
|
|
|
|
elif [ -e "$llvmPath/${targetPrefix}$llvmTool" ]; then
|
|
|
|
|
llvmTool=${targetPrefix}$llvmTool
|
|
|
|
|
fi
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
|
# Not all tools are included in the bootstrap tools. Don’t link them if they don’t exist.
|
|
|
|
|
if [ -e "$llvmPath/$llvmTool" ]; then
|
|
|
|
|
ln -s "$llvmPath/$llvmTool" "$out/bin/${targetPrefix}$cctoolsTool"
|
|
|
|
|
fi
|
|
|
|
|
${linkManPages llvm-manpages "$llvmTool" "$cctoolsTool"}
|
|
|
|
|
done
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
|
for tool in ${toString cctools_cmds}; do
|
|
|
|
|
toolsrc="${lib.getBin cctools}/bin/${targetPrefix}$tool"
|
|
|
|
|
if [ -e "$toolsrc" ]; then
|
|
|
|
|
ln -s "${lib.getBin cctools}/bin/${targetPrefix}$tool" "$out/bin/${targetPrefix}$tool"
|
|
|
|
|
fi
|
|
|
|
|
${linkManPages (lib.getMan cctools) "$tool" "$tool"}
|
2020-05-15 21:57:56 +00:00
|
|
|
|
done
|
2024-07-27 06:49:29 +00:00
|
|
|
|
${
|
2024-07-31 10:19:44 +00:00
|
|
|
|
# These are unprefixed because some tools expect to invoke them without it when cross-compiling to Darwin:
|
2024-07-27 06:49:29 +00:00
|
|
|
|
# - clang needs `dsymutil` when building with debug information;
|
|
|
|
|
# - meson needs `lipo` when cross-compiling to Darwin; and
|
|
|
|
|
# - meson also needs `install_name_tool` and `otool` when performing rpath cleanup on installation.
|
|
|
|
|
lib.optionalString (targetPrefix != "") ''
|
|
|
|
|
for bintool in dsymutil install_name_tool lipo otool; do
|
|
|
|
|
ln -s "$out/bin/${targetPrefix}$bintool" "$out/bin/$bintool"
|
|
|
|
|
done
|
|
|
|
|
''
|
|
|
|
|
}
|
|
|
|
|
# Use the clang-integrated assembler. `as` in cctools is deprecated upstream and no longer built in nixpkgs.
|
|
|
|
|
makeWrapper "${lib.getBin clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \
|
|
|
|
|
--add-flags "-x assembler -integrated-as -c"
|
|
|
|
|
|
2024-07-31 10:19:44 +00:00
|
|
|
|
ln -s '${lib.getBin ld64}/bin/${targetPrefix}ld' "$out/bin/${targetPrefix}ld"
|
|
|
|
|
${linkManPages (lib.getMan ld64) "ld" "ld"}
|
|
|
|
|
${linkManPages (lib.getMan ld64) "ld-classic" "ld-classic"}
|
|
|
|
|
${linkManPages (lib.getMan ld64) "ld64" "ld64"}
|
2024-07-27 06:49:29 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
__structuredAttrs = true;
|
2021-03-19 17:17:44 +00:00
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
passthru = {
|
2024-07-27 06:49:29 +00:00
|
|
|
|
inherit cctools_cmds llvm_cmds targetPrefix;
|
|
|
|
|
isCCTools = true; # The fact ld64 is used instead of lld is why this isn’t `isLLVM`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
meta = {
|
2024-07-27 06:49:29 +00:00
|
|
|
|
maintainers = with lib.maintainers; [ reckenrode ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
priority = 10;
|
|
|
|
|
};
|
|
|
|
|
}
|