Skip to content

Commit cb295b8

Browse files
committed
Zig 0.15: zig build test
1 parent 3770f97 commit cb295b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1268
-1148
lines changed

build.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ pub fn build(b: *std.Build) !void {
276276
.omit_frame_pointer = false,
277277
.unwind_tables = .sync,
278278
}),
279+
// Crash on x86_64 without this
280+
.use_llvm = true,
279281
});
280282
if (config.emit_test_exe) b.installArtifact(test_exe);
281283
_ = try deps.add(test_exe);
@@ -285,7 +287,7 @@ pub fn build(b: *std.Build) !void {
285287
test_step.dependOn(&test_run.step);
286288

287289
// Normal tests always test our libghostty modules
288-
test_step.dependOn(test_lib_vt_step);
290+
//test_step.dependOn(test_lib_vt_step);
289291

290292
// Valgrind test running
291293
const valgrind_run = b.addSystemCommand(&.{

src/Command.zig

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ fn startPosix(self: *Command, arena: Allocator) !void {
194194
// child process so there isn't much we can do. We try to output
195195
// something reasonable. Its important to note we MUST NOT return
196196
// any other error condition from here on out.
197-
const stderr = std.io.getStdErr().writer();
197+
var stderr_buf: [1024]u8 = undefined;
198+
var stderr_writer = std.fs.File.stderr().writer(&stderr_buf);
199+
const stderr = &stderr_writer.interface;
198200
switch (err) {
199201
error.FileNotFound => stderr.print(
200202
\\Requested executable not found. Please verify the command is on
@@ -211,6 +213,7 @@ fn startPosix(self: *Command, arena: Allocator) !void {
211213
.{err},
212214
) catch {},
213215
}
216+
stderr.flush() catch {};
214217

215218
// We return a very specific error that can be detected to determine
216219
// we're in the child.
@@ -464,34 +467,35 @@ fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const EnvMap) ![]u1
464467

465468
/// Copied from Zig. This function could be made public in child_process.zig instead.
466469
fn windowsCreateCommandLine(allocator: mem.Allocator, argv: []const []const u8) ![:0]u8 {
467-
var buf = std.ArrayList(u8).init(allocator);
470+
var buf: std.Io.Writer.Allocating = .init(allocator);
468471
defer buf.deinit();
472+
const writer = &buf.writer;
469473

470474
for (argv, 0..) |arg, arg_i| {
471-
if (arg_i != 0) try buf.append(' ');
475+
if (arg_i != 0) try writer.writeByte(' ');
472476
if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {
473-
try buf.appendSlice(arg);
477+
try writer.writeAll(arg);
474478
continue;
475479
}
476-
try buf.append('"');
480+
try writer.writeByte('"');
477481
var backslash_count: usize = 0;
478482
for (arg) |byte| {
479483
switch (byte) {
480484
'\\' => backslash_count += 1,
481485
'"' => {
482-
try buf.appendNTimes('\\', backslash_count * 2 + 1);
483-
try buf.append('"');
486+
try writer.splatByteAll('\\', backslash_count * 2 + 1);
487+
try writer.writeByte('"');
484488
backslash_count = 0;
485489
},
486490
else => {
487-
try buf.appendNTimes('\\', backslash_count);
488-
try buf.append(byte);
491+
try writer.splatByteAll('\\', backslash_count);
492+
try writer.writeByte(byte);
489493
backslash_count = 0;
490494
},
491495
}
492496
}
493-
try buf.appendNTimes('\\', backslash_count * 2);
494-
try buf.append('"');
497+
try writer.splatByteAll('\\', backslash_count * 2);
498+
try writer.writeByte('"');
495499
}
496500

497501
return buf.toOwnedSliceSentinel(0);

src/apprt/gtk/build/blueprint.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn main() !void {
4545
std.debug.print(
4646
\\`libadwaita` is too old.
4747
\\
48-
\\Ghostty requires a version {} or newer of `libadwaita` to
48+
\\Ghostty requires a version {f} or newer of `libadwaita` to
4949
\\compile this blueprint. Please install it, ensure that it is
5050
\\available on your PATH, and then retry building Ghostty.
5151
, .{required_adwaita_version});
@@ -80,7 +80,7 @@ pub fn main() !void {
8080
std.debug.print(
8181
\\`blueprint-compiler` not found.
8282
\\
83-
\\Ghostty requires version {} or newer of
83+
\\Ghostty requires version {f} or newer of
8484
\\`blueprint-compiler` as a build-time dependency starting
8585
\\from version 1.2. Please install it, ensure that it is
8686
\\available on your PATH, and then retry building Ghostty.
@@ -104,7 +104,7 @@ pub fn main() !void {
104104
std.debug.print(
105105
\\`blueprint-compiler` is the wrong version.
106106
\\
107-
\\Ghostty requires version {} or newer of
107+
\\Ghostty requires version {f} or newer of
108108
\\`blueprint-compiler` as a build-time dependency starting
109109
\\from version 1.2. Please install it, ensure that it is
110110
\\available on your PATH, and then retry building Ghostty.
@@ -145,7 +145,7 @@ pub fn main() !void {
145145
std.debug.print(
146146
\\`blueprint-compiler` not found.
147147
\\
148-
\\Ghostty requires version {} or newer of
148+
\\Ghostty requires version {f} or newer of
149149
\\`blueprint-compiler` as a build-time dependency starting
150150
\\from version 1.2. Please install it, ensure that it is
151151
\\available on your PATH, and then retry building Ghostty.

src/apprt/gtk/build/gresource.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ pub fn main() !void {
142142
);
143143
}
144144

145-
const writer = std.io.getStdOut().writer();
145+
var buf: [4096]u8 = undefined;
146+
var stdout = std.fs.File.stdout().writer(&buf);
147+
const writer = &stdout.interface;
146148
try writer.writeAll(
147149
\\<?xml version="1.0" encoding="UTF-8"?>
148150
\\<gresources>
@@ -157,6 +159,8 @@ pub fn main() !void {
157159
\\</gresources>
158160
\\
159161
);
162+
163+
try stdout.end();
160164
}
161165

162166
/// Generate the icon resources. This works by looking up all the icons

src/apprt/gtk/class/config.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,18 @@ pub const Config = extern struct {
117117
errdefer text_buf.unref();
118118

119119
var buf: [4095:0]u8 = undefined;
120-
var fbs = std.io.fixedBufferStream(&buf);
120+
var writer: std.Io.Writer = .fixed(&buf);
121121
for (config._diagnostics.items()) |diag| {
122-
fbs.reset();
123-
diag.write(fbs.writer()) catch |err| {
122+
writer.end = 0;
123+
diag.format(&writer) catch |err| {
124124
log.warn(
125125
"error writing diagnostic to buffer err={}",
126126
.{err},
127127
);
128128
continue;
129129
};
130130

131-
text_buf.insertAtCursor(&buf, @intCast(fbs.pos));
131+
text_buf.insertAtCursor(&buf, @intCast(writer.end));
132132
text_buf.insertAtCursor("\n", 1);
133133
}
134134

src/apprt/gtk/ipc/DBus.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ payload_builder: *glib.VariantBuilder,
2929
parameters_builder: *glib.VariantBuilder,
3030

3131
/// Initialize the helper.
32-
pub fn init(alloc: Allocator, target: apprt.ipc.Target, action: [:0]const u8) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!Self {
32+
pub fn init(alloc: Allocator, target: apprt.ipc.Target, action: [:0]const u8) (Allocator.Error || std.Io.Writer.Error || apprt.ipc.Errors)!Self {
33+
var buf: [256]u8 = undefined;
34+
var stderr_writer = std.fs.File.stderr().writer(&buf);
35+
const stderr = &stderr_writer.interface;
3336

3437
// Get the appropriate bus name and object path for contacting the
3538
// Ghostty instance we're interested in.
3639
const bus_name: [:0]const u8, const object_path: [:0]const u8 = switch (target) {
3740
.class => |class| result: {
3841
// Force the usage of the class specified on the CLI to determine the
3942
// bus name and object path.
40-
const object_path = try std.fmt.allocPrintZ(alloc, "/{s}", .{class});
43+
const object_path = try std.fmt.allocPrintSentinel(alloc, "/{s}", .{class}, 0);
4144

4245
std.mem.replaceScalar(u8, object_path, '.', '/');
4346
std.mem.replaceScalar(u8, object_path, '-', '_');
@@ -54,14 +57,14 @@ pub fn init(alloc: Allocator, target: apprt.ipc.Target, action: [:0]const u8) (A
5457
}
5558

5659
if (gio.Application.idIsValid(bus_name.ptr) == 0) {
57-
const stderr = std.io.getStdErr().writer();
5860
try stderr.print("D-Bus bus name is not valid: {s}\n", .{bus_name});
61+
try stderr.flush();
5962
return error.IPCFailed;
6063
}
6164

6265
if (glib.Variant.isObjectPath(object_path.ptr) == 0) {
63-
const stderr = std.io.getStdErr().writer();
6466
try stderr.print("D-Bus object path is not valid: {s}\n", .{object_path});
67+
try stderr.flush();
6568
return error.IPCFailed;
6669
}
6770

@@ -72,17 +75,17 @@ pub fn init(alloc: Allocator, target: apprt.ipc.Target, action: [:0]const u8) (A
7275

7376
const dbus_ = gio.busGetSync(.session, null, &err_);
7477
if (err_) |err| {
75-
const stderr = std.io.getStdErr().writer();
7678
try stderr.print(
7779
"Unable to establish connection to D-Bus session bus: {s}\n",
7880
.{err.f_message orelse "(unknown)"},
7981
);
82+
try stderr.flush();
8083
return error.IPCFailed;
8184
}
8285

8386
break :dbus dbus_ orelse {
84-
const stderr = std.io.getStdErr().writer();
8587
try stderr.print("gio.busGetSync returned null\n", .{});
88+
try stderr.flush();
8689
return error.IPCFailed;
8790
};
8891
};
@@ -128,7 +131,11 @@ pub fn addParameter(self: *Self, variant: *glib.Variant) void {
128131

129132
/// Send the IPC to the remote Ghostty. Once it completes, nothing further
130133
/// should be done with this object other than call `deinit`.
131-
pub fn send(self: *Self) (std.posix.WriteError || apprt.ipc.Errors)!void {
134+
pub fn send(self: *Self) (std.Io.Writer.Error || apprt.ipc.Errors)!void {
135+
var buf: [256]u8 = undefined;
136+
var stderr_writer = std.fs.File.stderr().writer(&buf);
137+
const stderr = &stderr_writer.interface;
138+
132139
// finish building the parameters
133140
const parameters = self.parameters_builder.end();
134141

@@ -167,11 +174,11 @@ pub fn send(self: *Self) (std.posix.WriteError || apprt.ipc.Errors)!void {
167174
defer if (result_) |result| result.unref();
168175

169176
if (err_) |err| {
170-
const stderr = std.io.getStdErr().writer();
171177
try stderr.print(
172178
"D-Bus method call returned an error err={s}\n",
173179
.{err.f_message orelse "(unknown)"},
174180
);
181+
try stderr.flush();
175182
return error.IPCFailed;
176183
}
177184
}

src/apprt/gtk/ipc/new_window.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const DBus = @import("DBus.zig");
2020
// ```
2121
// gdbus call --session --dest com.mitchellh.ghostty --object-path /com/mitchellh/ghostty --method org.gtk.Actions.Activate new-window-command '[<@as ["echo" "hello"]>]' []
2222
// ```
23-
pub fn newWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ipc.Action.NewWindow) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!bool {
23+
pub fn newWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ipc.Action.NewWindow) (Allocator.Error || std.Io.Writer.Error || apprt.ipc.Errors)!bool {
2424
var dbus = try DBus.init(
2525
alloc,
2626
target,

src/benchmark/CodepointWidth.zig

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const assert = std.debug.assert;
1010
const Allocator = std.mem.Allocator;
1111
const Benchmark = @import("Benchmark.zig");
1212
const options = @import("options.zig");
13-
const uucode = @import("uucode");
1413
const UTF8Decoder = @import("../terminal/UTF8Decoder.zig");
1514
const simd = @import("../simd/main.zig");
1615
const table = @import("../unicode/main.zig").table;
@@ -48,9 +47,6 @@ pub const Mode = enum {
4847

4948
/// Test our lookup table implementation.
5049
table,
51-
52-
/// Using uucode, with custom `width` extension based on `wcwidth`.
53-
uucode,
5450
};
5551

5652
/// Create a new terminal stream handler for the given arguments.
@@ -75,7 +71,6 @@ pub fn benchmark(self: *CodepointWidth) Benchmark {
7571
.wcwidth => stepWcwidth,
7672
.table => stepTable,
7773
.simd => stepSimd,
78-
.uucode => stepUucode,
7974
},
8075
.setupFn = setup,
8176
.teardownFn = teardown,
@@ -112,12 +107,15 @@ fn stepWcwidth(ptr: *anyopaque) Benchmark.Error!void {
112107
const self: *CodepointWidth = @ptrCast(@alignCast(ptr));
113108

114109
const f = self.data_f orelse return;
115-
var r = std.io.bufferedReader(f.reader());
110+
var read_buf: [4096]u8 = undefined;
111+
var f_reader = f.reader(&read_buf);
112+
var r = &f_reader.interface;
113+
116114
var d: UTF8Decoder = .{};
117115
var buf: [4096]u8 align(std.atomic.cache_line) = undefined;
118116
while (true) {
119-
const n = r.read(&buf) catch |err| {
120-
log.warn("error reading data file err={}", .{err});
117+
const n = r.readSliceShort(&buf) catch {
118+
log.warn("error reading data file err={?}", .{f_reader.err});
121119
return error.BenchmarkFailed;
122120
};
123121
if (n == 0) break; // EOF reached
@@ -136,12 +134,15 @@ fn stepTable(ptr: *anyopaque) Benchmark.Error!void {
136134
const self: *CodepointWidth = @ptrCast(@alignCast(ptr));
137135

138136
const f = self.data_f orelse return;
139-
var r = std.io.bufferedReader(f.reader());
137+
var read_buf: [4096]u8 = undefined;
138+
var f_reader = f.reader(&read_buf);
139+
var r = &f_reader.interface;
140+
140141
var d: UTF8Decoder = .{};
141142
var buf: [4096]u8 align(std.atomic.cache_line) = undefined;
142143
while (true) {
143-
const n = r.read(&buf) catch |err| {
144-
log.warn("error reading data file err={}", .{err});
144+
const n = r.readSliceShort(&buf) catch {
145+
log.warn("error reading data file err={?}", .{f_reader.err});
145146
return error.BenchmarkFailed;
146147
};
147148
if (n == 0) break; // EOF reached
@@ -165,36 +166,15 @@ fn stepSimd(ptr: *anyopaque) Benchmark.Error!void {
165166
const self: *CodepointWidth = @ptrCast(@alignCast(ptr));
166167

167168
const f = self.data_f orelse return;
168-
var r = std.io.bufferedReader(f.reader());
169-
var d: UTF8Decoder = .{};
170-
var buf: [4096]u8 align(std.atomic.cache_line) = undefined;
171-
while (true) {
172-
const n = r.read(&buf) catch |err| {
173-
log.warn("error reading data file err={}", .{err});
174-
return error.BenchmarkFailed;
175-
};
176-
if (n == 0) break; // EOF reached
177-
178-
for (buf[0..n]) |c| {
179-
const cp_, const consumed = d.next(c);
180-
assert(consumed);
181-
if (cp_) |cp| {
182-
std.mem.doNotOptimizeAway(simd.codepointWidth(cp));
183-
}
184-
}
185-
}
186-
}
187-
188-
fn stepUucode(ptr: *anyopaque) Benchmark.Error!void {
189-
const self: *CodepointWidth = @ptrCast(@alignCast(ptr));
169+
var read_buf: [4096]u8 = undefined;
170+
var f_reader = f.reader(&read_buf);
171+
var r = &f_reader.interface;
190172

191-
const f = self.data_f orelse return;
192-
var r = std.io.bufferedReader(f.reader());
193173
var d: UTF8Decoder = .{};
194174
var buf: [4096]u8 align(std.atomic.cache_line) = undefined;
195175
while (true) {
196-
const n = r.read(&buf) catch |err| {
197-
log.warn("error reading data file err={}", .{err});
176+
const n = r.readSliceShort(&buf) catch {
177+
log.warn("error reading data file err={?}", .{f_reader.err});
198178
return error.BenchmarkFailed;
199179
};
200180
if (n == 0) break; // EOF reached
@@ -203,12 +183,7 @@ fn stepUucode(ptr: *anyopaque) Benchmark.Error!void {
203183
const cp_, const consumed = d.next(c);
204184
assert(consumed);
205185
if (cp_) |cp| {
206-
// This is the same trick we do in terminal.zig so we
207-
// keep it here.
208-
std.mem.doNotOptimizeAway(if (cp <= 0xFF)
209-
1
210-
else
211-
uucode.get(.width, @intCast(cp)));
186+
std.mem.doNotOptimizeAway(simd.codepointWidth(cp));
212187
}
213188
}
214189
}

0 commit comments

Comments
 (0)