<commit_before>{ stdenv, fetchurl, pkgconfig, glib, freetype, cairo, libintl
, icu, graphite2, harfbuzz # The icu variant uses and propagates the non-icu one.
, ApplicationServices, CoreText
, withCoreText ? false
, withIcu ? false # recommended by upstream as default, but most don't needed and it's big
, withGraphite2 ? true # it is small and major distros do include it
, python
}:

let
  version = "2.3.1";
  inherit (stdenv.lib) optional optionals optionalString;
in

stdenv.mkDerivation {
  name = "harfbuzz${optionalString withIcu "-icu"}-${version}";

  src = fetchurl {
    url = "https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${version}.tar.bz2";
    sha256 = "0s74ramsbfa183rxkidqgfd2vbhrwicnrqzqsq440dwibffnj1gj";
  };

  postPatch = ''
    patchShebangs src/gen-def.py
    patchShebangs test
  '';

  outputs = [ "out" "dev" ];
  outputBin = "dev";

  configureFlags = [
    # not auto-detected by default
    "--with-graphite2=${if withGraphite2 then "yes" else "no"}"
    "--with-icu=${if withIcu then "yes" else "no"}"
  ]
    ++ stdenv.lib.optional withCoreText "--with-coretext=yes";

  nativeBuildInputs = [ pkgconfig libintl ];

  buildInputs = [ glib freetype cairo ] # recommended by upstream
    ++ stdenv.lib.optionals withCoreText [ ApplicationServices CoreText ];

  propagatedBuildInputs = []
    ++ optional withGraphite2 graphite2
    ++ optionals withIcu [ icu harfbuzz ];

  checkInputs = [ python ];
  doInstallCheck = false; # fails, probably a bug

  # Slightly hacky; some pkgs expect them in a single directory.
  postInstall = optionalString withIcu ''<commit_msg>harfbuzz-icu: disable error for cast-align<commit_after>{ stdenv, fetchurl, pkgconfig, glib, freetype, cairo, libintl
, icu, graphite2, harfbuzz # The icu variant uses and propagates the non-icu one.
, ApplicationServices, CoreText
, withCoreText ? false
, withIcu ? false # recommended by upstream as default, but most don't needed and it's big
, withGraphite2 ? true # it is small and major distros do include it
, python
}:

let
  version = "2.3.1";
  inherit (stdenv.lib) optional optionals optionalString;
in

stdenv.mkDerivation {
  name = "harfbuzz${optionalString withIcu "-icu"}-${version}";

  src = fetchurl {
    url = "https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-${version}.tar.bz2";
    sha256 = "0s74ramsbfa183rxkidqgfd2vbhrwicnrqzqsq440dwibffnj1gj";
  };

  postPatch = ''
    patchShebangs src/gen-def.py
    patchShebangs test
  '' + stdenv.lib.optionalString stdenv.isDarwin ''
    # ApplicationServices.framework headers have cast-align warnings.
    substituteInPlace src/hb.hh \
      --replace '#pragma GCC diagnostic error   "-Wcast-align"' ""
  '';

  outputs = [ "out" "dev" ];
  outputBin = "dev";

  configureFlags = [
    # not auto-detected by default
    "--with-graphite2=${if withGraphite2 then "yes" else "no"}"
    "--with-icu=${if withIcu then "yes" else "no"}"
  ]
    ++ stdenv.lib.optional withCoreText "--with-coretext=yes";

  nativeBuildInputs = [ pkgconfig libintl ];

  buildInputs = [ glib freetype cairo ] # recommended by upstream
    ++ stdenv.lib.optionals withCoreText [ ApplicationServices CoreText ];

  propagatedBuildInputs = []
    ++ optional withGraphite2 graphite2
    ++ optionals withIcu [ icu harfbuzz ];

  checkInputs = [ python ];
  doInstallCheck = false; # fails, probably a bug

  # Slightly hacky; some pkgs expect them in a single directory.
  postInstall = optionalString withIcu ''
{'fraction_non_alphanumeric': 0.1154727793696275, 'fraction_numerical': 0.013753581661891117, 'mean_word_length': 3.8962131837307155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5758108', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1162, 'n_words': 305}