<commit_before>{ lib, hostPlatform, targetPlatform
, makeWrapper
, runCommand, wrapBintoolsWith, wrapCCWith
, buildAndroidndk, androidndk, targetAndroidndkPkgs
}:

let
  # Mapping from a platform to information needed to unpack NDK stuff for that
  # platform.
  #
  # N.B. The Android NDK uses slightly different LLVM-style platform triples
  # than we do. We don't just use theirs because ours are less ambiguous and
  # some builds need that clarity.
  ndkInfoFun = { config, ... }: {
    "x86_64-unknown-linux-gnu" = {
      double = "linux-x86_64";
    };
    "armv5tel-unknown-linux-androideabi" = {
      arch = "arm";
      triple = "arm-linux-androideabi";
      gccVer = "4.8";
    };
    "armv7a-unknown-linux-androideabi" = {
      arch = "arm";
      triple = "arm-linux-androideabi";
      gccVer = "4.9";
    };
    "aarch64-unknown-linux-android" = {
      arch = "arm64";
      triple = "aarch64-linux-android";
      gccVer = "4.9";
    };
  }.${config} or
    (throw "Android NDK doesn't support ${config}, as far as we know");

  hostInfo = ndkInfoFun hostPlatform;
  targetInfo = ndkInfoFun targetPlatform;

in

rec {
  # Misc tools
  binaries = let
      ndkBinDir =
        "${androidndk}/libexec/${androidndk.name}/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin";
    in runCommand "ndk-gcc-binutils" {
      isGNU = true; # for cc-wrapper
      nativeBuildInputs = [ makeWrapper ];
      propgatedBuildInputs = [ androidndk ];
    } ''
      mkdir -p $out/bin
      for prog in ${ndkBinDir}/${targetInfo.triple}-*; do
        prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//')
        ln -s $prog $out/bin/${targetPlatform.config}-$prog_suffix
      done
    '';

  binutils = wrapBintoolsWith {
    bintools = binaries;
    libc = targetAndroidndkPkgs.libraries;
  };

  gcc = wrapCCWith {<commit_msg>android: add --build-id to ldflags<commit_after>{ lib, hostPlatform, targetPlatform
, makeWrapper
, runCommand, wrapBintoolsWith, wrapCCWith
, buildAndroidndk, androidndk, targetAndroidndkPkgs
}:

let
  # Mapping from a platform to information needed to unpack NDK stuff for that
  # platform.
  #
  # N.B. The Android NDK uses slightly different LLVM-style platform triples
  # than we do. We don't just use theirs because ours are less ambiguous and
  # some builds need that clarity.
  ndkInfoFun = { config, ... }: {
    "x86_64-unknown-linux-gnu" = {
      double = "linux-x86_64";
    };
    "armv5tel-unknown-linux-androideabi" = {
      arch = "arm";
      triple = "arm-linux-androideabi";
      gccVer = "4.8";
    };
    "armv7a-unknown-linux-androideabi" = {
      arch = "arm";
      triple = "arm-linux-androideabi";
      gccVer = "4.9";
    };
    "aarch64-unknown-linux-android" = {
      arch = "arm64";
      triple = "aarch64-linux-android";
      gccVer = "4.9";
    };
  }.${config} or
    (throw "Android NDK doesn't support ${config}, as far as we know");

  hostInfo = ndkInfoFun hostPlatform;
  targetInfo = ndkInfoFun targetPlatform;

in

rec {
  # Misc tools
  binaries = let
      ndkBinDir =
        "${androidndk}/libexec/${androidndk.name}/toolchains/${targetInfo.triple}-${targetInfo.gccVer}/prebuilt/${hostInfo.double}/bin";
    in runCommand "ndk-gcc-binutils" {
      isGNU = true; # for cc-wrapper
      nativeBuildInputs = [ makeWrapper ];
      propgatedBuildInputs = [ androidndk ];
    } ''
      mkdir -p $out/bin
      for prog in ${ndkBinDir}/${targetInfo.triple}-*; do
        prog_suffix=$(basename $prog | sed 's/${targetInfo.triple}-//')
        ln -s $prog $out/bin/${targetPlatform.config}-$prog_suffix
      done
    '';

  binutils = wrapBintoolsWith {
    bintools = binaries;
    libc = targetAndroidndkPkgs.libraries;
    extraBuildCommands = ''
      echo "--build-id" >> $out/nix-support/libc-ldflags
    '';
  };

  gcc = wrapCCWith {
{'fraction_non_alphanumeric': 0.13540051679586562, 'fraction_numerical': 0.011369509043927648, 'mean_word_length': 2.8288822947576655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6610039', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1313, 'n_words': 296}