Skip to content

Commit 0235548

Browse files
committed
fixup compile errors after rebase
1 parent 1d667b1 commit 0235548

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/BuildInterface.zig

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn createDisk(dimmer: Interface, size: u64, content: Content) std.Build.Lazy
2626

2727
const write_files = b.addWriteFiles();
2828

29-
const script_source, const variables = renderContent(write_files, b.allocator, content);
29+
const script_source, const variables = renderContent(write_files, b.allocator, content, dimmer.builder.graph.io);
3030

3131
const script_file = write_files.add("image.dis", script_source);
3232

@@ -69,6 +69,7 @@ fn renderContent(
6969
wfs: *std.Build.Step.WriteFile,
7070
allocator: std.mem.Allocator,
7171
content: Content,
72+
io: std.Io,
7273
) struct { []const u8, ContentWriter.VariableMap } {
7374
var code: std.Io.Writer.Allocating = .init(allocator);
7475
defer code.deinit();
@@ -81,7 +82,7 @@ fn renderContent(
8182
.vars = &variables,
8283
};
8384

84-
cw.render(content) catch @panic("out of memory");
85+
cw.render(content, io) catch @panic("out of memory");
8586

8687
const source = std.mem.trim(
8788
u8,
@@ -109,7 +110,7 @@ const ContentWriter = struct {
109110
code: *std.Io.Writer,
110111
vars: *VariableMap,
111112

112-
fn render(cw: ContentWriter, content: Content) !void {
113+
fn render(cw: ContentWriter, content: Content, io: std.Io) !void {
113114
// Always insert some padding before and after:
114115
try cw.code.writeAll(" ");
115116
errdefer cw.code.writeAll(" ") catch {};
@@ -124,15 +125,15 @@ const ContentWriter = struct {
124125
},
125126

126127
.paste_file => |data| {
127-
try cw.code.print("paste-file {f}", .{cw.fmtLazyPath(data, .file)});
128+
try cw.code.print("paste-file {f}", .{cw.fmtLazyPath(data, .file, io)});
128129
},
129130

130131
.mbr_part_table => |data| {
131132
try cw.code.writeAll("mbr-part\n");
132133

133134
if (data.bootloader) |loader| {
134135
try cw.code.writeAll(" bootloader ");
135-
try cw.render(loader.*);
136+
try cw.render(loader.*, io);
136137
try cw.code.writeAll("\n");
137138
}
138139

@@ -153,7 +154,7 @@ const ContentWriter = struct {
153154
try cw.code.print(" size {d}\n", .{size});
154155
}
155156
try cw.code.writeAll(" contains");
156-
try cw.render(part.data);
157+
try cw.render(part.data, io);
157158
try cw.code.writeAll("\n");
158159
try cw.code.writeAll(" endpart\n");
159160
} else {
@@ -195,7 +196,7 @@ const ContentWriter = struct {
195196
try cw.code.print(" size {d}\n", .{size});
196197
}
197198
try cw.code.writeAll(" contains");
198-
try cw.render(part.data);
199+
try cw.render(part.data, io);
199200
try cw.code.writeAll("\n");
200201
try cw.code.writeAll(" endpart\n");
201202
}
@@ -213,14 +214,14 @@ const ContentWriter = struct {
213214
});
214215
}
215216

216-
try cw.renderFileSystemTree(data.tree);
217+
try cw.renderFileSystemTree(data.tree, io);
217218

218219
try cw.code.writeAll("endfat\n");
219220
},
220221
}
221222
}
222223

