@@ -24,14 +24,15 @@ pub fn build(b: *std.Build) !void {
2424 const AFLplusplus_inc_path = AFLplusplus_dep .path ("include/" );
2525
2626 // 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 });
3031 if (target .result .cpu .arch .isX86 ()) {
31- flags .appendSliceAssumeCapacity (&.{ "-mavx2" , "-D_HAVE_AVX2" });
32+ try flags .appendSliceBounded (&.{ "-mavx2" , "-D_HAVE_AVX2" });
3233 }
3334 if (target .query .isNative ()) {
34- flags .appendAssumeCapacity ("-march=native" );
35+ try flags .appendBounded ("-march=native" );
3536 }
3637
3738 // Common objects
@@ -45,7 +46,7 @@ pub fn build(b: *std.Build) !void {
4546 });
4647 performance_obj .addCSourceFile (.{
4748 .file = AFLplusplus_src_path .path (b , "afl-performance.c" ),
48- .flags = flags .constSlice () ,
49+ .flags = flags .items ,
4950 });
5051 performance_obj .addIncludePath (AFLplusplus_inc_path );
5152 performance_obj .linkLibC ();
@@ -60,7 +61,7 @@ pub fn build(b: *std.Build) !void {
6061 });
6162 forkserver_obj .addCSourceFile (.{
6263 .file = AFLplusplus_src_path .path (b , "afl-forkserver.c" ),
63- .flags = flags .constSlice () ,
64+ .flags = flags .items ,
6465 });
6566 forkserver_obj .addIncludePath (AFLplusplus_inc_path );
6667 forkserver_obj .linkLibC ();
@@ -76,7 +77,7 @@ pub fn build(b: *std.Build) !void {
7677
7778 sharedmem_obj .addCSourceFile (.{
7879 .file = AFLplusplus_src_path .path (b , "afl-sharedmem.c" ),
79- .flags = flags .constSlice () ,
80+ .flags = flags .items ,
8081 });
8182
8283 sharedmem_obj .addIncludePath (AFLplusplus_inc_path );
@@ -92,7 +93,7 @@ pub fn build(b: *std.Build) !void {
9293 });
9394 common_obj .addCSourceFile (.{
9495 .file = AFLplusplus_src_path .path (b , "afl-common.c" ),
95- .flags = flags .constSlice () ,
96+ .flags = flags .items ,
9697 });
9798 common_obj .addIncludePath (AFLplusplus_inc_path );
9899 common_obj .linkLibC ();
@@ -124,7 +125,7 @@ pub fn build(b: *std.Build) !void {
124125 fuzz_exe .addCSourceFiles (.{
125126 .root = AFLplusplus_src_path ,
126127 .files = & EXE_FUZZ_SOURCES ,
127- .flags = flags .constSlice () ,
128+ .flags = flags .items ,
128129 });
129130 if (use_z ) {
130131 fuzz_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -152,7 +153,7 @@ pub fn build(b: *std.Build) !void {
152153 showmap_exe .addCSourceFiles (.{
153154 .root = AFLplusplus_src_path ,
154155 .files = &.{ "afl-showmap.c" , "afl-fuzz-mutators.c" , "afl-fuzz-python.c" },
155- .flags = flags .constSlice () ,
156+ .flags = flags .items ,
156157 });
157158
158159 if (use_z ) {
@@ -181,7 +182,7 @@ pub fn build(b: *std.Build) !void {
181182 });
182183 tmin_exe .addCSourceFile (.{
183184 .file = AFLplusplus_src_path .path (b , "afl-tmin.c" ),
184- .flags = flags .constSlice () ,
185+ .flags = flags .items ,
185186 });
186187
187188 if (use_z ) {
@@ -210,7 +211,7 @@ pub fn build(b: *std.Build) !void {
210211 });
211212 analyze_exe .addCSourceFile (.{
212213 .file = AFLplusplus_src_path .path (b , "afl-analyze.c" ),
213- .flags = flags .constSlice () ,
214+ .flags = flags .items ,
214215 });
215216 if (use_z ) {
216217 analyze_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -237,7 +238,7 @@ pub fn build(b: *std.Build) !void {
237238 });
238239 gotcpu_exe .addCSourceFile (.{
239240 .file = AFLplusplus_src_path .path (b , "afl-gotcpu.c" ),
240- .flags = flags .constSlice () ,
241+ .flags = flags .items ,
241242 });
242243 if (use_z ) {
243244 gotcpu_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -261,7 +262,7 @@ pub fn build(b: *std.Build) !void {
261262 });
262263 as_exe .addCSourceFile (.{
263264 .file = AFLplusplus_src_path .path (b , "afl-as.c" ),
264- .flags = flags .constSlice () ,
265+ .flags = flags .items ,
265266 });
266267 if (use_z ) {
267268 as_exe .root_module .addCMacro ("HAVE_ZLIB" , "" );
@@ -460,16 +461,17 @@ fn setupLLVMTooling(
460461 };
461462
462463 // 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 );
465467 const llvm_version = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--version" }), "\n " );
466468 var llvm_version_iter = std .mem .tokenizeScalar (u8 , llvm_version , '.' );
467469 const llvm_major = try std .fmt .parseUnsigned (u8 , llvm_version_iter .next ().? , 10 );
468470 const llvm_minor = try std .fmt .parseUnsigned (u8 , llvm_version_iter .next ().? , 10 );
469471 const llvm_bin_dir = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--bindir" }), "\n " );
470472 const llvm_lib_dir = std .mem .trimRight (u8 , b .run (&.{ llvm_config_path , "--libdir" }), "\n " );
471473 const llvm_lib_path = std.Build.LazyPath { .cwd_relative = llvm_lib_dir };
472- llvm_c_flags .appendSliceAssumeCapacity (&.{
474+ try llvm_c_flags .appendSliceBounded (&.{
473475 lib_path_flag ,
474476 bin_path_flag ,
475477 b .fmt ("-DLLVM_MAJOR={}" , .{llvm_major }),
@@ -481,31 +483,32 @@ fn setupLLVMTooling(
481483 b .fmt ("-DCLANGPP_BIN=\" {s}/clang++\" " , .{llvm_bin_dir }),
482484 });
483485 if (enable_lto ) {
484- llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\" -flto\" " );
486+ try llvm_c_flags .appendBounded ("-DAFL_CLANG_FLTO=\" -flto\" " );
485487 } else {
486- llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\"\" " );
488+ try llvm_c_flags .appendBounded ("-DAFL_CLANG_FLTO=\"\" " );
487489 }
488490 if (target .query .isNative ()) {
489- llvm_c_flags .appendAssumeCapacity ("-march=native" );
491+ try llvm_c_flags .appendBounded ("-march=native" );
490492 }
491493
492494 // 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 (&.{
497500 b .fmt ("-std={s}" , .{if (llvm_major < 10 ) "gnu++11" else if (llvm_major < 16 ) "c++14" else "c++17" }),
498501 });
499502 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" });
501504 }
502505
503506 inline for (LLVM_OBJ_NAMES ) | NAME | {
504507 const has_lto = std .mem .endsWith (u8 , NAME , "lto" );
505508 if (has_lto ) {
506- llvm_c_flags .appendAssumeCapacity ("-O0" );
509+ try llvm_c_flags .appendBounded ("-O0" );
507510 if (enable_lto ) {
508- llvm_c_flags .appendAssumeCapacity ("-flto" );
511+ try llvm_c_flags .appendBounded ("-flto" );
509512 }
510513 }
511514 defer if (has_lto ) {
@@ -516,7 +519,7 @@ fn setupLLVMTooling(
516519 };
517520 inline for (.{ "" , if (ptr_bit_width == 32 ) "32" else "64" }) | MODE | {
518521 if (MODE .len > 0 ) {
519- llvm_c_flags .appendAssumeCapacity ("-m" ++ MODE );
522+ try llvm_c_flags .appendBounded ("-m" ++ MODE );
520523 }
521524 defer if (MODE .len > 0 ) {
522525 _ = llvm_c_flags .pop ();
@@ -531,7 +534,7 @@ fn setupLLVMTooling(
531534 });
532535 obj .addCSourceFile (.{
533536 .file = AFLplusplus_ins_path .path (b , NAME ++ ".o.c" ),
534- .flags = llvm_c_flags .constSlice () ,
537+ .flags = llvm_c_flags .items ,
535538 });
536539 obj .addIncludePath (AFLplusplus_inc_path );
537540 obj .linkLibC ();
@@ -558,20 +561,21 @@ fn setupLLVMTooling(
558561 });
559562 llvm_common_obj .addCSourceFile (.{
560563 .file = AFLplusplus_ins_path .path (b , "afl-llvm-common.cc" ),
561- .flags = llvm_cpp_flags .constSlice () ,
564+ .flags = llvm_cpp_flags .items ,
562565 });
563566 llvm_common_obj .addIncludePath (AFLplusplus_inc_path );
564567 llvm_common_obj .addIncludePath (llvm_inc_path );
565568 llvm_common_obj .addLibraryPath (llvm_lib_path );
566569 llvm_common_obj .linkSystemLibrary (llvm_name );
567570 llvm_common_obj .linkLibCpp ();
568571
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 );
571575 if (enable_lto ) {
572- llvm_lib_names .appendSliceAssumeCapacity (& LLVM_LTO_LIB_NAMES );
576+ try llvm_lib_names .appendSliceBounded (& LLVM_LTO_LIB_NAMES );
573577 }
574- for (llvm_lib_names .constSlice () ) | name | {
578+ for (llvm_lib_names .items ) | name | {
575579 const lib = b .addLibrary (.{
576580 .linkage = .dynamic ,
577581 .name = name ,
@@ -588,7 +592,7 @@ fn setupLLVMTooling(
588592 b .fmt ("{s}.so.cc" , .{name });
589593 lib .addCSourceFile (.{
590594 .file = AFLplusplus_ins_path .path (b , file_name ),
591- .flags = llvm_cpp_flags .constSlice () ,
595+ .flags = llvm_cpp_flags .items ,
592596 });
593597 lib .addIncludePath (AFLplusplus_inc_path );
594598 lib .addIncludePath (llvm_inc_path );
@@ -616,7 +620,7 @@ fn setupLLVMTooling(
616620 });
617621 cc_exe .addCSourceFile (.{
618622 .file = AFLplusplus_src_path .path (b , "afl-cc.c" ),
619- .flags = llvm_c_flags .constSlice () ,
623+ .flags = llvm_c_flags .items ,
620624 });
621625 cc_exe .addIncludePath (AFLplusplus_inc_path );
622626 cc_exe .addIncludePath (AFLplusplus_ins_path );
@@ -642,7 +646,7 @@ fn setupLLVMTooling(
642646 });
643647 ld_lto_exe .addCSourceFile (.{
644648 .file = AFLplusplus_src_path .path (b , "afl-ld-lto.c" ),
645- .flags = llvm_c_flags .constSlice () ,
649+ .flags = llvm_c_flags .items ,
646650 });
647651 ld_lto_exe .addIncludePath (AFLplusplus_inc_path );
648652 ld_lto_exe .linkLibC ();
0 commit comments