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