223-
fn renderFileSystemTree(cw: ContentWriter, fs: FileSystem) !void {
224+
fn renderFileSystemTree(cw: ContentWriter, fs: FileSystem, io: std.Io) !void {
224225
for (fs.items) |item| {
225226
switch (item) {
226227
.empty_dir => |dir| try cw.code.print("mkdir {f}\n", .{
@@ -229,16 +230,16 @@ const ContentWriter = struct {
229230

230231
.copy_dir => |copy| try cw.code.print("copy-dir {f} {f}\n", .{
231232
fmtPath(copy.destination),
232-
cw.fmtLazyPath(copy.source, .directory),
233+
cw.fmtLazyPath(copy.source, .directory, io),
233234
}),
234235

235236
.copy_file => |copy| try cw.code.print("copy-file {f} {f}\n", .{
236237
fmtPath(copy.destination),
237-
cw.fmtLazyPath(copy.source, .file),
238+
cw.fmtLazyPath(copy.source, .file, io),
238239
}),
239240

240241
.include_script => |script| try cw.code.print("!include {f}\n", .{
241-
cw.fmtLazyPath(script, .file),
242+
cw.fmtLazyPath(script, .file, io),
242243
}),
243244
}
244245
}
@@ -285,7 +286,7 @@ const ContentWriter = struct {
285286
}
286287
};
287288
const LazyPathFormatter = std.fmt.Alt(
288-
struct { ContentWriter, std.Build.LazyPath, UsageHint },
289+
struct { ContentWriter, std.Build.LazyPath, UsageHint, std.Io },
289290
formatLazyPath,
290291
);
291292
const UsageHint = enum { file, directory };
@@ -294,19 +295,20 @@ const ContentWriter = struct {
294295
cw: ContentWriter,
295296
path: std.Build.LazyPath,
296297
hint: UsageHint,
298+
io: std.Io,
297299
) LazyPathFormatter {
298-
return .{ .data = .{ cw, path, hint } };
300+
return .{ .data = .{ cw, path, hint, io } };
299301
}
300302

301303
fn fmtPath(path: []const u8) PathFormatter {
302304
return .{ .path = path };
303305
}
304306

305307
fn formatLazyPath(
306-
data: struct { ContentWriter, std.Build.LazyPath, UsageHint },
308+
data: struct { ContentWriter, std.Build.LazyPath, UsageHint, std.Io },
307309
writer: *std.Io.Writer,
308310
) std.Io.Writer.Error!void {
309-
const cw, const path, const hint = data;
311+
const cw, const path, const hint, const io = data;
310312

311313
switch (path) {
312314
.cwd_relative,
@@ -319,12 +321,12 @@ const ContentWriter = struct {
319321
const rel_path = path.getPath2(cw.wfs.step.owner, &cw.wfs.step);
320322

321323
const full_path = if (!std.fs.path.isAbsolute(rel_path))
322-
std.fs.cwd().realpathAlloc(cw.wfs.step.owner.allocator, rel_path) catch @panic("oom")
324+
std.Io.Dir.cwd().realPathFileAlloc(io, rel_path, cw.wfs.step.owner.allocator) catch @panic("oom")
323325
else
324326
rel_path;
325327

326328
if (!std.fs.path.isAbsolute(full_path)) {
327-
const cwd = std.fs.cwd().realpathAlloc(cw.wfs.step.owner.allocator, ".") catch @panic("oom");
329+
const cwd = std.Io.Dir.cwd().realPathFileAlloc(io, ".", cw.wfs.step.owner.allocator) catch @panic("oom");
328330
std.debug.print("non-absolute path detected for {t}: cwd=\"{f}\" path=\"{f}\"\n", .{
329331
path,
330332
std.zig.fmtString(cwd),

src/components/FillData.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn parse(ctx: dim.Context, stdio: std.Io) !dim.Content {
2020
}
2121

2222
fn render(self: *FillData, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
23-
var writer = stream.writer(io);
23+
var writer = stream.writer(io, &.{});
2424
writer.interface.splatByteAll(
2525
self.fill_value,
2626
stream.length,

src/components/fs/FatFileSystem.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ const AtomicOps = struct {
242242
defer fs_file.close();
243243

244244
var fs_file_buffer: [1024]u8 = undefined;
245-
var adapter = fs_file.writer(io, &fs_file_buffer);
245+
var adapter = fs_file.writer( &fs_file_buffer);
246246

247-
_ = try reader.streamRemaining(&adapter.writer);
247+
_ = try reader.streamRemaining(&adapter.interface);
248248

249-
try adapter.writer.flush();
249+
try adapter.interface.flush();
250250
}
251251
};
252252

src/dim.zig

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const VariableMap = std.StringArrayHashMapUnmanaged([]const u8);
6363

6464
var global_deps_file: ?std.Io.File = null;
6565
var global_deps_buffer: []u8 = undefined;
66-
var global_deps_file_writer: std.fs.File.Writer = undefined;
66+
var global_deps_file_writer: std.Io.File.Writer = undefined;
6767
var global_deps_writer: *std.Io.Writer = undefined;
6868

6969
pub fn main(init: std.process.Init) !u8 {
@@ -453,7 +453,7 @@ const Environment = struct {
453453
///
454454
///
455455
pub const Content = struct {
456-
pub const RenderError = FileName.OpenError || std.Io.Reader.Error || BinaryStream.WriteError || error{
456+
pub const RenderError = FileName.OpenError || std.Io.Reader.Error || std.Io.Writer.Error || BinaryStream.WriteError || error{
457457
ConfigurationError,
458458
OutOfBounds,
459459
OutOfMemory,
@@ -511,7 +511,7 @@ pub const FileName = struct {
511511
const file = name.root_dir.openFile(stdio, name.rel_path, .{}) catch |err| switch (err) {
512512
error.FileNotFound => {
513513
var buffer: [std.fs.max_path_bytes]u8 = undefined;
514-
name.env.report_error("failed to open \"{f}/{f}\": not found", .{
514+
name.env.report_error("failed to open \"{f}\": not found", .{
515515
std.zig.fmtString(if (name.root_dir.realPath(stdio, &buffer)) |l| buffer[0..l] else |e| @errorName(e)),
516516
}) catch |e| std.debug.assert(e == error.OutOfMemory);
517517
return error.FileNotFound;
@@ -641,9 +641,9 @@ pub const FileName = struct {
641641
var file_reader = handle.file.reader(io, &.{});
642642

643643
var buffer: [8192]u8 = undefined;
644-
var writer = stream.writer(io).adaptToNewApi(&buffer);
644+
var writer = stream.writer(io,&buffer);
645645

646-
_ = try file_reader.interface.streamRemaining(&writer.new_interface);
646+
_ = try file_reader.interface.streamRemaining(&writer.interface);
647647
}
648648
};
649649

@@ -655,7 +655,7 @@ pub const FileHandle = struct {
655655
fd.* = undefined;
656656
}
657657

658-
pub fn reader(fd: FileHandle, io: std.Io, buffer: []u8) std.fs.File.Reader {
658+
pub fn reader(fd: FileHandle, io: std.Io, buffer: []u8) std.Io.File.Reader {
659659
return fd.file.reader(io, buffer);
660660
}
661661
};
@@ -723,7 +723,7 @@ pub const BinaryStream = struct {
723723
switch (bs.backing) {
724724
.buffer => |ptr| @memcpy(data, ptr[@intCast(offset)..][0..data.len]),
725725
.file => |state| {
726-
const len = state.file.pread(data, state.base + offset) catch return error.IoError;
726+
const len = state.file.readPositionalAll(io, data, state.base + offset) catch return error.IoError;
727727
if (len != data.len)
728728
return error.Overflow;
729729
},
@@ -738,9 +738,7 @@ pub const BinaryStream = struct {
738738
switch (bs.backing) {
739739
.buffer => |ptr| @memcpy(ptr[@intCast(offset)..][0..data.len], data),
740740
.file => |state| {
741-
const len = state.file.pwrite(data, state.base + offset) catch return error.IoError;
742-
if (len != data.len)
743-
return error.Overflow;
741+
state.file.writePositionalAll(io,data, state.base + offset) catch return error.IoError;
744742
},
745743
}
746744
}
@@ -751,13 +749,13 @@ pub const BinaryStream = struct {
751749
bs.virtual_offset = offset;
752750
}
753751

754-
pub fn writer(bs: *BinaryStream, stdio: std.Io) Writer {
752+
pub fn writer(bs: *BinaryStream, stdio: std.Io, buffer: []u8) Writer {
755753
return .{
756754
.interface = .{
757755
.vtable = &.{
758756
.drain = Writer.drain,
759757
},
760-
.buffer = &.{},
758+
.buffer = buffer,
761759
},
762760
.stream = bs,
763761
.stdio = stdio,

0 commit comments

Comments
 (0)