<commit_before>{ stdenv, binutils-raw, cctools
, hostPlatform, targetPlatform
}:

# Make sure both underlying packages claim to have prepended their binaries
# with the same prefix.
assert binutils-raw.prefix == cctools.prefix;

let
  inherit (binutils-raw) prefix;
  cmds = [
    "ar" "ranlib" "as" "dsymutil" "install_name_tool"
    "ld" "strip" "otool" "lipo" "nm" "strings" "size"
  ];
in

# TODO loop over prefixed binaries too
stdenv.mkDerivation {
  name = "${prefix}cctools-binutils-darwin";
  buildCommand = ''
    mkdir -p $out/bin $out/include

    ln -s ${binutils-raw.out}/bin/${prefix}c++filt $out/bin/${prefix}c++filt

    # We specifically need:
    # - ld: binutils doesn't provide it on darwin
    # - as: as above
    # - ar: the binutils one prodices .a files that the cctools ld doesn't like
    # - ranlib: for compatibility with ar
    # - dsymutil: soon going away once it goes into LLVM (this one is fake anyway)
    # - otool: we use it for some of our name mangling
    # - install_name_tool: we use it to rewrite stuff in our bootstrap tools
    # - strip: the binutils one seems to break mach-o files
    # - lipo: gcc build assumes it exists
    # - nm: the gnu one doesn't understand many new load commands
    for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: prefix + e) cmds)}; do
      ln -sf "${cctools}/bin/$i" "$out/bin/$i"
    done

    for i in ${binutils-raw.dev or binutils-raw.out}/include/*.h; do
      ln -s "$i" "$out/include/$(basename $i)"
    done

    for i in ${cctools}/include/*; do
      ln -s "$i" "$out/include/$(basename $i)"
    done

    # FIXME: this will give us incorrect man pages for bits of cctools
    ln -s ${binutils-raw.out}/share $out/share
    ln -s ${binutils-raw.out}/lib $out/lib

    ln -s ${cctools}/libexec $out/libexec
  '';

  passthru = {
    inherit prefix;
  };
}<commit_msg>darwin binutils: Unwrap GNU Binutils before splicing with cctools<commit_after>{ stdenv, binutils-raw, cctools
, hostPlatform, targetPlatform
}:

# despite the name, binutils-raw is in fact wrapped.
let binutils-unwrapped = binutils-raw.binutils; in

# Make sure both underlying packages claim to have prepended their binaries
# with the same prefix.
assert binutils-unwrapped.prefix == cctools.prefix;

let
  inherit (binutils-unwrapped) prefix;
  cmds = [
    "ar" "ranlib" "as" "dsymutil" "install_name_tool"
    "ld" "strip" "otool" "lipo" "nm" "strings" "size"
  ];
in

# TODO loop over prefixed binaries too
stdenv.mkDerivation {
  name = "${prefix}cctools-binutils-darwin";
  buildCommand = ''
    mkdir -p $out/bin $out/include

    ln -s ${binutils-unwrapped.out}/bin/${prefix}c++filt $out/bin/${prefix}c++filt

    # We specifically need:
    # - ld: binutils doesn't provide it on darwin
    # - as: as above
    # - ar: the binutils one prodices .a files that the cctools ld doesn't like
    # - ranlib: for compatibility with ar
    # - dsymutil: soon going away once it goes into LLVM (this one is fake anyway)
    # - otool: we use it for some of our name mangling
    # - install_name_tool: we use it to rewrite stuff in our bootstrap tools
    # - strip: the binutils one seems to break mach-o files
    # - lipo: gcc build assumes it exists
    # - nm: the gnu one doesn't understand many new load commands
    for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: prefix + e) cmds)}; do
      ln -sf "${cctools}/bin/$i" "$out/bin/$i"
    done

    for i in ${binutils-unwrapped.dev or binutils-unwrapped.out}/include/*.h; do
      ln -s "$i" "$out/include/$(basename $i)"
    done

    for i in ${cctools}/include/*; do
      ln -s "$i" "$out/include/$(basename $i)"
    done

    # FIXME: this will give us incorrect man pages for bits of cctools
    ln -s ${binutils-unwrapped.out}/share $out/share
    ln -s ${binutils-unwrapped.out}/lib $out/lib

    ln -s ${cctools}/libexec $out/libexec
  '';

  passthru = {
    inherit prefix;
  };
}
{'fraction_non_alphanumeric': 0.12604828462515882, 'fraction_numerical': 0.0, 'mean_word_length': 3.0286591606960083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6261624', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1336, 'n_words': 454}