@@ -9,8 +9,10 @@ const ArrayList = std.ArrayList;
9
9
const File = std .fs .File ;
10
10
const Step = std .Build .Step ;
11
11
const Watch = std .Build .Watch ;
12
+ const Fuzz = std .Build .Fuzz ;
12
13
const Allocator = std .mem .Allocator ;
13
- const fatal = std .zig .fatal ;
14
+ const fatal = std .process .fatal ;
15
+ const runner = @This ();
14
16
15
17
pub const root = @import ("@build" );
16
18
pub const dependencies = @import ("@dependencies" );
@@ -102,6 +104,7 @@ pub fn main() !void {
102
104
var steps_menu = false ;
103
105
var output_tmp_nonce : ? [16 ]u8 = null ;
104
106
var watch = false ;
107
+ var fuzz = false ;
105
108
var debounce_interval_ms : u16 = 50 ;
106
109
107
110
while (nextArg (args , & arg_idx )) | arg | {
@@ -205,6 +208,8 @@ pub fn main() !void {
205
208
try debug_log_scopes .append (next_arg );
206
209
} else if (mem .eql (u8 , arg , "--debug-pkg-config" )) {
207
210
builder .debug_pkg_config = true ;
211
+ } else if (mem .eql (u8 , arg , "--debug-rt" )) {
212
+ graph .debug_compiler_runtime_libs = true ;
208
213
} else if (mem .eql (u8 , arg , "--debug-compile-errors" )) {
209
214
builder .debug_compile_errors = true ;
210
215
} else if (mem .eql (u8 , arg , "--system" )) {
@@ -234,6 +239,8 @@ pub fn main() !void {
234
239
prominent_compile_errors = true ;
235
240
} else if (mem .eql (u8 , arg , "--watch" )) {
236
241
watch = true ;
242
+ } else if (mem .eql (u8 , arg , "--fuzz" )) {
243
+ fuzz = true ;
237
244
} else if (mem .eql (u8 , arg , "-fincremental" )) {
238
245
graph .incremental = true ;
239
246
} else if (mem .eql (u8 , arg , "-fno-incremental" )) {
@@ -353,6 +360,7 @@ pub fn main() !void {
353
360
.max_rss_mutex = .{},
354
361
.skip_oom_steps = skip_oom_steps ,
355
362
.watch = watch ,
363
+ .fuzz = fuzz ,
356
364
.memory_blocked_steps = std .ArrayList (* Step ).init (arena ),
357
365
.step_stack = .{},
358
366
.prominent_compile_errors = prominent_compile_errors ,
@@ -394,6 +402,10 @@ pub fn main() !void {
394
402
},
395
403
else = > return err ,
396
404
};
405
+ if (fuzz ) {
406
+ Fuzz .start (& run .thread_pool , run .step_stack .keys (), run .ttyconf , main_progress_node );
407
+ }
408
+
397
409
if (! watch ) return cleanExit ();
398
410
399
411
switch (builtin .os .tag ) {
@@ -457,6 +469,7 @@ const Run = struct {
457
469
max_rss_mutex : std.Thread.Mutex ,
458
470
skip_oom_steps : bool ,
459
471
watch : bool ,
472
+ fuzz : bool ,
460
473
memory_blocked_steps : std .ArrayList (* Step ),
461
474
step_stack : std .AutoArrayHashMapUnmanaged (* Step , void ),
462
475
prominent_compile_errors : bool ,
@@ -466,6 +479,11 @@ const Run = struct {
466
479
summary : Summary ,
467
480
ttyconf : std.io.tty.Config ,
468
481
stderr : File ,
482
+
483
+ fn cleanExit (run : Run ) void {
484
+ if (run .watch or run .fuzz ) return ;
485
+ return runner .cleanExit ();
486
+ }
469
487
};
470
488
471
489
fn prepare (
@@ -614,8 +632,7 @@ fn runStepNames(
614
632
else = > false ,
615
633
};
616
634
if (failure_count == 0 and failures_only ) {
617
- if (! run .watch ) cleanExit ();
618
- return ;
635
+ return run .cleanExit ();
619
636
}
620
637
621
638
const ttyconf = run .ttyconf ;
@@ -672,8 +689,7 @@ fn runStepNames(
672
689
}
673
690
674
691
if (failure_count == 0 ) {
675
- if (! run .watch ) cleanExit ();
676
- return ;
692
+ return run .cleanExit ();
677
693
}
678
694
679
695
// Finally, render compile errors at the bottom of the terminal.
@@ -1058,7 +1074,8 @@ fn workerMakeOneStep(
1058
1074
std .debug .lockStdErr ();
1059
1075
defer std .debug .unlockStdErr ();
1060
1076
1061
- printErrorMessages (b , s , run ) catch {};
1077
+ const gpa = b .allocator ;
1078
+ printErrorMessages (gpa , s , run .ttyconf , run .stderr , run .prominent_compile_errors ) catch {};
1062
1079
}
1063
1080
1064
1081
handle_result : {
@@ -1111,11 +1128,13 @@ fn workerMakeOneStep(
1111
1128
}
1112
1129
}
1113
1130
1114
- fn printErrorMessages (b : * std.Build , failing_step : * Step , run : * const Run ) ! void {
1115
- const gpa = b .allocator ;
1116
- const stderr = run .stderr ;
1117
- const ttyconf = run .ttyconf ;
1118
-
1131
+ pub fn printErrorMessages (
1132
+ gpa : Allocator ,
1133
+ failing_step : * Step ,
1134
+ ttyconf : std.io.tty.Config ,
1135
+ stderr : File ,
1136
+ prominent_compile_errors : bool ,
1137
+ ) ! void {
1119
1138
// Provide context for where these error messages are coming from by
1120
1139
// printing the corresponding Step subtree.
1121
1140
@@ -1152,7 +1171,7 @@ fn printErrorMessages(b: *std.Build, failing_step: *Step, run: *const Run) !void
1152
1171
}
1153
1172
}
1154
1173
1155
- if (! run . prominent_compile_errors and failing_step .result_error_bundle .errorMessageCount () > 0 )
1174
+ if (! prominent_compile_errors and failing_step .result_error_bundle .errorMessageCount () > 0 )
1156
1175
try failing_step .result_error_bundle .renderToWriter (renderOptions (ttyconf ), stderr .writer ());
1157
1176
1158
1177
for (failing_step .result_error_msgs .items ) | msg | {
@@ -1226,6 +1245,7 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
1226
1245
\\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss
1227
1246
\\ --fetch Exit after fetching dependency tree
1228
1247
\\ --watch Continuously rebuild when source files are modified
1248
+ \\ --fuzz Continuously search for unit test failures
1229
1249
\\ --debounce <ms> Delay before rebuilding after changed file detected
1230
1250
\\ -fincremental Enable incremental compilation
1231
1251
\\ -fno-incremental Disable incremental compilation
@@ -1294,6 +1314,7 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
1294
1314
\\ --seed [integer] For shuffling dependency traversal order (default: random)
1295
1315
\\ --debug-log [scope] Enable debugging the compiler
1296
1316
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered
1317
+ \\ --debug-rt Debug compiler runtime libraries
1297
1318
\\ --verbose-link Enable compiler debug output for linking
1298
1319
\\ --verbose-air Enable compiler debug output for Zig AIR
1299
1320
\\ --verbose-llvm-ir[=file] Enable compiler debug output for LLVM IR
0 commit comments