Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 551b5cb

Browse files
committed
catch up to lastest zig release
1 parent 6f1b3e9 commit 551b5cb

File tree

7 files changed

+90
-63
lines changed

7 files changed

+90
-63
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
matrix:
1010
os: [ubuntu-latest, windows-latest, macos-latest]
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: goto-bus-stop/setup-zig@v1.3.0
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Setup Zig
15+
uses: mlugg/setup-zig@v1
1416
with:
15-
version: 0.11.0
16-
17+
version: 0.13.0
1718
- name: Build
1819
run: zig build install
19-
2020
- name: Test Suite
2121
run: zig build test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
zig-*
1+
zig-out
2+
.zig-cache

build.zig

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const std = @import("std");
2+
const Build = std.Build;
3+
const LazyPath = Build.LazyPath;
4+
const ResolvedTarget = Build.ResolvedTarget;
5+
26
const TestSuiteConfig = @import("src/testconfig.zig").TestSuiteConfig;
37

48
const samples = [_][]const u8{
59
"math",
610
};
711

8-
const avr_target = std.zig.CrossTarget{
12+
const avr_target_query = std.zig.CrossTarget{
913
.cpu_arch = .avr,
1014
.cpu_model = .{ .explicit = &std.Target.avr.cpu.atmega328p },
1115
.os_tag = .freestanding,
@@ -15,7 +19,7 @@ const avr_target = std.zig.CrossTarget{
1519
// Although this function looks imperative, note that its job is to
1620
// declaratively construct a build graph that will be executed by an external
1721
// runner.
18-
pub fn build(b: *std.Build) !void {
22+
pub fn build(b: *Build) !void {
1923
// Targets
2024
const test_step = b.step("test", "Run test suite");
2125
const run_step = b.step("run", "Run the app");
@@ -36,17 +40,17 @@ pub fn build(b: *std.Build) !void {
3640
// Modules
3741

3842
const isa_module = b.createModule(.{
39-
.source_file = .{ .path = "src/shared/isa.zig" },
43+
.root_source_file = b.path("src/shared/isa.zig"),
4044
});
4145
const isa_tables_module = b.createModule(.{
42-
.source_file = generateIsaTables(b, isa_module),
43-
.dependencies = &.{
46+
.root_source_file = generateIsaTables(b, isa_module),
47+
.imports = &.{
4448
.{ .name = "isa", .module = isa_module },
4549
},
4650
});
4751
const aviron_module = b.addModule("aviron", .{
48-
.source_file = .{ .path = "src/lib/aviron.zig" },
49-
.dependencies = &.{
52+
.root_source_file = b.path("src/lib/aviron.zig"),
53+
.imports = &.{
5054
.{ .name = "autogen-tables", .module = isa_tables_module },
5155
.{ .name = "isa", .module = isa_module },
5256
},
@@ -55,12 +59,12 @@ pub fn build(b: *std.Build) !void {
5559
// Main emulator executable
5660
const aviron_exe = b.addExecutable(.{
5761
.name = "aviron",
58-
.root_source_file = .{ .path = "src/main.zig" },
62+
.root_source_file = b.path("src/main.zig"),
5963
.target = target,
6064
.optimize = optimize,
6165
});
62-
aviron_exe.addModule("args", args_module);
63-
aviron_exe.addModule("aviron", aviron_module);
66+
aviron_exe.root_module.addImport("args", args_module);
67+
aviron_exe.root_module.addImport("aviron", aviron_module);
6468
b.installArtifact(aviron_exe);
6569

6670
const run_cmd = b.addRunArtifact(aviron_exe);
@@ -70,17 +74,19 @@ pub fn build(b: *std.Build) !void {
7074
}
7175
run_step.dependOn(&run_cmd.step);
7276

77+
const avr_target = b.resolveTargetQuery(avr_target_query);
78+
7379
// Samples
7480
for (samples) |sample_name| {
7581
const sample = b.addExecutable(.{
7682
.name = sample_name,
77-
.root_source_file = .{ .path = b.fmt("samples/{s}.zig", .{sample_name}) },
83+
.root_source_file = b.path(b.fmt("samples/{s}.zig", .{sample_name})),
7884
.target = avr_target,
7985
.optimize = .ReleaseSmall,
86+
.strip = false,
8087
});
8188
sample.bundle_compiler_rt = false;
82-
sample.setLinkerScriptPath(std.build.FileSource{ .path = "linker.ld" });
83-
sample.strip = false;
89+
sample.setLinkerScriptPath(b.path("linker.ld"));
8490

8591
// install to the prefix:
8692
const install_elf_sample = b.addInstallFile(sample.getEmittedBin(), b.fmt("samples/{s}.elf", .{sample_name}));
@@ -95,34 +101,36 @@ pub fn build(b: *std.Build) !void {
95101
}
96102

97103
fn addTestSuite(
98-
b: *std.Build,
99-
test_step: *std.Build.Step,
100-
debug_step: *std.Build.Step,
101-
target: std.zig.CrossTarget,
104+
b: *Build,
105+
test_step: *Build.Step,
106+
debug_step: *Build.Step,
107+
target: ResolvedTarget,
102108
optimize: std.builtin.OptimizeMode,
103-
args_module: *std.build.Module,
104-
aviron_module: *std.build.Module,
109+
args_module: *Build.Module,
110+
aviron_module: *Build.Module,
105111
) !void {
106112
const unit_tests = b.addTest(.{
107-
.root_source_file = .{ .path = "src/main.zig" },
113+
.root_source_file = b.path("src/main.zig"),
108114
.target = target,
109115
.optimize = optimize,
110116
});
111117
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
112118

113119
const testrunner_exe = b.addExecutable(.{
114120
.name = "aviron-test-runner",
115-
.root_source_file = .{ .path = "src/testrunner.zig" },
121+
.root_source_file = b.path("src/testrunner.zig"),
116122
.target = target,
117123
.optimize = optimize,
118124
});
119-
testrunner_exe.addModule("args", args_module);
120-
testrunner_exe.addModule("aviron", aviron_module);
125+
testrunner_exe.root_module.addImport("args", args_module);
126+
testrunner_exe.root_module.addImport("aviron", aviron_module);
121127

122128
debug_step.dependOn(&b.addInstallArtifact(testrunner_exe, .{}).step);
123129

124130
{
125-
var walkdir = try b.build_root.handle.openIterableDir("testsuite", .{});
131+
var walkdir = try b.build_root.handle.openDir("testsuite", .{
132+
.iterate = true,
133+
});
126134
defer walkdir.close();
127135

128136
var walker = try walkdir.walk(b.allocator);
@@ -162,7 +170,7 @@ fn addTestSuite(
162170
} else .unknown;
163171

164172
const ConfigAndExe = struct {
165-
binary: std.Build.LazyPath,
173+
binary: LazyPath,
166174
config: TestSuiteConfig,
167175
};
168176

@@ -177,26 +185,26 @@ fn addTestSuite(
177185
const config = try parseTestSuiteConfig(b, file);
178186

179187
const custom_target = if (config.cpu) |cpu|
180-
std.zig.CrossTarget.parse(.{
188+
b.resolveTargetQuery(std.zig.CrossTarget.parse(.{
181189
.arch_os_abi = "avr-freestanding-eabi",
182190
.cpu_features = cpu,
183-
}) catch @panic(cpu)
191+
}) catch @panic(cpu))
184192
else
185-
avr_target;
193+
target;
186194

187195
const test_payload = b.addExecutable(.{
188196
.name = std.fs.path.stem(entry.basename),
189-
.root_source_file = .{ .path = b.fmt("testsuite/{s}", .{entry.path}) },
197+
.root_source_file = b.path(b.fmt("testsuite/{s}", .{entry.path})),
190198
.target = custom_target,
191199
.optimize = config.optimize,
200+
.strip = false,
192201
});
193202
test_payload.bundle_compiler_rt = false;
194-
test_payload.addIncludePath(.{ .path = "testsuite" });
195-
test_payload.setLinkerScriptPath(std.build.FileSource{ .path = "linker.ld" });
196-
test_payload.addAnonymousModule("testsuite", .{
197-
.source_file = .{ .path = "src/libtestsuite/lib.zig" },
203+
test_payload.addIncludePath(b.path("testsuite"));
204+
test_payload.setLinkerScriptPath(b.path("linker.ld"));
205+
test_payload.root_module.addAnonymousImport("testsuite", .{
206+
.root_source_file = b.path("src/libtestsuite/lib.zig"),
198207
});
199-
test_payload.strip = false;
200208

201209
debug_step.dependOn(&b.addInstallFile(
202210
test_payload.getEmittedBin(),
@@ -219,7 +227,7 @@ fn addTestSuite(
219227
} else |_| @panic(config_path);
220228

221229
break :blk ConfigAndExe{
222-
.binary = .{ .path = b.fmt("testsuite/{s}", .{entry.path}) },
230+
.binary = b.path(b.fmt("testsuite/{s}", .{entry.path})),
223231
.config = config,
224232
};
225233
},
@@ -242,16 +250,20 @@ fn addTestSuite(
242250
}
243251
}
244252

245-
fn addTestSuiteUpdate(b: *std.Build, invoke_step: *std.Build.Step) !void {
246-
const avr_gcc = if (b.findProgram(&.{"avr-gcc"}, &.{})) |path| std.build.LazyPath{
253+
fn addTestSuiteUpdate(
254+
b: *Build,
255+
invoke_step: *Build.Step,
256+
) !void {
257+
const avr_gcc = if (b.findProgram(&.{"avr-gcc"}, &.{})) |path| LazyPath{
247258
.cwd_relative = path,
248259
} else |_| b.addExecutable(.{
249260
.name = "no-avr-gcc",
250-
.root_source_file = .{ .path = "tools/no-avr-gcc.zig" },
261+
.target = b.host,
262+
.root_source_file = b.path("tools/no-avr-gcc.zig"),
251263
}).getEmittedBin();
252264

253265
{
254-
var walkdir = try b.build_root.handle.openIterableDir("testsuite.avr-gcc", .{});
266+
var walkdir = try b.build_root.handle.openDir("testsuite.avr-gcc", .{ .iterate = true });
255267
defer walkdir.close();
256268

257269
var walker = try walkdir.walk(b.allocator);
@@ -295,11 +307,12 @@ fn addTestSuiteUpdate(b: *std.Build, invoke_step: *std.Build.Step) !void {
295307

296308
const config = try parseTestSuiteConfig(b, file);
297309

298-
const gcc_invocation = std.Build.Step.Run.create(b, "run avr-gcc");
310+
const gcc_invocation = Build.Step.Run.create(b, "run avr-gcc");
299311
gcc_invocation.addFileArg(avr_gcc);
300312
gcc_invocation.addArg("-o");
301313
gcc_invocation.addArg(b.fmt("testsuite/{s}/{s}.elf", .{ std.fs.path.dirname(entry.path).?, std.fs.path.stem(entry.basename) }));
302-
gcc_invocation.addArg(b.fmt("-mmcu={s}", .{config.cpu orelse avr_target.cpu_model.explicit.llvm_name orelse @panic("Unknown MCU!")}));
314+
gcc_invocation.addArg(b.fmt("-mmcu={s}", .{config.cpu orelse @panic("Uknown MCU!")}));
315+
//avr_target.cpu_model.explicit.llvm_name orelse @panic("Unknown MCU!")}));
303316
for (config.gcc_flags) |opt| {
304317
gcc_invocation.addArg(opt);
305318
}
@@ -321,7 +334,7 @@ fn addTestSuiteUpdate(b: *std.Build, invoke_step: *std.Build.Step) !void {
321334
}
322335
}
323336

324-
fn parseTestSuiteConfig(b: *std.Build, file: std.fs.File) !TestSuiteConfig {
337+
fn parseTestSuiteConfig(b: *Build, file: std.fs.File) !TestSuiteConfig {
325338
var code = std.ArrayList(u8).init(b.allocator);
326339
defer code.deinit();
327340

@@ -355,14 +368,14 @@ fn parseTestSuiteConfig(b: *std.Build, file: std.fs.File) !TestSuiteConfig {
355368
);
356369
}
357370

358-
fn generateIsaTables(b: *std.Build, isa_mod: *std.Build.Module) std.Build.LazyPath {
371+
fn generateIsaTables(b: *Build, isa_mod: *Build.Module) LazyPath {
359372
const generate_tables_exe = b.addExecutable(.{
360373
.name = "aviron-generate-tables",
361-
.root_source_file = .{ .path = "tools/generate-tables.zig" },
362-
.target = .{},
374+
.root_source_file = b.path("tools/generate-tables.zig"),
375+
.target = b.host,
363376
.optimize = .Debug,
364377
});
365-
generate_tables_exe.addModule("isa", isa_mod);
378+
generate_tables_exe.root_module.addImport("isa", isa_mod);
366379

367380
const run = b.addRunArtifact(generate_tables_exe);
368381

build.zig.zon

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33
.version = "0.1.0",
44
.dependencies = .{
55
.args = .{
6-
.url = "https://github.com/MasterQ32/zig-args/archive/bb2eced8ddf28114b3a1ff761c2d80b90b1a61e2.tar.gz",
7-
.hash = "12208556082c280af264ca2a174fd04fc7a35f865bfe59e2c61f4a977bf7a65063e4",
6+
.url = "git+https://github.com/MasterQ32/zig-args#c5f79a133c1eeab38298493c2f4a2b4bd9a9c791",
7+
.hash = "1220904d2fdcd970dd0d216211d092eb3ef6da01117163cc9393ab845a1d66c029d9",
88
},
99
},
10+
.paths = .{
11+
"README.md",
12+
"build.zig",
13+
"build.zig.zon",
14+
"doc",
15+
"linker.ld",
16+
"samples",
17+
"shell.nix",
18+
"src",
19+
"testsuite",
20+
"testsuite.avr-gcc",
21+
"tools",
22+
},
1023
}

samples/math.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub export fn _start() callconv(.C) noreturn {
44
var a: usize = 1 + 2;
55

66
for (0..10) |p| {
7-
var k = p;
7+
const k = p;
88
std.mem.doNotOptimizeAway(k);
99
a += k;
1010
}

src/main.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ const IO = struct {
227227
const io: *IO = @ptrCast(@alignCast(ctx.?));
228228
const reg: Register = @enumFromInt(addr);
229229
switch (reg) {
230-
.exit => std.os.exit(value & mask),
230+
.exit => std.process.exit(value & mask),
231231
.stdio => std.io.getStdOut().writer().writeByte(value & mask) catch @panic("i/o failure"),
232232
.stderr => std.io.getStdErr().writer().writeByte(value & mask) catch @panic("i/o failure"),
233233

@@ -259,16 +259,16 @@ const IO = struct {
259259
fn lobyte(val: *u16) *u8 {
260260
const bits: *[2]u8 = @ptrCast(val);
261261
return switch (comptime builtin.cpu.arch.endian()) {
262-
.Big => return &bits[1],
263-
.Little => return &bits[0],
262+
.big => return &bits[1],
263+
.little => return &bits[0],
264264
};
265265
}
266266

267267
fn hibyte(val: *u16) *u8 {
268268
const bits: *[2]u8 = @ptrCast(val);
269269
return switch (comptime builtin.cpu.arch.endian()) {
270-
.Big => return &bits[0],
271-
.Little => return &bits[1],
270+
.big => return &bits[0],
271+
.little => return &bits[1],
272272
};
273273
}
274274

tools/generate-tables.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn main() !void {
6060
'0' => {},
6161
'1' => base_number_bit_set.set(index),
6262
else => {
63-
var gop = try positionals.getPtr(opcode).getOrPut(allocator, r);
63+
const gop = try positionals.getPtr(opcode).getOrPut(allocator, r);
6464
if (!gop.found_existing) {
6565
gop.value_ptr.* = try std.BoundedArray(u8, 16).init(0);
6666
}
@@ -144,7 +144,7 @@ pub fn main() !void {
144144
try writer.writeAll("pub const lookup = [65536]isa.Opcode {");
145145

146146
for (lut, 0..) |v, i| {
147-
try writer.print(".{s},", .{std.zig.fmtId(@tagName(v))});
147+
try writer.print(".{},", .{std.zig.fmtId(@tagName(v))});
148148
if ((i + 1) % 16 == 0) {
149149
try writer.print("\n", .{});
150150
}
@@ -180,7 +180,7 @@ pub fn main() !void {
180180

181181
try writer.writeAll("};");
182182

183-
var txt = try buf.toOwnedSliceSentinel(0);
183+
const txt = try buf.toOwnedSliceSentinel(0);
184184
defer allocator.free(txt);
185185

186186
var tree = try std.zig.Ast.parse(allocator, txt, .zig);

0 commit comments

Comments
 (0)