10 enableManpages ? stdenvNoCC.targetPlatform == stdenvNoCC.hostPlatform,
14 inherit (stdenvNoCC) targetPlatform hostPlatform;
15 targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
36 # Use the cctools versions because the LLVM ones can crash or fail when the cctools ones don’t.
37 # Revisit when LLVM is updated to LLVM 18 on Darwin.
44 lib.optionalString enableManpages ''
45 sourcePath=${pkg}/share/man/man1/${source}.1.gz
46 targetPath=''${!outputMan}/share/man/man1/${target}.1.gz
48 if [ -f "$sourcePath" ]; then
49 mkdir -p "$(dirname "$targetPath")"
50 ln -s "$sourcePath" "$targetPath"
54 stdenvNoCC.mkDerivation {
55 pname = "${targetPrefix}cctools-binutils-darwin";
56 inherit (cctools) version;
58 outputs = [ "out" ] ++ lib.optional enableManpages "man";
62 nativeBuildInputs = [ makeWrapper ];
65 mkdir -p $out/bin $out/include
67 for tool in ${toString llvm_cmds}; do
68 # Translate between LLVM and traditional tool names (e.g., `c++filt` versus `cxxfilt`).
69 cctoolsTool=''${tool//-/_}
70 llvmTool=''${tool//++/xx}
72 # Some tools aren’t prefixed (like `dsymutil`).
73 llvmPath="${lib.getBin llvm}/bin"
74 if [ -e "$llvmPath/llvm-$llvmTool" ]; then
75 llvmTool=llvm-$llvmTool
76 elif [ -e "$llvmPath/${targetPrefix}$llvmTool" ]; then
77 llvmTool=${targetPrefix}$llvmTool
80 # Not all tools are included in the bootstrap tools. Don’t link them if they don’t exist.
81 if [ -e "$llvmPath/$llvmTool" ]; then
82 ln -s "$llvmPath/$llvmTool" "$out/bin/${targetPrefix}$cctoolsTool"
84 ${linkManPages llvm-manpages "$llvmTool" "$cctoolsTool"}
87 for tool in ${toString cctools_cmds}; do
88 toolsrc="${lib.getBin cctools}/bin/${targetPrefix}$tool"
89 if [ -e "$toolsrc" ]; then
90 ln -s "${lib.getBin cctools}/bin/${targetPrefix}$tool" "$out/bin/${targetPrefix}$tool"
92 ${linkManPages (lib.getMan cctools) "$tool" "$tool"}
95 # These are unprefixed because some tools expect to invoke them without it when cross-compiling to Darwin:
96 # - clang needs `dsymutil` when building with debug information;
97 # - meson needs `lipo` when cross-compiling to Darwin; and
98 # - meson also needs `install_name_tool` and `otool` when performing rpath cleanup on installation.
99 lib.optionalString (targetPrefix != "") ''
100 for bintool in dsymutil install_name_tool lipo otool; do
101 ln -s "$out/bin/${targetPrefix}$bintool" "$out/bin/$bintool"
105 # Use the clang-integrated assembler. `as` in cctools is deprecated upstream and no longer built in nixpkgs.
106 makeWrapper "${lib.getBin clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \
107 --add-flags "-x assembler -integrated-as -c"
109 ln -s '${lib.getBin ld64}/bin/${targetPrefix}ld' "$out/bin/${targetPrefix}ld"
110 ${linkManPages (lib.getMan ld64) "ld" "ld"}
111 ${linkManPages (lib.getMan ld64) "ld-classic" "ld-classic"}
112 ${linkManPages (lib.getMan ld64) "ld64" "ld64"}
115 __structuredAttrs = true;
118 inherit cctools_cmds llvm_cmds targetPrefix;
119 isCCTools = true; # The fact ld64 is used instead of lld is why this isn’t `isLLVM`.
123 maintainers = with lib.maintainers; [ reckenrode ];