1{ lib
2, stdenv
3, fetchurl
4, pkg-config
5, glib
6, freetype
7, fontconfig
8, libintl
9, meson
10, ninja
11, gobject-introspection
12, icu
13, graphite2
14, harfbuzz # The icu variant uses and propagates the non-icu one.
15, ApplicationServices
16, CoreText
17, withCoreText ? false
18, withIcu ? false # recommended by upstream as default, but most don't needed and it's big
19, withGraphite2 ? true # it is small and major distros do include it
20, python3
21, gtk-doc
22, docbook-xsl-nons
23, docbook_xml_dtd_43
24# for passthru.tests
25, gimp
26, gtk3
27, gtk4
28, mapnik
29, qt5
30}:
31
32let
33 version = "5.2.0";
34 inherit (lib) optional optionals optionalString;
35 mesonFeatureFlag = feature: flag:
36 "-D${feature}=${if flag then "enabled" else "disabled"}";
37in
38
39stdenv.mkDerivation {
40 pname = "harfbuzz${optionalString withIcu "-icu"}";
41 inherit version;
42
43 src = fetchurl {
44 url = "https://github.com/harfbuzz/harfbuzz/releases/download/${version}/harfbuzz-${version}.tar.xz";
45 sha256 = "0b4lpkidwx0lf8slczjji652yll6g5zgmm5lmisnb4s7gf8r8nkk";
46 };
47
48 postPatch = ''
49 patchShebangs src/*.py test
50 '' + lib.optionalString stdenv.isDarwin ''
51 # ApplicationServices.framework headers have cast-align warnings.
52 substituteInPlace src/hb.hh \
53 --replace '#pragma GCC diagnostic error "-Wcast-align"' ""
54 '';
55
56 outputs = [ "out" "dev" "devdoc" ];
57 outputBin = "dev";
58
59 mesonFlags = [
60 # upstream recommends cairo, but it is only used for development purposes
61 # and is not part of the library.
62 # Cairo causes transitive (build) dependencies on various X11 or other
63 # GUI-related libraries, so it shouldn't be re-added lightly.
64 (mesonFeatureFlag "cairo" false)
65 # chafa is only used in a development utility, not in the library
66 (mesonFeatureFlag "chafa" false)
67 (mesonFeatureFlag "coretext" withCoreText)
68 (mesonFeatureFlag "graphite" withGraphite2)
69 (mesonFeatureFlag "icu" withIcu)
70 ];
71
72 depsBuildBuild = [
73 pkg-config
74 ];
75
76 nativeBuildInputs = [
77 meson
78 ninja
79 gobject-introspection
80 libintl
81 pkg-config
82 python3
83 gtk-doc
84 docbook-xsl-nons
85 docbook_xml_dtd_43
86 ];
87
88 buildInputs = [ glib freetype gobject-introspection ]
89 ++ lib.optionals withCoreText [ ApplicationServices CoreText ];
90
91 propagatedBuildInputs = optional withGraphite2 graphite2
92 ++ optionals withIcu [ icu harfbuzz ];
93
94 doCheck = true;
95
96 # Slightly hacky; some pkgs expect them in a single directory.
97 postFixup = optionalString withIcu ''
98 rm "$out"/lib/libharfbuzz.* "$dev/lib/pkgconfig/harfbuzz.pc"
99 ln -s {'${harfbuzz.out}',"$out"}/lib/libharfbuzz.la
100 ln -s {'${harfbuzz.dev}',"$dev"}/lib/pkgconfig/harfbuzz.pc
101 ${optionalString stdenv.isDarwin ''
102 ln -s {'${harfbuzz.out}',"$out"}/lib/libharfbuzz.dylib
103 ln -s {'${harfbuzz.out}',"$out"}/lib/libharfbuzz.0.dylib
104 ''}
105 '';
106
107 passthru.tests = {
108 inherit gimp gtk3 gtk4 mapnik;
109 inherit (qt5) qtbase;
110 };
111
112 meta = with lib; {
113 description = "An OpenType text shaping engine";
114 homepage = "https://harfbuzz.github.io/";
115 maintainers = [ maintainers.eelco ];
116 license = licenses.mit;
117 platforms = with platforms; linux ++ darwin;
118 };
119}