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