mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-14 18:01:58 +00:00
This commit represents the majority of the work necessary to upgrade Ghostty to use Zig 0.16.0. Key parts: * In addition to its previous responsibilities, the global state now houses state for global I/O implementations and the process environment. It is now also utilized in the main application along with the C library. Where necessary, global state is isolated from key parts of the implementation (e.g., in libghostty subsystems), and it's expected that this list will grow. * We currently manage our own C translation layer where necessary. In these cases, cImport has been removed in favor of the new external translate-c package. Due to fixes that have needed be made to properly translate the dependencies that were swapped out, as mentioned, we have had to backport fixes from the current translate-c package (and the upstream Arocc dependency). We will host this ourselves until Zig 0.17.0 is released with these fixes. * Where necessary (only a small number of cases), some stdlib code from 0.15.2 (and even from 0.17.0) has been taken, adopted, and vendored in lib/compat. Co-authored-by: Leah Amelia Chen <hi@pluie.me>
87 lines
2.8 KiB
Zig
87 lines
2.8 KiB
Zig
const Version = @This();
|
|
|
|
const std = @import("std");
|
|
|
|
/// The short hash (7 characters) of the latest commit.
|
|
short_hash: []const u8,
|
|
|
|
/// True if there was a diff at build time.
|
|
changes: bool,
|
|
|
|
/// The tag -- if any -- that this commit is a part of.
|
|
tag: ?[]const u8,
|
|
|
|
/// The branch that was checked out at the time of the build.
|
|
branch: []const u8,
|
|
|
|
/// Initialize the version and detect it from the Git environment. This
|
|
/// allocates using the build allocator and doesn't free.
|
|
pub fn detect(b: *std.Build) !Version {
|
|
// Execute a bunch of git commands to determine the automatic version.
|
|
var code: u8 = 0;
|
|
const branch: []const u8 = b: {
|
|
const tmp: []u8 = b.runAllowFail(
|
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "rev-parse", "--abbrev-ref", "HEAD" },
|
|
&code,
|
|
.ignore,
|
|
) catch |err| switch (err) {
|
|
error.FileNotFound => return error.GitNotFound,
|
|
error.ExitCodeFailure => return error.GitNotRepository,
|
|
else => return err,
|
|
};
|
|
|
|
// Replace characters that are not valid in semantic version
|
|
// pre-release identifiers (which only allow [0-9A-Za-z-]).
|
|
// Slashes would also mess up dist tarball paths.
|
|
for (tmp) |*c| {
|
|
if (!std.ascii.isAlphanumeric(c.*) and c.* != '-') c.* = '-';
|
|
}
|
|
|
|
break :b tmp;
|
|
};
|
|
|
|
const short_hash = short_hash: {
|
|
const output = b.runAllowFail(
|
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "-c", "log.showSignature=false", "log", "--pretty=format:%h", "-n", "1" },
|
|
&code,
|
|
.ignore,
|
|
) catch |err| switch (err) {
|
|
error.FileNotFound => return error.GitNotFound,
|
|
else => return err,
|
|
};
|
|
|
|
break :short_hash std.mem.trimEnd(u8, output, "\r\n ");
|
|
};
|
|
|
|
const tag = b.runAllowFail(
|
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--exact-match", "--tags" },
|
|
&code,
|
|
.ignore,
|
|
) catch |err| switch (err) {
|
|
error.FileNotFound => return error.GitNotFound,
|
|
error.ExitCodeFailure => "", // expected
|
|
else => return err,
|
|
};
|
|
|
|
_ = b.runAllowFail(&[_][]const u8{
|
|
"git",
|
|
"-C",
|
|
b.build_root.path orelse ".",
|
|
"diff",
|
|
"--quiet",
|
|
"--exit-code",
|
|
}, &code, .ignore) catch |err| switch (err) {
|
|
error.FileNotFound => return error.GitNotFound,
|
|
error.ExitCodeFailure => {}, // expected
|
|
else => return err,
|
|
};
|
|
const changes = code != 0;
|
|
|
|
return .{
|
|
.short_hash = short_hash,
|
|
.changes = changes,
|
|
.tag = if (tag.len > 0) std.mem.trimEnd(u8, tag, "\r\n ") else null,
|
|
.branch = std.mem.trimEnd(u8, branch, "\r\n "),
|
|
};
|
|
}
|