Zig 0.15: zig build test

This commit is contained in:
Mitchell Hashimoto
2025-10-01 13:10:40 -07:00
parent 3770f97608
commit cb295b84a0
66 changed files with 1264 additions and 1144 deletions

View File

@@ -7,6 +7,7 @@ const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const build_config = @import("../build_config.zig");
const uucode = @import("uucode");
const EntryFormatter = @import("../config/formatter.zig").EntryFormatter;
const key = @import("key.zig");
const KeyEvent = key.KeyEvent;
@@ -1184,13 +1185,8 @@ pub const Action = union(enum) {
/// action back into the format used by parse.
pub fn format(
self: Action,
comptime layout: []const u8,
opts: std.fmt.FormatOptions,
writer: anytype,
writer: *std.Io.Writer,
) !void {
_ = layout;
_ = opts;
switch (self) {
inline else => |value| {
// All actions start with the tag.
@@ -1206,16 +1202,16 @@ pub const Action = union(enum) {
}
fn formatValue(
writer: anytype,
writer: *std.Io.Writer,
value: anytype,
) !void {
const Value = @TypeOf(value);
const value_info = @typeInfo(Value);
switch (Value) {
void => {},
[]const u8 => try std.zig.stringEscape(value, "", .{}, writer),
[]const u8 => try std.zig.stringEscape(value, writer),
else => switch (value_info) {
.@"enum" => try writer.print("{s}", .{@tagName(value)}),
.@"enum" => try writer.print("{t}", .{value}),
.float => try writer.print("{d}", .{value}),
.int => try writer.print("{d}", .{value}),
.@"struct" => |info| if (!info.is_tuple) {
@@ -1648,13 +1644,8 @@ pub const Trigger = struct {
/// Format implementation for fmt package.
pub fn format(
self: Trigger,
comptime layout: []const u8,
opts: std.fmt.FormatOptions,
writer: anytype,
writer: *std.Io.Writer,
) !void {
_ = layout;
_ = opts;
// Modifiers first
if (self.mods.super) try writer.writeAll("super+");
if (self.mods.ctrl) try writer.writeAll("ctrl+");
@@ -1663,7 +1654,7 @@ pub const Trigger = struct {
// Key
switch (self.key) {
.physical => |k| try writer.print("{s}", .{@tagName(k)}),
.physical => |k| try writer.print("{t}", .{k}),
.unicode => |c| try writer.print("{u}", .{c}),
}
}
@@ -1721,13 +1712,8 @@ pub const Set = struct {
/// action back into the format used by parse.
pub fn format(
self: Value,
comptime layout: []const u8,
opts: std.fmt.FormatOptions,
writer: anytype,
writer: *std.Io.Writer,
) !void {
_ = layout;
_ = opts;
switch (self) {
.leader => |set| {
// the leader key was already printed.
@@ -1758,26 +1744,34 @@ pub const Set = struct {
/// that is shared between calls to nested levels of the set.
/// For example, 'a>b>c=x' and 'a>b>d=y' will re-use the 'a>b' written
/// to the buffer before flushing it to the formatter with 'c=x' and 'd=y'.
pub fn formatEntries(self: Value, buffer_stream: anytype, formatter: anytype) !void {
pub fn formatEntries(
self: Value,
buffer: *std.Io.Writer,
formatter: EntryFormatter,
) !void {
switch (self) {
.leader => |set| {
// We'll rewind to this position after each sub-entry,
// sharing the prefix between siblings.
const pos = try buffer_stream.getPos();
const pos = buffer.end;
var iter = set.bindings.iterator();
while (iter.next()) |binding| {
buffer_stream.seekTo(pos) catch unreachable; // can't fail
std.fmt.format(buffer_stream.writer(), ">{s}", .{binding.key_ptr.*}) catch return error.OutOfMemory;
try binding.value_ptr.*.formatEntries(buffer_stream, formatter);
// I'm not exactly if this is safe for any arbitrary
// writer since the Writer interface does not have any
// rewind functions, but for our use case of a
// fixed-size buffer writer this should work just fine.
buffer.end = pos;
buffer.print(">{f}", .{binding.key_ptr.*}) catch return error.OutOfMemory;
try binding.value_ptr.*.formatEntries(buffer, formatter);
}
},
.leaf => |leaf| {
// When we get to the leaf, the buffer_stream contains
// the full sequence of keys needed to reach this action.
std.fmt.format(buffer_stream.writer(), "={s}", .{leaf.action}) catch return error.OutOfMemory;
try formatter.formatEntry([]const u8, buffer_stream.getWritten());
buffer.print("={f}", .{leaf.action}) catch return error.OutOfMemory;
try formatter.formatEntry([]const u8, buffer.buffer[0..buffer.end]);
},
}
}
@@ -3234,11 +3228,8 @@ test "action: format" {
const a: Action = .{ .text = "👻" };
var buf: std.ArrayListUnmanaged(u8) = .empty;
defer buf.deinit(alloc);
const writer = buf.writer(alloc);
try a.format("", .{}, writer);
try testing.expectEqualStrings("text:\\xf0\\x9f\\x91\\xbb", buf.items);
var buf: std.Io.Writer.Allocating = .init(alloc);
defer buf.deinit();
try a.format(&buf.writer);
try testing.expectEqualStrings("text:\\xf0\\x9f\\x91\\xbb", buf.written());
}

View File

@@ -50,7 +50,7 @@ pub const Command = struct {
return .{
.action_key = @tagName(self.action),
.action = std.fmt.comptimePrint("{s}", .{self.action}),
.action = std.fmt.comptimePrint("{t}", .{self.action}),
.title = self.title,
.description = self.description,
};
@@ -94,6 +94,7 @@ pub const defaults: []const Command = defaults: {
/// Defaults in C-compatible form.
pub const defaultsC: []const Command.C = defaults: {
@setEvalBranchQuota(100_000);
var result: [defaults.len]Command.C = undefined;
for (defaults, 0..) |cmd, i| result[i] = cmd.comptimeCval();
const final = result;

View File

@@ -278,6 +278,7 @@ fn pcStyle(comptime fmt: []const u8) []Entry {
// The comptime {} wrapper is superfluous but it prevents us from
// accidentally running this function at runtime.
comptime {
@setEvalBranchQuota(500_000);
var entries: [modifiers.len]Entry = undefined;
for (modifiers, 2.., 0..) |mods, code, i| {
entries[i] = .{

View File

@@ -13,7 +13,7 @@ pub const Format = enum {
/// Markdown formatted output
markdown,
fn formatFieldName(self: Format, writer: anytype, field_name: []const u8) !void {
fn formatFieldName(self: Format, writer: *std.Io.Writer, field_name: []const u8) !void {
switch (self) {
.plaintext => {
try writer.writeAll(field_name);
@@ -27,16 +27,16 @@ pub const Format = enum {
}
}
fn formatDocLine(self: Format, writer: anytype, line: []const u8) !void {
fn formatDocLine(self: Format, writer: *std.Io.Writer, line: []const u8) !void {
switch (self) {
.plaintext => {
try writer.appendSlice(" ");
try writer.appendSlice(line);
try writer.appendSlice("\n");
try writer.writeAll(" ");
try writer.writeAll(line);
try writer.writeAll("\n");
},
.markdown => {
try writer.appendSlice(line);
try writer.appendSlice("\n");
try writer.writeAll(line);
try writer.writeAll("\n");
},
}
}
@@ -61,7 +61,7 @@ pub const Format = enum {
/// Generate keybind actions documentation with the specified format
pub fn generate(
writer: anytype,
writer: *std.Io.Writer,
format: Format,
show_docs: bool,
page_allocator: std.mem.Allocator,
@@ -70,8 +70,8 @@ pub fn generate(
try writer.writeAll(header);
}
var buffer = std.ArrayList(u8).init(page_allocator);
defer buffer.deinit();
var stream: std.Io.Writer.Allocating = .init(page_allocator);
defer stream.deinit();
const fields = @typeInfo(KeybindAction).@"union".fields;
inline for (fields) |field| {
@@ -79,10 +79,9 @@ pub fn generate(
// Write previously stored doc comment below all related actions
if (show_docs and @hasDecl(help_strings.KeybindAction, field.name)) {
try writer.writeAll(buffer.items);
try writer.writeAll(stream.written());
try writer.writeAll("\n");
buffer.clearRetainingCapacity();
stream.clearRetainingCapacity();
}
if (show_docs) {
@@ -101,13 +100,13 @@ pub fn generate(
while (iter.next()) |s| {
// If it is the last line and empty, then skip it.
if (iter.peek() == null and s.len == 0) continue;
try format.formatDocLine(&buffer, s);
try format.formatDocLine(&stream.writer, s);
}
}
}
// Write any remaining buffered documentation
if (buffer.items.len > 0) {
try writer.writeAll(buffer.items);
if (stream.written().len > 0) {
try writer.writeAll(stream.written());
}
}