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

Commit 67a5e42

Browse files
author
Felix Queißner
committed
Fixes invalid target for build. Won't link due to zig linking a libc(???)
1 parent 7b42273 commit 67a5e42

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

build.zig

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn build(b: *Build) !void {
9595

9696
// Test suite:
9797

98-
try addTestSuite(b, test_step, debug_testsuite_step, target, optimize, args_module, aviron_module);
98+
try addTestSuite(b, test_step, debug_testsuite_step, target, avr_target, optimize, args_module, aviron_module);
9999

100100
try addTestSuiteUpdate(b, update_testsuite_step);
101101
}
@@ -104,22 +104,23 @@ fn addTestSuite(
104104
b: *Build,
105105
test_step: *Build.Step,
106106
debug_step: *Build.Step,
107-
target: ResolvedTarget,
107+
host_target: ResolvedTarget,
108+
avr_target: ResolvedTarget,
108109
optimize: std.builtin.OptimizeMode,
109110
args_module: *Build.Module,
110111
aviron_module: *Build.Module,
111112
) !void {
112113
const unit_tests = b.addTest(.{
113114
.root_source_file = b.path("src/main.zig"),
114-
.target = target,
115+
.target = host_target,
115116
.optimize = optimize,
116117
});
117118
test_step.dependOn(&b.addRunArtifact(unit_tests).step);
118119

119120
const testrunner_exe = b.addExecutable(.{
120121
.name = "aviron-test-runner",
121122
.root_source_file = b.path("src/testrunner.zig"),
122-
.target = target,
123+
.target = host_target,
123124
.optimize = optimize,
124125
});
125126
testrunner_exe.root_module.addImport("args", args_module);
@@ -140,6 +141,11 @@ fn addTestSuite(
140141
if (entry.kind != .file)
141142
continue;
142143

144+
if (std.mem.eql(u8, entry.path, "dummy.zig")) {
145+
// This file is not interesting to test.
146+
continue;
147+
}
148+
143149
const FileAction = union(enum) {
144150
compile,
145151
load,
@@ -190,18 +196,33 @@ fn addTestSuite(
190196
.cpu_features = cpu,
191197
}) catch @panic(cpu))
192198
else
193-
target;
199+
avr_target;
200+
201+
const is_zig_test = std.mem.eql(u8, std.fs.path.extension(entry.path), ".zig");
202+
203+
const source_file = b.path(b.fmt("testsuite/{s}", .{entry.path}));
204+
const root_file = if (is_zig_test)
205+
source_file
206+
else
207+
b.path("testsuite/dummy.zig");
194208

195209
const test_payload = b.addExecutable(.{
196210
.name = std.fs.path.stem(entry.basename),
197211
.target = custom_target,
198212
.optimize = config.optimize,
199213
.strip = false,
214+
.root_source_file = root_file,
215+
.link_libc = false,
200216
});
201-
test_payload.addCSourceFile(.{
202-
.file = b.path(b.fmt("testsuite/{s}", .{entry.path})),
203-
.flags = &.{},
204-
});
217+
test_payload.want_lto = false; // AVR has no LTO support!
218+
test_payload.verbose_link = true;
219+
test_payload.verbose_cc = true;
220+
if (!is_zig_test) {
221+
test_payload.addCSourceFile(.{
222+
.file = source_file,
223+
.flags = &.{},
224+
});
225+
}
205226
test_payload.bundle_compiler_rt = false;
206227
test_payload.addIncludePath(b.path("testsuite"));
207228
test_payload.setLinkerScriptPath(b.path("linker.ld"));

src/testrunner.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pub fn main() !u8 {
150150
.cpu = aviron.Cpu{
151151
.trace = cli.options.trace,
152152

153+
.instruction_set = .avr5,
154+
153155
.flash = test_system.flash_storage.memory(),
154156
.sram = test_system.sram.memory(),
155157
.eeprom = test_system.eeprom.memory(),

testsuite/dummy.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//!
2+
//! This file is just a blank file which will be compiled as the application 'root'
3+
//!

0 commit comments

Comments
 (0)