add helpgen entrypoint

This commit is contained in:
Mitchell Hashimoto
2024-02-04 20:17:47 -08:00
parent 1f2b30496b
commit 1a9f80c403
3 changed files with 16 additions and 4 deletions

View File

@ -199,7 +199,7 @@ pub fn build(b: *std.Build) !void {
// Help exe. This must be run before any dependent executables because // Help exe. This must be run before any dependent executables because
// otherwise the build will be cached without emit. That's clunky but meh. // 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 // Add our benchmarks
try benchSteps(b, target, optimize, config, emit_bench); 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; return static_libs;
} }
@ -1116,7 +1116,8 @@ fn addDeps(
fn addHelp( fn addHelp(
b: *std.Build, b: *std.Build,
step_: ?*std.Build.Step.Compile, step_: ?*std.Build.Step.Compile,
) void { config: BuildConfig,
) !void {
// Our static state between runs. We memoize our help strings // Our static state between runs. We memoize our help strings
// so that we only execute the help generation once. // so that we only execute the help generation once.
const HelpState = struct { const HelpState = struct {
@ -1131,6 +1132,15 @@ fn addHelp(
}); });
if (step_ == null) b.installArtifact(help_exe); 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); const help_run = b.addRunArtifact(help_exe);
HelpState.generated = help_run.captureStdOut(); HelpState.generated = help_run.captureStdOut();
break :strings HelpState.generated.?; break :strings HelpState.generated.?;
@ -1163,7 +1173,7 @@ fn buildDocumentation(
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = .{ .path = "src/main.zig" },
.target = b.host, .target = b.host,
}); });
addHelp(b, generate_markdown); try addHelp(b, generate_markdown, config);
const gen_config = config: { const gen_config = config: {
var copy = config; var copy = config;

View File

@ -135,6 +135,7 @@ pub const Artifact = enum {
/// Therefore, main.zig uses this to switch between the different entrypoints. /// Therefore, main.zig uses this to switch between the different entrypoints.
pub const ExeEntrypoint = enum { pub const ExeEntrypoint = enum {
ghostty, ghostty,
helpgen,
mdgen_ghostty_1, mdgen_ghostty_1,
mdgen_ghostty_5, mdgen_ghostty_5,
}; };

View File

@ -37,6 +37,7 @@ pub fn main() !MainReturn {
if (comptime build_config.artifact == .exe) entrypoint: { if (comptime build_config.artifact == .exe) entrypoint: {
switch (comptime build_config.exe_entrypoint) { switch (comptime build_config.exe_entrypoint) {
.ghostty => break :entrypoint, // This function .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_1 => try @import("build/mdgen/main_ghostty_1.zig").main(),
.mdgen_ghostty_5 => try @import("build/mdgen/main_ghostty_5.zig").main(), .mdgen_ghostty_5 => try @import("build/mdgen/main_ghostty_5.zig").main(),
} }