aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/fontconfig/build.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/pkg/fontconfig/build.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/pkg/fontconfig/build.zig')
-rw-r--r--vendor/libghostty-vt/pkg/fontconfig/build.zig116
1 files changed, 96 insertions, 20 deletions
diff --git a/vendor/libghostty-vt/pkg/fontconfig/build.zig b/vendor/libghostty-vt/pkg/fontconfig/build.zig
index 7c87d1f2..a1f43eac 100644
--- a/vendor/libghostty-vt/pkg/fontconfig/build.zig
+++ b/vendor/libghostty-vt/pkg/fontconfig/build.zig
@@ -1,6 +1,49 @@
const std = @import("std");
+const build_zon = @import("build.zig.zon");
const NativeTargetInfo = std.zig.system.NativeTargetInfo;
+// NOTE: This build is becoming more and more complex; we need to continually
+// extract the correct options from fontconfig build process (although this
+// part has been reasonably manageable for now); more concerning is the fact
+// that we also need to now extract more generated files as fontconfig is
+// leaning on generation more during their own Autoconf/Meson toolchain.
+// Additionally, the Autoconf process (which incidentally is what Nix uses as
+// well) has been deprecated since 2.18.3 (based on tracking the contents of
+// the INSTALL file), which means we will need to lean on Meson more and more
+// for this data.
+//
+// For now, autoconf still seems to work and can get us the files we need.
+//
+// If this build fails for any reason during update, you will need to inspect
+// the build logs and extract any possible missing headers. These can be
+// fetched through the following:
+//
+// * Set yourself up a Nix flake or build environment otherwise with the
+// following deps (note: these were extracted from the Nix package itself):
+//
+// autoconf
+// automake
+// expat
+// freetype
+// gettext
+// gperf
+// libtool
+// libxslt
+// pkg-config
+// python3
+//
+// * Fetch the fontconfig source and extract it in this environment.
+//
+// * In the source root, run "./autogen.sh" followed by "make". (Don't run
+// "make install").
+//
+// * You should now have a reasonable set of files that you can use to hunt for
+// any missing auto-generated headers and plumb through errors otherwise.
+//
+// * Make sure when you copy includes and what not into the "override" tree,
+// that you preserve directory structure. This will help us keep track of what
+// we need and where it specifically came from.
+
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -41,7 +84,7 @@ pub fn build(b: *std.Build) !void {
if (b.systemIntegrationOption("fontconfig", .{})) {
module.linkSystemLibrary("fontconfig", dynamic_link_opts);
- test_exe.linkSystemLibrary2("fontconfig", dynamic_link_opts);
+ test_exe.root_module.linkSystemLibrary("fontconfig", dynamic_link_opts);
} else {
const lib = try buildLib(b, module, .{
.target = target,
@@ -54,7 +97,7 @@ pub fn build(b: *std.Build) !void {
.dynamic_link_opts = dynamic_link_opts,
});
- test_exe.linkLibrary(lib);
+ test_exe.root_module.linkLibrary(lib);
}
}
@@ -71,19 +114,43 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
+ .link_libc = true,
}),
.linkage = .static,
});
- lib.linkLibC();
+
+ const dynamic_link_opts = options.dynamic_link_opts;
+
if (target.result.os.tag != .windows) {
- lib.linkSystemLibrary("pthread");
+ lib.root_module.linkSystemLibrary("pthread", dynamic_link_opts);
}
- lib.addIncludePath(b.path("override/include"));
- module.addIncludePath(b.path("override/include"));
+ // NOTE: The following directories are present in override but don't need
+ // to be added here:
+ //
+ // override/fc-case
+ //
+ inline for (.{
+ "override",
+ "override/fc-const",
+ "override/fc-genericfamily",
+ "override/fc-lang",
+ "override/src",
+ }) |override_dir| {
+ lib.root_module.addIncludePath(b.path(override_dir));
+ module.addIncludePath(b.path(override_dir));
+ }
var flags: std.ArrayList([]const u8) = .empty;
defer flags.deinit(b.allocator);
+
+ const version = try std.SemanticVersion.parse(build_zon.version);
+ try flags.appendSlice(b.allocator, &.{
+ b.fmt("-DFC_VERSION_MAJOR={d}", .{version.major}),
+ b.fmt("-DFC_VERSION_MINOR={d}", .{version.minor}),
+ b.fmt("-DFC_VERSION_MICRO={d}", .{version.patch}),
+ });
+
try flags.appendSlice(b.allocator, &.{
"-DHAVE_DIRENT_H",
"-DHAVE_FCNTL_H",
@@ -98,6 +165,7 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
"-DHAVE_RAND",
//"-DHAVE_RANDOM_R",
"-DHAVE_VPRINTF",
+ "-DHAVE_VSNPRINTF",
"-DHAVE_FT_GET_BDF_PROPERTY",
"-DHAVE_FT_GET_PS_FONT_INFO",
@@ -165,6 +233,7 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
"-DHAVE_RANDOM",
"-DHAVE_RAND_R",
"-DHAVE_READLINK",
+ "-DHAVE_USELOCALE",
"-DHAVE_SYS_MOUNT_H",
"-DHAVE_SYS_STATVFS_H",
@@ -194,19 +263,19 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
}
}
- const dynamic_link_opts = options.dynamic_link_opts;
-
// Freetype2
_ = b.systemIntegrationOption("freetype", .{}); // So it shows up in help
if (freetype_enabled) {
+ // Value-tested (#if/#elif) by upstream so it must be =1.
+ try flags.append(b.allocator, "-DENABLE_FREETYPE=1");
if (b.systemIntegrationOption("freetype", .{})) {
- lib.linkSystemLibrary2("freetype2", dynamic_link_opts);
+ lib.root_module.linkSystemLibrary("freetype2", dynamic_link_opts);
} else {
if (b.lazyDependency(
"freetype",
.{ .target = target, .optimize = optimize },
)) |freetype_dep| {
- lib.linkLibrary(freetype_dep.artifact("freetype"));
+ lib.root_module.linkLibrary(freetype_dep.artifact("freetype"));
}
}
}
@@ -227,22 +296,22 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
}
if (b.systemIntegrationOption("libxml2", .{})) {
- lib.linkSystemLibrary2("libxml-2.0", dynamic_link_opts);
+ lib.root_module.linkSystemLibrary("libxml-2.0", dynamic_link_opts);
} else {
if (b.lazyDependency("libxml2", .{
.target = target,
.optimize = optimize,
.iconv = libxml2_iconv_enabled,
})) |libxml2_dep| {
- lib.linkLibrary(libxml2_dep.artifact("xml2"));
+ lib.root_module.linkLibrary(libxml2_dep.artifact("xml2"));
}
}
}
if (b.lazyDependency("fontconfig", .{})) |upstream| {
- lib.addIncludePath(upstream.path(""));
+ lib.root_module.addIncludePath(upstream.path(""));
module.addIncludePath(upstream.path(""));
- lib.addCSourceFiles(.{
+ lib.root_module.addCSourceFiles(.{
.root = upstream.path(""),
.files = srcs,
.flags = flags.items,
@@ -253,6 +322,18 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
"fontconfig",
.{ .include_extensions = &.{".h"} },
);
+
+ // Upstream only ships fontconfig.h.in; we generate fontconfig.h into
+ // our override directory.
+ //
+ // TODO: I'm not too sure if this is fully needed - testing the build
+ // with both system integration on and off seems to be not break with
+ // this missing (and for that matter, all of the header install stuff
+ // we do, funny enough).
+ lib.installHeader(
+ b.path("override/fontconfig/fontconfig.h"),
+ "fontconfig/fontconfig.h",
+ );
}
b.installArtifact(lib);
@@ -260,12 +341,6 @@ fn buildLib(b: *std.Build, module: *std.Build.Module, options: anytype) !*std.Bu
return lib;
}
-const headers = &.{
- "fontconfig/fontconfig.h",
- "fontconfig/fcprivate.h",
- "fontconfig/fcfreetype.h",
-};
-
const srcs: []const []const u8 = &.{
"src/fcatomic.c",
"src/fccache.c",
@@ -278,6 +353,7 @@ const srcs: []const []const u8 = &.{
"src/fcformat.c",
"src/fcfreetype.c",
"src/fcfs.c",
+ "src/fcgenericalias.c",
"src/fcptrlist.c",
"src/fchash.c",
"src/fcinit.c",