diff --git a/build.zig b/build.zig index 78a871efb..58cfc8965 100644 --- a/build.zig +++ b/build.zig @@ -199,7 +199,7 @@ pub fn build(b: *std.Build) !void { // Help exe. This must be run before any dependent executables because // otherwise the build will be cached without emit. That's clunky but meh. - if (emit_helpgen) addHelp(b, null); + if (emit_helpgen) try addHelp(b, null, config); // Add our benchmarks try benchSteps(b, target, optimize, config, emit_bench); @@ -1107,7 +1107,7 @@ fn addDeps( } } - addHelp(b, step); + try addHelp(b, step, config); return static_libs; } @@ -1116,7 +1116,8 @@ fn addDeps( fn addHelp( b: *std.Build, step_: ?*std.Build.Step.Compile, -) void { + config: BuildConfig, +) !void { // Our static state between runs. We memoize our help strings // so that we only execute the help generation once. const HelpState = struct { @@ -1131,6 +1132,15 @@ fn addHelp( }); if (step_ == null) b.installArtifact(help_exe); + const help_config = config: { + var copy = config; + copy.exe_entrypoint = .helpgen; + break :config copy; + }; + const options = b.addOptions(); + try help_config.addOptions(options); + help_exe.root_module.addOptions("build_options", options); + const help_run = b.addRunArtifact(help_exe); HelpState.generated = help_run.captureStdOut(); break :strings HelpState.generated.?; @@ -1163,7 +1173,7 @@ fn buildDocumentation( .root_source_file = .{ .path = "src/main.zig" }, .target = b.host, }); - addHelp(b, generate_markdown); + try addHelp(b, generate_markdown, config); const gen_config = config: { var copy = config; diff --git a/src/build_config.zig b/src/build_config.zig index 789155fee..94621e1c7 100644 --- a/src/build_config.zig +++ b/src/build_config.zig @@ -135,6 +135,7 @@ pub const Artifact = enum { /// Therefore, main.zig uses this to switch between the different entrypoints. pub const ExeEntrypoint = enum { ghostty, + helpgen, mdgen_ghostty_1, mdgen_ghostty_5, }; diff --git a/src/main.zig b/src/main.zig index 9038fc351..d0be97b85 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,6 +37,7 @@ pub fn main() !MainReturn { if (comptime build_config.artifact == .exe) entrypoint: { switch (comptime build_config.exe_entrypoint) { .ghostty => break :entrypoint, // This function + .helpgen => try @import("helpgen.zig").main(), .mdgen_ghostty_1 => try @import("build/mdgen/main_ghostty_1.zig").main(), .mdgen_ghostty_5 => try @import("build/mdgen/main_ghostty_5.zig").main(), }