Skip to content

Commit d722b6e

Browse files
author
Felix "xq" Queißner
committed
Update to Zig 0.13.0
1 parent 9f4fb8a commit d722b6e

File tree

6 files changed

+44
-68
lines changed

6 files changed

+44
-68
lines changed

.github/workflows/build.yml

-24
This file was deleted.

.github/workflows/validate.yml

+2-15
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ jobs:
2222
run: |
2323
zig build
2424
25-
- name: Exercise Build options
25+
- name: Compile and run demo
2626
run: |
27-
zig build -Dstatic-rtc=1980-01-01
28-
zig build -Dstatic-rtc=2107-01-01
29-
zig build -Dsector-size=512
30-
zig build -Dsector-size=1024
31-
zig build -Dsector-size=2048
32-
zig build -Dsector-size=4096
33-
zig build -Dsector-size=512:4096
34-
zig build -Dsector-size=1024:4096
35-
zig build -Dsector-size=2048:4096
36-
zig build -Dvolume-count=1
37-
zig build -Dvolume-count=2
38-
zig build -Dvolume-count=10
39-
zig build -Dvolume-names=C
40-
zig build -Dvolume-names=C,D,E,F
27+
zig build install debug

build.zig

+32-19
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub fn build(b: *std.Build) void {
119119
// .max_long_name_len = 121,
120120
.code_page = .us,
121121
.@"volume-count" = @as(u32, 1),
122+
.@"sector-size" = @as(u32, 512),
122123
// .rtc = .dynamic,
123124
.mkfs = true,
124125
.exfat = true,
@@ -130,7 +131,7 @@ pub fn build(b: *std.Build) void {
130131
.name = "mkfs.fat",
131132
.target = b.host,
132133
.optimize = .ReleaseSafe,
133-
.root_source_file = .{ .cwd_relative = build_root ++ "/src/mkfs.fat.zig" },
134+
.root_source_file = b.path("src/mkfs.fat.zig"),
134135
});
135136
mkfs_fat.root_module.addImport("fat", zfat_mod);
136137
mkfs_fat.linkLibC();
@@ -305,8 +306,13 @@ pub const InitializeDiskStep = struct {
305306

306307
const HumanContext = std.BoundedArray(u8, 256);
307308

308-
fn writeDiskImage(b: *std.Build, asking: *std.Build.Step, disk: std.fs.File, base: u64, length: u64, content: Content, context: *HumanContext) !void {
309-
try disk.seekTo(base);
309+
const DiskImage = struct {
310+
path: []const u8,
311+
handle: *std.fs.File,
312+
};
313+
314+
fn writeDiskImage(b: *std.Build, asking: *std.Build.Step, disk: DiskImage, base: u64, length: u64, content: Content, context: *HumanContext) !void {
315+
try disk.handle.seekTo(base);
310316

311317
const context_len = context.len;
312318
defer context.len = context_len;
@@ -396,7 +402,7 @@ pub const InitializeDiskStep = struct {
396402
boot_sector[0x01FE] = 0x55;
397403
boot_sector[0x01FF] = 0xAA;
398404

399-
try disk.writeAll(&boot_sector);
405+
try disk.handle.writeAll(&boot_sector);
400406
}
401407

402408
{
@@ -426,23 +432,23 @@ pub const InitializeDiskStep = struct {
426432
.fs => |fs| {
427433
const maker_exe = fs.executable.?.getPath2(b, asking);
428434

429-
try disk.sync();
435+
try disk.handle.sync();
430436

431-
const disk_image_path = switch (builtin.os.tag) {
432-
.linux => blk: {
433-
const self_pid = std.os.linux.getpid();
434-
break :blk b.fmt("/proc/{}/fd/{}", .{ self_pid, disk.handle });
435-
},
437+
// const disk_image_path = switch (builtin.os.tag) {
438+
// .linux => blk: {
439+
// const self_pid = std.os.linux.getpid();
440+
// break :blk b.fmt("/proc/{}/fd/{}", .{ self_pid, disk.handle });
441+
// },
436442

437-
else => @compileError("TODO: Support this on other OS as well!"),
438-
};
443+
// else => @compileError("TODO: Support this on other OS as well!"),
444+
// };
439445

440446
var argv = std.ArrayList([]const u8).init(b.allocator);
441447
defer argv.deinit();
442448

443449
try argv.appendSlice(&.{
444450
maker_exe, // exe
445-
disk_image_path, // image file
451+
disk.path, // image file
446452
b.fmt("0x{X:0>8}", .{base}), // filesystem offset (bytes)
447453
b.fmt("0x{X:0>8}", .{length}), // filesystem length (bytes)
448454
@tagName(fs.format), // filesystem type
@@ -473,7 +479,7 @@ pub const InitializeDiskStep = struct {
473479
// use shared access to the file:
474480
const stdout = b.run(argv.items);
475481

476-
try disk.sync();
482+
try disk.handle.sync();
477483

478484
_ = stdout;
479485
},
@@ -490,7 +496,7 @@ pub const InitializeDiskStep = struct {
490496
}
491497
}
492498

493-
fn copyFileToImage(disk: std.fs.File, max_length: u64, dir: std.fs.Dir, path: []const u8, context: []const u8) !void {
499+
fn copyFileToImage(disk: DiskImage, max_length: u64, dir: std.fs.Dir, path: []const u8, context: []const u8) !void {
494500
errdefer std.log.err("{s}: failed to copy data to image.", .{context});
495501

496502
var file = try dir.openFile(path, .{});
@@ -510,11 +516,11 @@ pub const InitializeDiskStep = struct {
510516

511517
var pumper = IoPump.init();
512518

513-
try pumper.pump(file.reader(), disk.writer());
519+
try pumper.pump(file.reader(), disk.handle.writer());
514520

515521
const padding = max_length - stat.size;
516522
if (padding > 0) {
517-
try disk.writer().writeByteNTimes(' ', padding);
523+
try disk.handle.writer().writeByteNTimes(' ', padding);
518524
}
519525
}
520526

@@ -549,7 +555,9 @@ pub const InitializeDiskStep = struct {
549555
return;
550556

551557
{
552-
var disk = try std.fs.cwd().createFile(ids.disk_file.path.?, .{});
558+
const disk_path = ids.disk_file.path.?;
559+
560+
var disk = try std.fs.cwd().createFile(disk_path, .{});
553561
defer disk.close();
554562

555563
try disk.seekTo(ids.size - 1);
@@ -559,7 +567,12 @@ pub const InitializeDiskStep = struct {
559567
var context = HumanContext{};
560568
context.appendSliceAssumeCapacity("disk");
561569

562-
try writeDiskImage(b, step, disk, 0, ids.size, ids.content, &context);
570+
const disk_image = DiskImage{
571+
.path = disk_path,
572+
.handle = &disk,
573+
};
574+
575+
try writeDiskImage(b, step, disk_image, 0, ids.size, ids.content, &context);
563576
}
564577

565578
// if (!step.result_cached)

build.zig.zon

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.version = "0.1.0",
44
.dependencies = .{
55
.zfat = .{
6-
.url = "https://github.com/ZigEmbeddedGroup/zfat/archive/34f1c70afe1b04d9b378c373922fe01de342ddcf.tar.gz",
7-
.hash = "1220321b9050e25e4e6d94cb8564009e5f913cf39f26f2c0b358f971175bb1c299b2",
6+
.url = "https://github.com/ZigEmbeddedGroup/zfat/archive/68dbbe19258b174fe4f374a91b4cc939019d9fe7.tar.gz",
7+
.hash = "1220963601b9bc8dacc422d098368567e5c7b84d21f9ae73067fe3eb9c566aea02fd",
88
},
99
},
1010
.paths = .{

src/mkfs.fat.zig

+4-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn format() !void {
4848
}
4949

5050
pub fn mount() !void {
51-
try fatfs.FileSystem.mount(&filesystem, "0:", true);
51+
try filesystem.mount("0:", true);
5252
}
5353

5454
pub fn mkdir(path: []const u8) !void {
@@ -95,11 +95,9 @@ fn disk_initialize(intf: *fatfs.Disk) fatfs.Disk.Error!fatfs.Disk.Status {
9595
fn disk_read(intf: *fatfs.Disk, buff: [*]u8, sector: fatfs.LBA, count: c_uint) fatfs.Disk.Error!void {
9696
_ = intf;
9797

98-
const block_ptr = @as([*][512]u8, @ptrCast(buff));
99-
100-
var i: usize = 0;
101-
while (i < count) : (i += 1) {
102-
block_ptr[i] = App.device.read(sector + i) catch return error.IoError;
98+
const blocks = std.mem.bytesAsSlice(shared.Block, buff[0 .. count * shared.BlockDevice.block_size]);
99+
for (blocks, 0..) |*block, i| {
100+
block.* = App.device.read(sector + i) catch return error.IoError;
103101
}
104102
}
105103

src/shared.zig

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ pub fn App(comptime Context: type) type {
4646
if (command_list.len == 0)
4747
return mistake("no commands.", .{});
4848

49-
var image_file = try std.fs.cwd().openFile(image_file_path, .{ .mode = .read_write });
49+
var image_file = try std.fs.cwd().openFile(image_file_path, .{
50+
.mode = .read_write,
51+
});
5052
defer image_file.close();
5153

5254
const stat = try image_file.stat();
@@ -200,7 +202,7 @@ const Command = enum {
200202
dir,
201203
};
202204

203-
pub const Block = [512]u8;
205+
pub const Block = [BlockDevice.block_size]u8;
204206

205207
pub const BlockDevice = struct {
206208
pub const block_size = 512;

0 commit comments

Comments
 (0)