@@ -24,14 +24,15 @@ pub fn build(b: *std.Build) !void {
24
24
const AFLplusplus_inc_path = AFLplusplus_dep .path ("include/" );
25
25
26
26
// Common flags
27
- var flags = std .BoundedArray ([]const u8 , 16 ){};
28
- flags .appendSliceAssumeCapacity (& EXE_FLAGS );
29
- flags .appendSliceAssumeCapacity (&.{ lib_path_flag , bin_path_flag });
27
+ var flag_buffer : [16 ][]const u8 = undefined ;
28
+ var flags : std .ArrayList ([]const u8 ) = .initBuffer (& flag_buffer );
29
+ try flags .appendSliceBounded (& EXE_FLAGS );
30
+ try flags .appendSliceBounded (&.{ lib_path_flag , bin_path_flag });
30
31
if (target .result .cpu .arch .isX86 ()) {
31
- flags .appendSliceAssumeCapacity (&.{ "-mavx2" , "-D_HAVE_AVX2" });
32
+ try flags .appendSliceBounded (&.{ "-mavx2" , "-D_HAVE_AVX2" });
32
33
}
33
34
if (target .query .isNative ()) {
34
- flags .appendAssumeCapacity ("-march=native" );
35
+ try flags .appendBounded ("-march=native" );
35
36
}
36
37
37
38
// Common objects
@@ -45,7 +46,7 @@ pub fn build(b: *std.Build) !void {
45
46
});
46
47
performance_obj .addCSourceFile (.{
47
48
.file = AFLplusplus_src_path .path (b , "afl-performance.c" ),
48
- .flags = flags .constSlice () ,
49
+ .flags = flags .items ,
49
50
});
50
51
performance_obj .addIncludePath (AFLplusplus_inc_path );
51
52
performance_obj .linkLibC ();
@@ -60,7 +61,7 @@ pub fn build(b: *std.Build) !void {
60
61
});
61
62
forkserver_obj .addCSourceFile (.{
62
63
.file = AFLplusplus_src_path .path (b , "afl-forkserver.c" ),
63
- .flags = flags .constSlice () ,
64
+ .flags = flags .items ,
64
65
});
65
66
forkserver_obj .addIncludePath (AFLplusplus_inc_path );
66
67
forkserver_obj .linkLibC ();
@@ -76,7 +77,7 @@ pub fn build(b: *std.Build) !void {
76
77
77
78
sharedmem_obj .addCSourceFile (.{
78
79
.file = AFLplusplus_src_path .path (b , "afl-sharedmem.c" ),
79
- .flags = flags .constSlice () ,
80
+ .flags = flags .items ,
80
81
});
81
82
82
83
sharedmem_obj .addIncludePath (AFLplusplus_inc_path );
@@ -92,7 +93,7 @@ pub fn build(b: *std.Build) !void {
92
93
});
93
94
common_obj .addCSourceFile (.{
94
95
.file = AFLplusplus_src_path .path (b , "afl-common.c" ),
95
- .flags = flags .constSlice () ,
96
+ .flags = flags .items ,
96
97
});
97
98
common_obj .addIncludePath (AFLplusplus_inc_path );
98
99
common_obj .linkLibC ();
@@ -124,7 +125,7 @@ pub fn build(b: *std.Build) !void {
124
125
fuzz_exe .addCSourceFiles (.{
125
126
.root = AFLplusplus_src_path ,
126
127
.files = & EXE_FUZZ_SOURCES ,
127
- .flags = flags .constSlice () ,
128
+ .flags = flags .items ,
128
129
});
129
130
if (use_z ) {
130
131
fuzz_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -152,7 +153,7 @@ pub fn build(b: *std.Build) !void {
152
153
showmap_exe .addCSourceFiles (.{
153
154
.root = AFLplusplus_src_path ,
154
155
.files = &.{ "afl-showmap.c" , "afl-fuzz-mutators.c" , "afl-fuzz-python.c" },
155
- .flags = flags .constSlice () ,
156
+ .flags = flags .items ,
156
157
});
157
158
158
159
if (use_z ) {
@@ -181,7 +182,7 @@ pub fn build(b: *std.Build) !void {
181
182
});
182
183
tmin_exe .addCSourceFile (.{
183
184
.file = AFLplusplus_src_path .path (b , "afl-tmin.c" ),
184
- .flags = flags .constSlice () ,
185
+ .flags = flags .items ,
185
186
});
186
187
187
188
if (use_z ) {
@@ -210,7 +211,7 @@ pub fn build(b: *std.Build) !void {
210
211
});
211
212
analyze_exe .addCSourceFile (.{
212
213
.file = AFLplusplus_src_path .path (b , "afl-analyze.c" ),
213
- .flags = flags .constSlice () ,
214
+ .flags = flags .items ,
214
215
});
215
216
if (use_z ) {
216
217
analyze_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -237,7 +238,7 @@ pub fn build(b: *std.Build) !void {
237
238
});
238
239
gotcpu_exe .addCSourceFile (.{
239
240
.file = AFLplusplus_src_path .path (b , "afl-gotcpu.c" ),
240
- .flags = flags .constSlice () ,
241
+ .flags = flags .items ,
241
242
});
242
243
if (use_z ) {
243
244
gotcpu_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -261,7 +262,7 @@ pub fn build(b: *std.Build) !void {
261
262
});
262
263
as_exe .addCSourceFile (.{
263
264
.file = AFLplusplus_src_path .path (b , "afl-as.c" ),
264
- .flags = flags .constSlice () ,
265
+ .flags = flags .items ,
265
266
});
266
267
if (use_z ) {
267
268
as_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -460,16 +461,17 @@ fn setupLLVMTooling(
460
461
};
461
462
462
463
// LLVM instrumentation C flags
463
- var llvm_c_flags = std .BoundedArray ([]const u8 , 32 ){};
464
- llvm_c_flags .appendSliceAssumeCapacity (& LLVM_EXE_C_FLAGS );
464
+ var llvm_c_flags_buffer : [32 ][]const u8 = undefined ;
465
+ var llvm_c_flags : std .ArrayList ([]const u8 ) = .initBuffer (& llvm_c_flags_buffer );
466
+ try llvm_c_flags .appendSliceBounded (& LLVM_EXE_C_FLAGS );
465
467
const llvm_version = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--version" }), "\n " );
466
468
var llvm_version_iter = std .mem .tokenizeScalar (u8 , llvm_version , '.' );
467
469
const llvm_major = try std .fmt .parseUnsigned (u8 , llvm_version_iter .next ().? , 10 );
468
470
const llvm_minor = try std .fmt .parseUnsigned (u8 , llvm_version_iter .next ().? , 10 );
469
471
const llvm_bin_dir = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--bindir" }), "\n " );
470
472
const llvm_lib_dir = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--libdir" }), "\n " );
471
473
const llvm_lib_path = std.Build.LazyPath { .cwd_relative = llvm_lib_dir };
472
- llvm_c_flags .appendSliceAssumeCapacity (&.{
474
+ try llvm_c_flags .appendSliceBounded (&.{
473
475
lib_path_flag ,
474
476
bin_path_flag ,
475
477
b .fmt ("-DLLVM_MAJOR={}" , .{llvm_major }),
@@ -481,31 +483,32 @@ fn setupLLVMTooling(
481
483
b .fmt ("-DCLANGPP_BIN=\" {s}/clang++\" " , .{llvm_bin_dir }),
482
484
});
483
485
if (enable_lto ) {
484
- llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\" -flto\" " );
486
+ try llvm_c_flags .appendBounded ("-DAFL_CLANG_FLTO=\" -flto\" " );
485
487
} else {
486
- llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\"\" " );
488
+ try llvm_c_flags .appendBounded ("-DAFL_CLANG_FLTO=\"\" " );
487
489
}
488
490
if (target .query .isNative ()) {
489
- llvm_c_flags .appendAssumeCapacity ("-march=native" );
491
+ try llvm_c_flags .appendBounded ("-march=native" );
490
492
}
491
493
492
494
// LLVM instrumentation C++ flags
493
- var llvm_cpp_flags = std .BoundedArray ([]const u8 , 64 ){};
494
- llvm_cpp_flags .appendSliceAssumeCapacity (llvm_c_flags .constSlice ());
495
- llvm_cpp_flags .appendSliceAssumeCapacity (& LLVM_EXE_CPP_FLAGS );
496
- llvm_cpp_flags .appendSliceAssumeCapacity (&.{
495
+ var llvm_cpp_flags_buf : [64 ][]const u8 = undefined ;
496
+ var llvm_cpp_flags : std .ArrayList ([]const u8 ) = .initBuffer (& llvm_cpp_flags_buf );
497
+ try llvm_cpp_flags .appendSliceBounded (llvm_c_flags .items );
498
+ try llvm_cpp_flags .appendSliceBounded (& LLVM_EXE_CPP_FLAGS );
499
+ try llvm_cpp_flags .appendSliceBounded (&.{
497
500
b .fmt ("-std={s}" , .{if (llvm_major < 10 ) "gnu++11" else if (llvm_major < 16 ) "c++14" else "c++17" }),
498
501
});
499
502
if (enable_wafl and target .result .cpu .arch .isWasm ()) {
500
- llvm_cpp_flags .appendSliceAssumeCapacity (&.{ "-DNDEBUG" , "-DNO_TLS" });
503
+ try llvm_cpp_flags .appendSliceBounded (&.{ "-DNDEBUG" , "-DNO_TLS" });
501
504
}
502
505
503
506
inline for (LLVM_OBJ_NAMES ) | NAME | {
504
507
const has_lto = std .mem .endsWith (u8 , NAME , "lto" );
505
508
if (has_lto ) {
506
- llvm_c_flags .appendAssumeCapacity ("-O0" );
509
+ try llvm_c_flags .appendBounded ("-O0" );
507
510
if (enable_lto ) {
508
- llvm_c_flags .appendAssumeCapacity ("-flto" );
511
+ try llvm_c_flags .appendBounded ("-flto" );
509
512
}
510
513
}
511
514
defer if (has_lto ) {
@@ -516,7 +519,7 @@ fn setupLLVMTooling(
516
519
};
517
520
inline for (.{ "" , if (ptr_bit_width == 32 ) "32" else "64" }) | MODE | {
518
521
if (MODE .len > 0 ) {
519
- llvm_c_flags .appendAssumeCapacity ("-m" ++ MODE );
522
+ try llvm_c_flags .appendBounded ("-m" ++ MODE );
520
523
}
521
524
defer if (MODE .len > 0 ) {
522
525
_ = llvm_c_flags .pop ();
@@ -531,7 +534,7 @@ fn setupLLVMTooling(
531
534
});
532
535
obj .addCSourceFile (.{
533
536
.file = AFLplusplus_ins_path .path (b , NAME ++ ".o.c" ),
534
- .flags = llvm_c_flags .constSlice () ,
537
+ .flags = llvm_c_flags .items ,
535
538
});
536
539
obj .addIncludePath (AFLplusplus_inc_path );
537
540
obj .linkLibC ();
@@ -558,20 +561,21 @@ fn setupLLVMTooling(
558
561
});
559
562
llvm_common_obj .addCSourceFile (.{
560
563
.file = AFLplusplus_ins_path .path (b , "afl-llvm-common.cc" ),
561
- .flags = llvm_cpp_flags .constSlice () ,
564
+ .flags = llvm_cpp_flags .items ,
562
565
});
563
566
llvm_common_obj .addIncludePath (AFLplusplus_inc_path );
564
567
llvm_common_obj .addIncludePath (llvm_inc_path );
565
568
llvm_common_obj .addLibraryPath (llvm_lib_path );
566
569
llvm_common_obj .linkSystemLibrary (llvm_name );
567
570
llvm_common_obj .linkLibCpp ();
568
571
569
- var llvm_lib_names = std .BoundedArray ([]const u8 , 16 ){};
570
- llvm_lib_names .appendSliceAssumeCapacity (& LLVM_LIB_NAMES );
572
+ var llvm_lib_names_buf : [16 ][]const u8 = undefined ;
573
+ var llvm_lib_names : std .ArrayList ([]const u8 ) = .initBuffer (& llvm_lib_names_buf );
574
+ try llvm_lib_names .appendSliceBounded (& LLVM_LIB_NAMES );
571
575
if (enable_lto ) {
572
- llvm_lib_names .appendSliceAssumeCapacity (& LLVM_LTO_LIB_NAMES );
576
+ try llvm_lib_names .appendSliceBounded (& LLVM_LTO_LIB_NAMES );
573
577
}
574
- for (llvm_lib_names .constSlice () ) | name | {
578
+ for (llvm_lib_names .items ) | name | {
575
579
const lib = b .addLibrary (.{
576
580
.linkage = .dynamic ,
577
581
.name = name ,
@@ -588,7 +592,7 @@ fn setupLLVMTooling(
588
592
b .fmt ("{s}.so.cc" , .{name });
589
593
lib .addCSourceFile (.{
590
594
.file = AFLplusplus_ins_path .path (b , file_name ),
591
- .flags = llvm_cpp_flags .constSlice () ,
595
+ .flags = llvm_cpp_flags .items ,
592
596
});
593
597
lib .addIncludePath (AFLplusplus_inc_path );
594
598
lib .addIncludePath (llvm_inc_path );
@@ -616,7 +620,7 @@ fn setupLLVMTooling(
616
620
});
617
621
cc_exe .addCSourceFile (.{
618
622
.file = AFLplusplus_src_path .path (b , "afl-cc.c" ),
619
- .flags = llvm_c_flags .constSlice () ,
623
+ .flags = llvm_c_flags .items ,
620
624
});
621
625
cc_exe .addIncludePath (AFLplusplus_inc_path );
622
626
cc_exe .addIncludePath (AFLplusplus_ins_path );
@@ -642,7 +646,7 @@ fn setupLLVMTooling(
642
646
});
643
647
ld_lto_exe .addCSourceFile (.{
644
648
.file = AFLplusplus_src_path .path (b , "afl-ld-lto.c" ),
645
- .flags = llvm_c_flags .constSlice () ,
649
+ .flags = llvm_c_flags .items ,
646
650
});
647
651
ld_lto_exe .addIncludePath (AFLplusplus_inc_path );
648
652
ld_lto_exe .linkLibC ();
0 commit comments