1
1
const std = @import ("std" );
2
+ const Build = std .Build ;
3
+ const LazyPath = Build .LazyPath ;
4
+ const ResolvedTarget = Build .ResolvedTarget ;
5
+
2
6
const TestSuiteConfig = @import ("src/testconfig.zig" ).TestSuiteConfig ;
3
7
4
8
const samples = [_ ][]const u8 {
5
9
"math" ,
6
10
};
7
11
8
- const avr_target = std.zig.CrossTarget {
12
+ const avr_target_query = std.zig.CrossTarget {
9
13
.cpu_arch = .avr ,
10
14
.cpu_model = .{ .explicit = & std .Target .avr .cpu .atmega328p },
11
15
.os_tag = .freestanding ,
@@ -15,7 +19,7 @@ const avr_target = std.zig.CrossTarget{
15
19
// Although this function looks imperative, note that its job is to
16
20
// declaratively construct a build graph that will be executed by an external
17
21
// runner.
18
- pub fn build (b : * std. Build ) ! void {
22
+ pub fn build (b : * Build ) ! void {
19
23
// Targets
20
24
const test_step = b .step ("test" , "Run test suite" );
21
25
const run_step = b .step ("run" , "Run the app" );
@@ -36,17 +40,17 @@ pub fn build(b: *std.Build) !void {
36
40
// Modules
37
41
38
42
const isa_module = b .createModule (.{
39
- .source_file = .{ . path = "src/shared/isa.zig" } ,
43
+ .root_source_file = b . path ( "src/shared/isa.zig" ) ,
40
44
});
41
45
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 = &.{
44
48
.{ .name = "isa" , .module = isa_module },
45
49
},
46
50
});
47
51
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 = &.{
50
54
.{ .name = "autogen-tables" , .module = isa_tables_module },
51
55
.{ .name = "isa" , .module = isa_module },
52
56
},
@@ -55,12 +59,12 @@ pub fn build(b: *std.Build) !void {
55
59
// Main emulator executable
56
60
const aviron_exe = b .addExecutable (.{
57
61
.name = "aviron" ,
58
- .root_source_file = .{ . path = "src/main.zig" } ,
62
+ .root_source_file = b . path ( "src/main.zig" ) ,
59
63
.target = target ,
60
64
.optimize = optimize ,
61
65
});
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 );
64
68
b .installArtifact (aviron_exe );
65
69
66
70
const run_cmd = b .addRunArtifact (aviron_exe );
@@ -70,17 +74,19 @@ pub fn build(b: *std.Build) !void {
70
74
}
71
75
run_step .dependOn (& run_cmd .step );
72
76
77
+ const avr_target = b .resolveTargetQuery (avr_target_query );
78
+
73
79
// Samples
74
80
for (samples ) | sample_name | {
75
81
const sample = b .addExecutable (.{
76
82
.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 })) ,
78
84
.target = avr_target ,
79
85
.optimize = .ReleaseSmall ,
86
+ .strip = false ,
80
87
});
81
88
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" ));
84
90
85
91
// install to the prefix:
86
92
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 {
95
101
}
96
102
97
103
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 ,
102
108
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 ,
105
111
) ! void {
106
112
const unit_tests = b .addTest (.{
107
- .root_source_file = .{ . path = "src/main.zig" } ,
113
+ .root_source_file = b . path ( "src/main.zig" ) ,
108
114
.target = target ,
109
115
.optimize = optimize ,
110
116
});
111
117
test_step .dependOn (& b .addRunArtifact (unit_tests ).step );
112
118
113
119
const testrunner_exe = b .addExecutable (.{
114
120
.name = "aviron-test-runner" ,
115
- .root_source_file = .{ . path = "src/testrunner.zig" } ,
121
+ .root_source_file = b . path ( "src/testrunner.zig" ) ,
116
122
.target = target ,
117
123
.optimize = optimize ,
118
124
});
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 );
121
127
122
128
debug_step .dependOn (& b .addInstallArtifact (testrunner_exe , .{}).step );
123
129
124
130
{
125
- var walkdir = try b .build_root .handle .openIterableDir ("testsuite" , .{});
131
+ var walkdir = try b .build_root .handle .openDir ("testsuite" , .{
132
+ .iterate = true ,
133
+ });
126
134
defer walkdir .close ();
127
135
128
136
var walker = try walkdir .walk (b .allocator );
@@ -162,7 +170,7 @@ fn addTestSuite(
162
170
} else .unknown ;
163
171
164
172
const ConfigAndExe = struct {
165
- binary : std.Build. LazyPath ,
173
+ binary : LazyPath ,
166
174
config : TestSuiteConfig ,
167
175
};
168
176
@@ -177,26 +185,26 @@ fn addTestSuite(
177
185
const config = try parseTestSuiteConfig (b , file );
178
186
179
187
const custom_target = if (config .cpu ) | cpu |
180
- std .zig .CrossTarget .parse (.{
188
+ b . resolveTargetQuery ( std .zig .CrossTarget .parse (.{
181
189
.arch_os_abi = "avr-freestanding-eabi" ,
182
190
.cpu_features = cpu ,
183
- }) catch @panic (cpu )
191
+ }) catch @panic (cpu ))
184
192
else
185
- avr_target ;
193
+ target ;
186
194
187
195
const test_payload = b .addExecutable (.{
188
196
.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 })) ,
190
198
.target = custom_target ,
191
199
.optimize = config .optimize ,
200
+ .strip = false ,
192
201
});
193
202
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" ) ,
198
207
});
199
- test_payload .strip = false ;
200
208
201
209
debug_step .dependOn (& b .addInstallFile (
202
210
test_payload .getEmittedBin (),
@@ -219,7 +227,7 @@ fn addTestSuite(
219
227
} else | _ | @panic (config_path );
220
228
221
229
break :blk ConfigAndExe {
222
- .binary = .{ . path = b .fmt ("testsuite/{s}" , .{entry .path }) } ,
230
+ .binary = b . path ( b .fmt ("testsuite/{s}" , .{entry .path })) ,
223
231
.config = config ,
224
232
};
225
233
},
@@ -242,16 +250,20 @@ fn addTestSuite(
242
250
}
243
251
}
244
252
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 {
247
258
.cwd_relative = path ,
248
259
} else | _ | b .addExecutable (.{
249
260
.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" ),
251
263
}).getEmittedBin ();
252
264
253
265
{
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 });
255
267
defer walkdir .close ();
256
268
257
269
var walker = try walkdir .walk (b .allocator );
@@ -295,11 +307,12 @@ fn addTestSuiteUpdate(b: *std.Build, invoke_step: *std.Build.Step) !void {
295
307
296
308
const config = try parseTestSuiteConfig (b , file );
297
309
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" );
299
311
gcc_invocation .addFileArg (avr_gcc );
300
312
gcc_invocation .addArg ("-o" );
301
313
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!")}));
303
316
for (config .gcc_flags ) | opt | {
304
317
gcc_invocation .addArg (opt );
305
318
}
@@ -321,7 +334,7 @@ fn addTestSuiteUpdate(b: *std.Build, invoke_step: *std.Build.Step) !void {
321
334
}
322
335
}
323
336
324
- fn parseTestSuiteConfig (b : * std. Build , file : std.fs.File ) ! TestSuiteConfig {
337
+ fn parseTestSuiteConfig (b : * Build , file : std.fs.File ) ! TestSuiteConfig {
325
338
var code = std .ArrayList (u8 ).init (b .allocator );
326
339
defer code .deinit ();
327
340
@@ -355,14 +368,14 @@ fn parseTestSuiteConfig(b: *std.Build, file: std.fs.File) !TestSuiteConfig {
355
368
);
356
369
}
357
370
358
- fn generateIsaTables (b : * std. Build , isa_mod : * std. Build.Module ) std.Build. LazyPath {
371
+ fn generateIsaTables (b : * Build , isa_mod : * Build.Module ) LazyPath {
359
372
const generate_tables_exe = b .addExecutable (.{
360
373
.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 ,
363
376
.optimize = .Debug ,
364
377
});
365
- generate_tables_exe .addModule ("isa" , isa_mod );
378
+ generate_tables_exe .root_module . addImport ("isa" , isa_mod );
366
379
367
380
const run = b .addRunArtifact (generate_tables_exe );
368
381
0 commit comments