diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/build.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/build.zig')
| -rw-r--r-- | vendor/libghostty-vt/build.zig | 97 |
1 files changed, 81 insertions, 16 deletions
diff --git a/vendor/libghostty-vt/build.zig b/vendor/libghostty-vt/build.zig index 8ef7701e..5204b3d8 100644 --- a/vendor/libghostty-vt/build.zig +++ b/vendor/libghostty-vt/build.zig @@ -25,9 +25,10 @@ pub fn build(b: *std.Build) !void { // use that as the version source of truth. Otherwise we fall back // to what is in the build.zig.zon. const file_version: ?[]const u8 = if (b.build_root.handle.readFileAlloc( - b.allocator, + b.graph.io, "VERSION", - 128, + b.allocator, + .limited(128), )) |content| std.mem.trim( u8, content, @@ -68,6 +69,14 @@ pub fn build(b: *std.Build) !void { "test-lib-vt", "Run libghostty-vt tests", ); + const test_lib_vt_build_step = b.step( + "test-lib-vt-build", + "Build libghostty-vt tests without running them (compile check)", + ); + const test_lib_vt_schema_step = b.step( + "test-lib-vt-schema", + "Validate the libghostty-vt ABI type manifest", + ); const test_valgrind_step = b.step( "test-valgrind", "Run tests under valgrind", @@ -100,8 +109,10 @@ pub fn build(b: *std.Build) !void { if (config.emit_webdata) webdata.install(); // Ghostty bench tools - const bench = try buildpkg.GhosttyBench.init(b, &deps); - if (config.emit_bench) bench.install(); + if (config.emit_bench) { + const bench = try buildpkg.GhosttyBench.init(b, &deps); + bench.install(); + } // Ghostty dist tarball const dist = try buildpkg.GhosttyDist.init(b, &config); @@ -114,20 +125,36 @@ pub fn build(b: *std.Build) !void { } // libghostty-vt - const libghostty_vt_shared = shared: { + const native_freestanding = config.target.result.os.tag == .freestanding and + !config.target.result.cpu.arch.isWasm(); + const libghostty_vt_shared: ?buildpkg.GhosttyLibVt = shared: { if (config.target.result.cpu.arch.isWasm()) { break :shared try buildpkg.GhosttyLibVt.initWasm( b, &mod, ); } + if (native_freestanding) break :shared null; break :shared try buildpkg.GhosttyLibVt.initShared( b, &mod, ); }; - libghostty_vt_shared.install(b.getInstallStep()); + if (libghostty_vt_shared) |shared| { + shared.install(b.getInstallStep()); + + const type_schema_test = b.addSystemCommand(&.{"python3"}); + type_schema_test.addFileArg(b.path("src/terminal/c/types-schema-verify.py")); + type_schema_test.addFileArg(b.path("src/terminal/c/types.schema.json")); + type_schema_test.addFileArg(shared.output); + test_lib_vt_schema_step.dependOn(&type_schema_test.step); + } else { + try test_lib_vt_schema_step.addError( + "cannot execute the ABI manifest for a native freestanding target", + .{}, + ); + } // libghostty-vt static lib const libghostty_vt_static = try buildpkg.GhosttyLibVt.initStatic( @@ -150,6 +177,15 @@ pub fn build(b: *std.Build) !void { libghostty_vt_static.output, static_lib_name, ).step); + + if (native_freestanding) { + b.getInstallStep().dependOn(&b.addInstallDirectory(.{ + .source_dir = b.path("include/ghostty"), + .install_dir = .header, + .install_subdir = "ghostty", + .include_extensions = &.{".h"}, + }).step); + } } // libghostty-vt xcframework (Apple only, universal binary). @@ -298,7 +334,7 @@ pub fn build(b: *std.Build) !void { // We need to rebuild Ghostty with a baseline CPU target. const valgrind_exe = exe: { var valgrind_config = config; - valgrind_config.target = valgrind_config.baselineTarget(); + valgrind_config.target = valgrind_config.baselineTarget(b.graph.io); break :exe try buildpkg.GhosttyExe.init( b, &valgrind_config, @@ -309,6 +345,7 @@ pub fn build(b: *std.Build) !void { const run_cmd = b.addSystemCommand(&.{ "valgrind", "--leak-check=full", + "--error-exitcode=1", "--num-callers=50", b.fmt("--suppressions={s}", .{b.pathFromRoot("valgrind.supp")}), "--gen-suppressions=all", @@ -326,6 +363,7 @@ pub fn build(b: *std.Build) !void { }); const mod_vt_test_run = b.addRunArtifact(mod_vt_test); test_lib_vt_step.dependOn(&mod_vt_test_run.step); + test_lib_vt_build_step.dependOn(&mod_vt_test.step); const mod_vt_c_test = b.addTest(.{ .root_module = mod.vt_c, @@ -333,6 +371,7 @@ pub fn build(b: *std.Build) !void { }); const mod_vt_c_test_run = b.addRunArtifact(mod_vt_c_test); test_lib_vt_step.dependOn(&mod_vt_c_test_run.step); + test_lib_vt_build_step.dependOn(&mod_vt_c_test.step); } // Tests (skip when building libghostty-vt) @@ -343,7 +382,7 @@ pub fn build(b: *std.Build) !void { .filters = test_filters, .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), - .target = config.baselineTarget(), + .target = config.baselineTarget(b.graph.io), .optimize = .Debug, .strip = false, .omit_frame_pointer = false, @@ -352,19 +391,18 @@ pub fn build(b: *std.Build) !void { // Crash on x86_64 without this .use_llvm = true, }); - if (config.emit_test_exe) b.installArtifact(test_exe); + if (config.emit_test_exe) { + const test_exe_install = b.addInstallArtifact(test_exe, .{}); + config.addPatchElf(test_exe, &test_exe_install.step); + test_step.dependOn(&test_exe_install.step); + } _ = try deps.add(test_exe); - // Verify our internal libghostty header. - const ghostty_h = b.addTranslateC(.{ - .root_source_file = b.path("include/ghostty.h"), - .target = config.baselineTarget(), - .optimize = .Debug, - }); - test_exe.root_module.addImport("ghostty.h", ghostty_h.createModule()); + addGhosttyH(b, test_exe.root_module, config.baselineTarget(b.graph.io), .Debug); // Normal test running const test_run = b.addRunArtifact(test_exe); + config.addPatchElf(test_exe, &test_run.step); test_step.dependOn(&test_run.step); // Normal tests always test our libghostty modules @@ -374,11 +412,13 @@ pub fn build(b: *std.Build) !void { const valgrind_run = b.addSystemCommand(&.{ "valgrind", "--leak-check=full", + "--error-exitcode=1", "--num-callers=50", b.fmt("--suppressions={s}", .{b.pathFromRoot("valgrind.supp")}), "--gen-suppressions=all", }); valgrind_run.addArtifactArg(test_exe); + config.addPatchElf(test_exe, &valgrind_run.step); test_valgrind_step.dependOn(&valgrind_run.step); } @@ -390,3 +430,28 @@ pub fn build(b: *std.Build) !void { try translations_step.addError("cannot update translations when i18n is disabled", .{}); } } + +fn addGhosttyH( + b: *std.Build, + module: *std.Build.Module, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, +) void { + const translate_c = b.lazyImport(@This(), "translate_c") orelse return; + const translate_c_dep = b.lazyDependency("translate_c", .{}) orelse return; + + const translated: translate_c.Translator = .init(translate_c_dep, .{ + .c_source_file = b.addWriteFiles().add( + "hb_c.h", + \\#include <ghostty.h> + , + ), + .target = target, + .optimize = optimize, + .link_libc = true, + }); + + translated.addSystemIncludePath(b.path("include")); + + module.addImport("ghostty.h", translated.mod); +} |
