mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-01 03:02:15 +00:00
The major idea behind the refactor is to split the `build.zig` file up into
distinct `src/build/*.zig` files. By doing so, we can improve readability of
the primary `build.zig` while also enabling better reuse of steps. Our
`build.zig` is now less than 150 lines of code (of course, it calls into a lot
more lines but they're neatly organized now).
Improvements:
* `build.zig` is less than 150 lines of readable code.
* Help strings and unicode table generators are only run once when multiple
artifacts are built since the results are the same regardless of target.
* Metal lib is only built once per architecture (rather than once per artifact)
* Resources (shell integration, terminfo, etc.) and docs are only
built/installed for artifacts that need them
Breaking changes:
* Removed broken wasm build (@gabydd will re-add)
* Removed conformance files, shell scripts are better and we don't run
these anymore
* Removed macOS app bundle creation, we don't use this anymore since we
use Xcode
## Some History
Our `build.zig` hasn't been significantly refactored since the project started,
when Zig was _version 0.10_. Since then, the build system has changed
significantly. We've only ever duct taped the `build.zig` as we needed to
support new Zig versions, new features, etc. It was a mess.
The major improvement is adapting the entire Ghostty `build.zig` to the Step
and LazyPath changes introduced way back in Zig 0.12. This lets us better take
advantage of parallelism and the dependency graph so that steps are only
executed as they're needed.
As such, you can see in the build.zig that we initialize a lot of things, but
unless a final target (i.e. install, run) references those steps, _they'll
never be executed_. This lets us clean up a lot.
83 lines
2.4 KiB
Zig
83 lines
2.4 KiB
Zig
//! GhosttyWebdata generates all the Ghostty website data that is
|
|
//! merged with the website for things like config references.
|
|
const GhosttyWebdata = @This();
|
|
|
|
const std = @import("std");
|
|
const Config = @import("Config.zig");
|
|
const SharedDeps = @import("SharedDeps.zig");
|
|
|
|
steps: []*std.Build.Step,
|
|
|
|
pub fn init(
|
|
b: *std.Build,
|
|
deps: *const SharedDeps,
|
|
) !GhosttyWebdata {
|
|
var steps = std.ArrayList(*std.Build.Step).init(b.allocator);
|
|
errdefer steps.deinit();
|
|
|
|
{
|
|
const webgen_config = b.addExecutable(.{
|
|
.name = "webgen_config",
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = b.host,
|
|
});
|
|
deps.help_strings.addImport(webgen_config);
|
|
|
|
{
|
|
const buildconfig = config: {
|
|
var copy = deps.config.*;
|
|
copy.exe_entrypoint = .webgen_config;
|
|
break :config copy;
|
|
};
|
|
|
|
const options = b.addOptions();
|
|
try buildconfig.addOptions(options);
|
|
webgen_config.root_module.addOptions("build_options", options);
|
|
}
|
|
|
|
const webgen_config_step = b.addRunArtifact(webgen_config);
|
|
const webgen_config_out = webgen_config_step.captureStdOut();
|
|
|
|
try steps.append(&b.addInstallFile(
|
|
webgen_config_out,
|
|
"share/ghostty/webdata/config.mdx",
|
|
).step);
|
|
}
|
|
|
|
{
|
|
const webgen_actions = b.addExecutable(.{
|
|
.name = "webgen_actions",
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = b.host,
|
|
});
|
|
deps.help_strings.addImport(webgen_actions);
|
|
|
|
{
|
|
const buildconfig = config: {
|
|
var copy = deps.config.*;
|
|
copy.exe_entrypoint = .webgen_actions;
|
|
break :config copy;
|
|
};
|
|
|
|
const options = b.addOptions();
|
|
try buildconfig.addOptions(options);
|
|
webgen_actions.root_module.addOptions("build_options", options);
|
|
}
|
|
|
|
const webgen_actions_step = b.addRunArtifact(webgen_actions);
|
|
const webgen_actions_out = webgen_actions_step.captureStdOut();
|
|
|
|
try steps.append(&b.addInstallFile(
|
|
webgen_actions_out,
|
|
"share/ghostty/webdata/actions.mdx",
|
|
).step);
|
|
}
|
|
|
|
return .{ .steps = steps.items };
|
|
}
|
|
|
|
pub fn install(self: *const GhosttyWebdata) void {
|
|
const b = self.steps[0].owner;
|
|
for (self.steps) |step| b.getInstallStep().dependOn(step);
|
|
}
|