mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-02 19:42:38 +00:00
Previously we're just feeding the compiler source files generated via capturing stdout, which all by default have the filename `stdout`. Under some particular yet uncertain circumstances in Zig 0.14 (only factor we've found so far is a large amount of cores/compilation shards) the compiler will actually crash on an unreachable code path that assumes all source files either end in .zig or .zon, causing crashes for packagers for distros like Nixpkgs and Gentoo. Given this has been explicitly made illegal in Zig 0.15 (see ziglang/zig#24957) I don't really see why we shouldn't fix this for 1.2 too. We have to do this at some point no matter what anyways.
57 lines
1.5 KiB
Zig
57 lines
1.5 KiB
Zig
const HelpStrings = @This();
|
|
|
|
const std = @import("std");
|
|
const Config = @import("Config.zig");
|
|
|
|
/// The "helpgen" exe.
|
|
exe: *std.Build.Step.Compile,
|
|
|
|
/// The output path for the help strings.
|
|
output: std.Build.LazyPath,
|
|
|
|
pub fn init(b: *std.Build, cfg: *const Config) !HelpStrings {
|
|
const exe = b.addExecutable(.{
|
|
.name = "helpgen",
|
|
.root_module = b.createModule(.{
|
|
.root_source_file = b.path("src/helpgen.zig"),
|
|
.target = b.graph.host,
|
|
.strip = false,
|
|
.omit_frame_pointer = false,
|
|
.unwind_tables = .sync,
|
|
}),
|
|
});
|
|
|
|
const help_config = config: {
|
|
var copy = cfg.*;
|
|
copy.exe_entrypoint = .helpgen;
|
|
break :config copy;
|
|
};
|
|
const options = b.addOptions();
|
|
try help_config.addOptions(options);
|
|
exe.root_module.addOptions("build_options", options);
|
|
|
|
const help_run = b.addRunArtifact(exe);
|
|
|
|
// Generated Zig files have to end with .zig
|
|
const wf = b.addWriteFiles();
|
|
const output = wf.addCopyFile(help_run.captureStdOut(), "helpgen.zig");
|
|
|
|
return .{
|
|
.exe = exe,
|
|
.output = output,
|
|
};
|
|
}
|
|
|
|
/// Add the "help_strings" import.
|
|
pub fn addImport(self: *const HelpStrings, step: *std.Build.Step.Compile) void {
|
|
self.output.addStepDependencies(&step.step);
|
|
step.root_module.addAnonymousImport("help_strings", .{
|
|
.root_source_file = self.output,
|
|
});
|
|
}
|
|
|
|
/// Install the help exe
|
|
pub fn install(self: *const HelpStrings) void {
|
|
self.exe.step.owner.installArtifact(self.exe);
|
|
}
|