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

Commit 130bc0e

Browse files
author
Felix "xq" Queißner
committed
Update to zig 0.14.0
1 parent 67a5e42 commit 130bc0e

File tree

6 files changed

+48
-30
lines changed

6 files changed

+48
-30
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4
14+
1415
- name: Setup Zig
1516
uses: mlugg/setup-zig@v1
1617
with:
17-
version: 0.13.0
18+
version: 0.14.0
19+
1820
- name: Build
1921
run: zig build install
22+
2023
- name: Test Suite
2124
run: zig build test

build.zig

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const samples = [_][]const u8{
99
"math",
1010
};
1111

12-
const avr_target_query = std.zig.CrossTarget{
12+
const avr_target_query = std.Target.Query{
1313
.cpu_arch = .avr,
1414
.cpu_model = .{ .explicit = &std.Target.avr.cpu.atmega328p },
1515
.os_tag = .freestanding,
@@ -86,7 +86,7 @@ pub fn build(b: *Build) !void {
8686
.strip = false,
8787
});
8888
sample.bundle_compiler_rt = false;
89-
sample.setLinkerScriptPath(b.path("linker.ld"));
89+
sample.setLinkerScript(b.path("linker.ld"));
9090

9191
// install to the prefix:
9292
const install_elf_sample = b.addInstallFile(sample.getEmittedBin(), b.fmt("samples/{s}.elf", .{sample_name}));
@@ -191,14 +191,19 @@ fn addTestSuite(
191191
const config = try parseTestSuiteConfig(b, file);
192192

193193
const custom_target = if (config.cpu) |cpu|
194-
b.resolveTargetQuery(std.zig.CrossTarget.parse(.{
194+
b.resolveTargetQuery(std.Target.Query.parse(.{
195195
.arch_os_abi = "avr-freestanding-eabi",
196196
.cpu_features = cpu,
197197
}) catch @panic(cpu))
198198
else
199199
avr_target;
200200

201-
const is_zig_test = std.mem.eql(u8, std.fs.path.extension(entry.path), ".zig");
201+
const file_ext = std.fs.path.extension(entry.path);
202+
const is_zig_test = std.mem.eql(u8, file_ext, ".zig");
203+
const is_c_test = std.mem.eql(u8, file_ext, ".c");
204+
const is_asm_test = std.mem.eql(u8, file_ext, ".S");
205+
206+
std.debug.assert(is_zig_test or is_c_test or is_asm_test);
202207

203208
const source_file = b.path(b.fmt("testsuite/{s}", .{entry.path}));
204209
const root_file = if (is_zig_test)
@@ -211,24 +216,33 @@ fn addTestSuite(
211216
.target = custom_target,
212217
.optimize = config.optimize,
213218
.strip = false,
214-
.root_source_file = root_file,
219+
.root_source_file = if (is_zig_test) root_file else null,
215220
.link_libc = false,
216221
});
217222
test_payload.want_lto = false; // AVR has no LTO support!
218223
test_payload.verbose_link = true;
219224
test_payload.verbose_cc = true;
220-
if (!is_zig_test) {
225+
test_payload.bundle_compiler_rt = false;
226+
227+
test_payload.setLinkerScript(b.path("linker.ld"));
228+
229+
if (is_c_test or is_asm_test) {
230+
test_payload.addIncludePath(b.path("testsuite"));
231+
}
232+
if (is_c_test) {
221233
test_payload.addCSourceFile(.{
222234
.file = source_file,
223235
.flags = &.{},
224236
});
225237
}
226-
test_payload.bundle_compiler_rt = false;
227-
test_payload.addIncludePath(b.path("testsuite"));
228-
test_payload.setLinkerScriptPath(b.path("linker.ld"));
229-
test_payload.root_module.addAnonymousImport("testsuite", .{
230-
.root_source_file = b.path("src/libtestsuite/lib.zig"),
231-
});
238+
if (is_asm_test) {
239+
test_payload.addAssemblyFile(source_file);
240+
}
241+
if (is_zig_test) {
242+
test_payload.root_module.addAnonymousImport("testsuite", .{
243+
.root_source_file = b.path("src/libtestsuite/lib.zig"),
244+
});
245+
}
232246

233247
debug_step.dependOn(&b.addInstallFile(
234248
test_payload.getEmittedBin(),
@@ -261,7 +275,7 @@ fn addTestSuite(
261275

262276
const test_run = b.addRunArtifact(testrunner_exe);
263277
test_run.addArg("--config");
264-
test_run.addFileArg(write_file.files.items[0].getPath());
278+
test_run.addFileArg(write_file.getDirectory().path(b, "config.json"));
265279
test_run.addArg("--name");
266280
test_run.addArg(entry.path);
267281

@@ -282,7 +296,7 @@ fn addTestSuiteUpdate(
282296
.cwd_relative = path,
283297
} else |_| b.addExecutable(.{
284298
.name = "no-avr-gcc",
285-
.target = b.host,
299+
.target = b.graph.host,
286300
.root_source_file = b.path("tools/no-avr-gcc.zig"),
287301
}).getEmittedBin();
288302

@@ -347,7 +361,7 @@ fn addTestSuiteUpdate(
347361
const write_file = b.addWriteFile("config.json", config.toString(b));
348362

349363
const copy_file = b.addSystemCommand(&.{"cp"}); // todo make this cross-platform!
350-
copy_file.addFileArg(write_file.files.items[0].getPath());
364+
copy_file.addFileArg(write_file.getDirectory().path(b, "config.json"));
351365
copy_file.addArg(b.fmt("testsuite/{s}/{s}.elf.json", .{ std.fs.path.dirname(entry.path).?, std.fs.path.stem(entry.basename) }));
352366

353367
invoke_step.dependOn(&gcc_invocation.step);
@@ -396,7 +410,7 @@ fn generateIsaTables(b: *Build, isa_mod: *Build.Module) LazyPath {
396410
const generate_tables_exe = b.addExecutable(.{
397411
.name = "aviron-generate-tables",
398412
.root_source_file = b.path("tools/generate-tables.zig"),
399-
.target = b.host,
413+
.target = b.graph.host,
400414
.optimize = .Debug,
401415
});
402416
generate_tables_exe.root_module.addImport("isa", isa_mod);

build.zig.zon

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.{
2-
.name = "aviron",
2+
.name = .aviron,
33
.version = "0.1.0",
4+
.fingerprint = 0x5dcc57b3c9d31477,
45
.dependencies = .{
56
.args = .{
6-
.url = "git+https://github.com/MasterQ32/zig-args#c5f79a133c1eeab38298493c2f4a2b4bd9a9c791",
7-
.hash = "1220904d2fdcd970dd0d216211d092eb3ef6da01117163cc9393ab845a1d66c029d9",
7+
.url = "git+https://github.com/MasterQ32/zig-args#9425b94c103a031777fdd272c555ce93a7dea581",
8+
.hash = "args-0.0.0-CiLiqv_NAAC97fGpk9hS2K681jkiqPsWP6w3ucb_ctGH",
89
},
910
},
1011
.paths = .{

src/lib/Cpu.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const std = @import("std");
22
const isa = @import("decoder.zig");
3-
const io = @import("io.zig");
3+
const io_mod = @import("io.zig");
44

5-
const Flash = io.Flash;
6-
const RAM = io.RAM;
7-
const EEPROM = io.EEPROM;
8-
const IO = io.IO;
5+
const Flash = io_mod.Flash;
6+
const RAM = io_mod.RAM;
7+
const EEPROM = io_mod.EEPROM;
8+
const IO = io_mod.IO;
99

1010
const Cpu = @This();
1111

@@ -1673,7 +1673,7 @@ fn formatInstruction(inst: isa.Instruction, fmt: []const u8, opt: std.fmt.Format
16731673
inline else => |args| {
16741674
const T = @TypeOf(args);
16751675
if (T != void) {
1676-
const info = @typeInfo(T).Struct;
1676+
const info = @typeInfo(T).@"struct";
16771677

16781678
inline for (info.fields, 0..) |fld, i| {
16791679
if (i > 0) {

src/lib/decoder.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn decode(inst_val: u16) !Instruction {
5252

5353
const Dst = @TypeOf(@field(result, name));
5454
@field(result, name) = switch (@typeInfo(Dst)) {
55-
.Enum => @enumFromInt(raw),
55+
.@"enum" => @enumFromInt(raw),
5656
else => raw,
5757
};
5858
}

tools/generate-tables.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const isa_def = @embedFile("isa.txt");
33
const isa = @import("isa");
44

55
fn stringToEnum(comptime T: type, str: []const u8) ?T {
6-
inline for (@typeInfo(T).Enum.fields) |enumField| {
6+
inline for (@typeInfo(T).@"enum".fields) |enumField| {
77
if (std.mem.eql(u8, str, enumField.name)) {
88
return @field(T, enumField.name);
99
}
@@ -39,9 +39,9 @@ pub fn main() !void {
3939
map.deinit(allocator);
4040
};
4141

42-
var lit = std.mem.split(u8, isa_def, "\n");
42+
var lit = std.mem.splitScalar(u8, isa_def, '\n');
4343
while (lit.next()) |line| {
44-
var pit = std.mem.tokenize(u8, line, " ");
44+
var pit = std.mem.tokenizeScalar(u8, line, ' ');
4545

4646
const op_name = pit.next() orelse continue;
4747
const opcode = stringToEnum(isa.Opcode, op_name) orelse @panic(op_name);

0 commit comments

Comments
 (0)