feat: build with Zig 0.14

Multiple changes needed to build with Zig 0.14:

* upgraded ansi_term to version that also builds with 0.14 and made
the necessary code changes here.
* used the new separate cbor from flow-syntax and removed thespian
* updated for 0.14 renaming of some std enum values
* updated for a new 0.14 version of clap
* update flow-themes
This commit is contained in:
Robert Kroeger 2025-04-22 08:30:28 +08:00 committed by CJ van den Berg
parent 66629f0f9d
commit 9b3f6153da
5 changed files with 36 additions and 36 deletions

View file

@ -86,12 +86,14 @@ pub fn build_exe(
strip: bool, strip: bool,
pie: ?bool, pie: ?bool,
) void { ) void {
const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize }); const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize });
const ansi_term_dep = b.dependency("ansi-term", .{ .target = target, .optimize = optimize }); const ansi_term_dep = b.dependency("ansi_term", .{ .target = target, .optimize = optimize });
const themes_dep = b.dependency("themes", .{}); const themes_dep = b.dependency("themes", .{});
const syntax_dep = b.dependency("syntax", .{ .target = target, .optimize = optimize }); const syntax_dep = b.dependency("syntax", .{ .target = target, .optimize = optimize });
const thespian_dep = b.dependency("thespian", .{}); const cbor_dep = syntax_dep.builder.dependency("cbor", .{
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "zat", .name = "zat",
@ -105,8 +107,8 @@ pub fn build_exe(
exe.root_module.addImport("theme", themes_dep.module("theme")); exe.root_module.addImport("theme", themes_dep.module("theme"));
exe.root_module.addImport("themes", themes_dep.module("themes")); exe.root_module.addImport("themes", themes_dep.module("themes"));
exe.root_module.addImport("clap", clap_dep.module("clap")); exe.root_module.addImport("clap", clap_dep.module("clap"));
exe.root_module.addImport("ansi-term", ansi_term_dep.module("ansi-term")); exe.root_module.addImport("ansi_term", ansi_term_dep.module("ansi_term"));
exe.root_module.addImport("cbor", b.createModule(.{ .root_source_file = thespian_dep.path("src/cbor.zig") })); exe.root_module.addImport("cbor", cbor_dep.module("cbor"));
const exe_install = b.addInstallArtifact(exe, exe_install_options); const exe_install = b.addInstallArtifact(exe, exe_install_options);
b.getInstallStep().dependOn(&exe_install.step); b.getInstallStep().dependOn(&exe_install.step);

View file

@ -1 +1 @@
0.13.0 0.14.0

View file

@ -1,26 +1,23 @@
.{ .{
.name = "zat", .name = .zat,
.version = "1.0.0", .version = "1.0.0",
.fingerprint = 0x8da9db57fa011a09,
.dependencies = .{ .dependencies = .{
.clap = .{ .clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/c0193e9247335a6c1688b946325060289405de2a.tar.gz", .url = "https://github.com/Hejsil/zig-clap/archive/0.10.0.tar.gz",
.hash = "12207ee987ce045596cb992cfb15b0d6d9456e50d4721c3061c69dabc2962053644d", .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0",
}, },
.themes = .{ .themes = .{
.url = "https://github.com/neurocyte/flow-themes/releases/download/master-618a7801d3383049adfe18cc09f5f5086c66995f/flow-themes.tar.gz", .url = "https://github.com/neurocyte/flow-themes/releases/download/master-ac2e3fe2df3419b71276f86fa9c45fd39d668f23/flow-themes.tar.gz",
.hash = "1220019ed92f48fb94d4ae82bba17b11d0ba06f17ed31cd66613b3c048b1d2382095", .hash = "N-V-__8AAEtaFwAjAHCmWHRCrBxL7uSG4hQiIsSgS32Y67K6",
}, },
.syntax = .{ .syntax = .{
.url = "https://github.com/neurocyte/flow-syntax/archive/28bc77f4615488aaa269c25fc862864f4b3a7460.tar.gz", .url = "https://github.com/neurocyte/flow-syntax/archive/fa6a411bc769882acc87cf0d961af3813abf2eac.tar.gz",
.hash = "1220abddc10ca8f8b6b5477f8c007948c168504b9dd3516899fe37251890eeabf4ab", .hash = "flow_syntax-0.1.0-X8jOof39AADK25RT1Bst_x7aUIwHbh7y09PJXBghLu_b",
}, },
.thespian = .{ .ansi_term = .{
.url = "https://github.com/neurocyte/thespian/archive/d7dd27116398b17c8ab68327c384885f161d0cc1.tar.gz", .url = "https://github.com/ziglibs/ansi-term/archive/c0e6ad093d4f6a9ed4e65d962d1e53b97888f989.tar.gz",
.hash = "1220ace715c2ee9087fe375996b8e9180bfc722b2d1acdcbf00e8b507b31dd1cdd94", .hash = "ansi_term-0.1.0-_baAywpoAABEqsPmS5Jz_CddDCrG8qdIyRIESH8D2fzd",
},
.@"ansi-term" = .{
.url = "https://github.com/ziglibs/ansi-term/archive/0bb62115db6749044765fdb37c9791388e7970f2.tar.gz",
.hash = "12200719196e0abd325efa248fb03882c8fa2c7130e3ae1d57dbff72afc846b28495",
}, },
}, },
.paths = .{ .paths = .{

View file

@ -31,7 +31,7 @@ fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]c
var found = false; var found = false;
var field_name: []const u8 = undefined; var field_name: []const u8 = undefined;
if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidConfig; if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidConfig;
inline for (@typeInfo(config).Struct.fields) |field_info| { inline for (@typeInfo(config).@"struct".fields) |field_info| {
if (std.mem.eql(u8, field_name, field_info.name)) { if (std.mem.eql(u8, field_name, field_info.name)) {
var value: field_info.type = undefined; var value: field_info.type = undefined;
if (!(try cbor.matchValue(&iter, cbor.extract(&value)))) return error.InvalidConfig; if (!(try cbor.matchValue(&iter, cbor.extract(&value)))) return error.InvalidConfig;

View file

@ -3,7 +3,7 @@ const clap = @import("clap");
const syntax = @import("syntax"); const syntax = @import("syntax");
const Theme = @import("theme"); const Theme = @import("theme");
const themes = @import("themes"); const themes = @import("themes");
const term = @import("ansi-term"); const term = @import("ansi_term");
const config_loader = @import("config_loader.zig"); const config_loader = @import("config_loader.zig");
const Writer = std.io.BufferedWriter(4096, std.fs.File.Writer).Writer; const Writer = std.io.BufferedWriter(4096, std.fs.File.Writer).Writer;
@ -70,7 +70,7 @@ pub fn main() !void {
return list_langs(writer); return list_langs(writer);
if (res.args.color == 0 and !stdout_file.supportsAnsiEscapeCodes()) if (res.args.color == 0 and !stdout_file.supportsAnsiEscapeCodes())
return plain_cat(res.positionals); return plain_cat(res.positionals[0]);
var conf_buf: ?[]const u8 = null; var conf_buf: ?[]const u8 = null;
const conf = config_loader.read_config(a, &conf_buf); const conf = config_loader.read_config(a, &conf_buf);
@ -106,8 +106,8 @@ pub fn main() !void {
if (res.args.html != 0) if (res.args.html != 0)
try write_html_preamble(writer, theme.editor); try write_html_preamble(writer, theme.editor);
if (res.positionals.len > 0) { if (res.positionals[0].len > 0) {
for (res.positionals) |arg| { for (res.positionals[0]) |arg| {
const file = if (std.mem.eql(u8, arg, "-")) const file = if (std.mem.eql(u8, arg, "-"))
std.io.getStdIn() std.io.getStdIn()
else else
@ -158,11 +158,11 @@ pub fn main() !void {
try write_html_postamble(writer); try write_html_postamble(writer);
} }
fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8) *syntax { fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8, query_cache: *syntax.QueryCache) *syntax {
return (if (lang_override) |name| return (if (lang_override) |name|
syntax.create_file_type(a, name) catch unknown_file_type(name) syntax.create_file_type(a, name, query_cache) catch unknown_file_type(name)
else else
syntax.create_guess_file_type(a, content, file_path)) catch syntax.create_file_type(a, lang_default) catch unknown_file_type(lang_default); syntax.create_guess_file_type(a, content, file_path, query_cache)) catch syntax.create_file_type(a, lang_default, query_cache) catch unknown_file_type(lang_default);
} }
fn unknown_file_type(name: []const u8) noreturn { fn unknown_file_type(name: []const u8) noreturn {
@ -200,7 +200,8 @@ fn render_file(
end_line = start_line + lines; end_line = start_line + lines;
} }
const parser = get_parser(a, content, file_path); const query_cache = try syntax.QueryCache.create(a, .{});
const parser = get_parser(a, content, file_path, query_cache);
try parser.refresh_full(content); try parser.refresh_full(content);
if (show) { if (show) {
try render_file_type(writer, parser.file_type, theme); try render_file_type(writer, parser.file_type, theme);
@ -399,16 +400,16 @@ fn list_themes(writer: Writer) !void {
} }
fn set_ansi_style(writer: Writer, style: Theme.Style) Writer.Error!void { fn set_ansi_style(writer: Writer, style: Theme.Style) Writer.Error!void {
const ansi_style = .{ const ansi_style: term.style.Style = .{
.foreground = if (style.fg) |color| to_rgb_color(color.color) else .Default, .foreground = if (style.fg) |color| to_rgb_color(color.color) else .Default,
.background = if (style.bg) |color| to_rgb_color(color.color) else .Default, .background = if (style.bg) |color| to_rgb_color(color.color) else .Default,
.font_style = switch (style.fs orelse .normal) { .font_style = switch (style.fs orelse .normal) {
.normal => term.style.FontStyle{}, .normal => term.style.FontStyle{},
.bold => term.style.FontStyle.bold, .bold => term.style.FontStyle{ .bold = true },
.italic => term.style.FontStyle.italic, .italic => term.style.FontStyle{ .italic = true },
.underline => term.style.FontStyle.underline, .underline => term.style.FontStyle{ .underline = true },
.undercurl => term.style.FontStyle.underline, .undercurl => term.style.FontStyle{ .underline = true },
.strikethrough => term.style.FontStyle.crossedout, .strikethrough => term.style.FontStyle{ .crossedout = true },
}, },
}; };
try term.format.updateStyle(writer, ansi_style, null); try term.format.updateStyle(writer, ansi_style, null);
@ -503,7 +504,7 @@ fn plain_cat_file(out_file: std.fs.File, in_file_name: []const u8) !void {
try std.fs.cwd().openFile(in_file_name, .{}); try std.fs.cwd().openFile(in_file_name, .{});
defer in_file.close(); defer in_file.close();
var buf: [std.mem.page_size]u8 = undefined; var buf: [std.heap.page_size_min]u8 = undefined;
while (true) { while (true) {
const bytes_read = try in_file.read(&buf); const bytes_read = try in_file.read(&buf);
if (bytes_read == 0) return; if (bytes_read == 0) return;