From fd4d2313d08663ce787f306e87bb80e9d4df60af Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 4 Apr 2024 12:22:35 -0700 Subject: [PATCH] build: do not build/link harfbuzz on macOS --- build.zig | 19 +++++++++++++------ src/font/face/coretext.zig | 2 +- src/font/main.zig | 13 +++++++++++++ src/main_ghostty.zig | 4 +++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index 28b5c11ef..feeb808ad 100644 --- a/build.zig +++ b/build.zig @@ -1055,11 +1055,14 @@ fn addDeps( "fontconfig", fontconfig_dep.module("fontconfig"), ); + if (config.font_backend.hasHarfbuzz()) step.root_module.addImport( + "harfbuzz", + harfbuzz_dep.module("harfbuzz"), + ); step.root_module.addImport("oniguruma", oniguruma_dep.module("oniguruma")); step.root_module.addImport("freetype", freetype_dep.module("freetype")); step.root_module.addImport("glslang", glslang_dep.module("glslang")); step.root_module.addImport("spirv_cross", spirv_cross_dep.module("spirv_cross")); - step.root_module.addImport("harfbuzz", harfbuzz_dep.module("harfbuzz")); step.root_module.addImport("xev", libxev_dep.module("xev")); step.root_module.addImport("opengl", opengl_dep.module("opengl")); step.root_module.addImport("pixman", pixman_dep.module("pixman")); @@ -1110,7 +1113,6 @@ fn addDeps( step.addIncludePath(freetype_dep.path("")); step.linkSystemLibrary2("bzip2", dynamic_link_opts); step.linkSystemLibrary2("freetype2", dynamic_link_opts); - step.linkSystemLibrary2("harfbuzz", dynamic_link_opts); step.linkSystemLibrary2("libpng", dynamic_link_opts); step.linkSystemLibrary2("oniguruma", dynamic_link_opts); step.linkSystemLibrary2("pixman-1", dynamic_link_opts); @@ -1119,6 +1121,9 @@ fn addDeps( if (config.font_backend.hasFontconfig()) { step.linkSystemLibrary2("fontconfig", dynamic_link_opts); } + if (config.font_backend.hasHarfbuzz()) { + step.linkSystemLibrary2("harfbuzz", dynamic_link_opts); + } } // Other dependencies, we may dynamically link @@ -1136,14 +1141,16 @@ fn addDeps( step.linkLibrary(freetype_dep.artifact("freetype")); try static_libs.append(freetype_dep.artifact("freetype").getEmittedBin()); - // Harfbuzz - step.linkLibrary(harfbuzz_dep.artifact("harfbuzz")); - try static_libs.append(harfbuzz_dep.artifact("harfbuzz").getEmittedBin()); - // Pixman step.linkLibrary(pixman_dep.artifact("pixman")); try static_libs.append(pixman_dep.artifact("pixman").getEmittedBin()); + // Harfbuzz + if (config.font_backend.hasHarfbuzz()) { + step.linkLibrary(harfbuzz_dep.artifact("harfbuzz")); + try static_libs.append(harfbuzz_dep.artifact("harfbuzz").getEmittedBin()); + } + // Only Linux gets fontconfig if (config.font_backend.hasFontconfig()) { // Fontconfig diff --git a/src/font/face/coretext.zig b/src/font/face/coretext.zig index 4e82432d5..e3177e888 100644 --- a/src/font/face/coretext.zig +++ b/src/font/face/coretext.zig @@ -28,7 +28,7 @@ pub const Face = struct { /// True if our build is using Harfbuzz. If we're not, we can avoid /// some Harfbuzz-specific code paths. - const harfbuzz_shaper = font.Shaper == font.shape.harfbuzz.Shaper; + const harfbuzz_shaper = font.options.backend.hasHarfbuzz(); /// The matrix applied to a regular font to auto-italicize it. pub const italic_skew = macos.graphics.AffineTransform{ diff --git a/src/font/main.zig b/src/font/main.zig index 3a03000bf..383f2da74 100644 --- a/src/font/main.zig +++ b/src/font/main.zig @@ -115,6 +115,19 @@ pub const Backend = enum { => false, }; } + + pub fn hasHarfbuzz(self: Backend) bool { + return switch (self) { + .freetype, + .fontconfig_freetype, + .coretext_freetype, + => true, + + .coretext, + .web_canvas, + => false, + }; + } }; /// The styles that a family can take. diff --git a/src/main_ghostty.zig b/src/main_ghostty.zig index 17c521d1e..ff38b800d 100644 --- a/src/main_ghostty.zig +++ b/src/main_ghostty.zig @@ -256,7 +256,9 @@ pub const GlobalState = struct { std.log.info("ghostty build optimize={s}", .{build_config.mode_string}); std.log.info("runtime={}", .{build_config.app_runtime}); std.log.info("font_backend={}", .{build_config.font_backend}); - std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()}); + if (comptime build_config.font_backend.hasHarfbuzz()) { + std.log.info("dependency harfbuzz={s}", .{harfbuzz.versionString()}); + } if (comptime build_config.font_backend.hasFontconfig()) { std.log.info("dependency fontconfig={d}", .{fontconfig.version()}); }