Files
ghostty/src/main_build_data.zig
Alessandro De Blasis f9d3b1aafb build: fix Windows build failures in helpgen and framegen
Use writerStreaming() instead of writer() for stdout in helpgen and
main_build_data. The positional writer calls setEndPos/ftruncate in
end(), which fails on Windows because ftruncate on pipes maps
INVALID_PARAMETER to FileTooBig.

Replace scandir with opendir/readdir plus qsort in framegen since
scandir is a POSIX extension not available on Windows.

This was previously applied and reverted upstream (f4998c6ab, 0fdddd5bc)
as collateral from an unrelated example-execution hang that has since
been resolved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 08:07:31 +01:00

52 lines
1.8 KiB
Zig

//! This CLI is used to generate data that is used by the build process.
//!
//! We used to do this directly in our `build.zig` but the problem with
//! that approach is that any changes to the dependencies of this data would
//! force a rebuild of our build binary. If we're just doing something like
//! running tests and not emitting any of the info below, then that is a
//! complete waste.
const std = @import("std");
const Allocator = std.mem.Allocator;
const cli = @import("cli.zig");
pub const Action = enum {
// Shell completions
bash,
fish,
zsh,
// Editor syntax files
sublime,
@"vim-syntax",
@"vim-ftdetect",
@"vim-ftplugin",
@"vim-compiler",
// Other
terminfo,
};
pub fn main() !void {
const alloc = std.heap.c_allocator;
const action_ = try cli.action.detectArgs(Action, alloc);
const action = action_ orelse return error.NoAction;
// Our output always goes to stdout.
var buffer: [1024]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
const writer = &stdout_writer.interface;
switch (action) {
.bash => try writer.writeAll(@import("extra/bash.zig").completions),
.fish => try writer.writeAll(@import("extra/fish.zig").completions),
.zsh => try writer.writeAll(@import("extra/zsh.zig").completions),
.sublime => try writer.writeAll(@import("extra/sublime.zig").syntax),
.@"vim-syntax" => try writer.writeAll(@import("extra/vim.zig").syntax),
.@"vim-ftdetect" => try writer.writeAll(@import("extra/vim.zig").ftdetect),
.@"vim-ftplugin" => try writer.writeAll(@import("extra/vim.zig").ftplugin),
.@"vim-compiler" => try writer.writeAll(@import("extra/vim.zig").compiler),
.terminfo => try @import("terminfo/ghostty.zig").ghostty.encode(writer),
}
try stdout_writer.end();
}