authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 14:02:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-31 15:09:35-07:00
log90e48d4b3469fb4f8dd2f3b52e05453029d45fdc
treec213ee58f8a39ce6275456f5d37a59de4a58cf68
parent13a96165405af33fa6ef43a3ce2c1d8aea846287

std.Build: avoid use of catch unreachable

Usage of `catch unreachable` in build scripts is completely harmless because build scripts are always run in Debug mode, however, it sets a poor example for beginners to learn from.

13 files changed, 169 insertions(+), 161 deletions(-)

lib/std/Build.zig+34-35
......@@ -564,12 +564,12 @@ pub fn addConfigHeader(
564564
565565/// Allocator.dupe without the need to handle out of memory.
566566pub fn dupe(self: *Build, bytes: []const u8) []u8 {
567 return self.allocator.dupe(u8, bytes) catch unreachable;
567 return self.allocator.dupe(u8, bytes) catch @panic("OOM");
568568}
569569
570570/// Duplicates an array of strings without the need to handle out of memory.
571571pub fn dupeStrings(self: *Build, strings: []const []const u8) [][]u8 {
572 const array = self.allocator.alloc([]u8, strings.len) catch unreachable;
572 const array = self.allocator.alloc([]u8, strings.len) catch @panic("OOM");
573573 for (strings) |s, i| {
574574 array[i] = self.dupe(s);
575575 }
......@@ -596,7 +596,7 @@ pub fn dupePkg(self: *Build, package: Pkg) Pkg {
596596 };
597597
598598 if (package.dependencies) |dependencies| {
599 const new_dependencies = self.allocator.alloc(Pkg, dependencies.len) catch unreachable;
599 const new_dependencies = self.allocator.alloc(Pkg, dependencies.len) catch @panic("OOM");
600600 the_copy.dependencies = new_dependencies;
601601
602602 for (dependencies) |dep_package, i| {
......@@ -613,20 +613,20 @@ pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Writ
613613}
614614
615615pub fn addWriteFiles(self: *Build) *WriteFileStep {
616 const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
616 const write_file_step = self.allocator.create(WriteFileStep) catch @panic("OOM");
617617 write_file_step.* = WriteFileStep.init(self);
618618 return write_file_step;
619619}
620620
621621pub fn addLog(self: *Build, comptime format: []const u8, args: anytype) *LogStep {
622622 const data = self.fmt(format, args);
623 const log_step = self.allocator.create(LogStep) catch unreachable;
623 const log_step = self.allocator.create(LogStep) catch @panic("OOM");
624624 log_step.* = LogStep.init(self, data);
625625 return log_step;
626626}
627627
628628pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *RemoveDirStep {
629 const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
629 const remove_dir_step = self.allocator.create(RemoveDirStep) catch @panic("OOM");
630630 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
631631 return remove_dir_step;
632632}
......@@ -719,13 +719,13 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_
719719 const type_id = comptime typeToEnum(T);
720720 const enum_options = if (type_id == .@"enum") blk: {
721721 const fields = comptime std.meta.fields(T);
722 var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch unreachable;
722 var options = ArrayList([]const u8).initCapacity(self.allocator, fields.len) catch @panic("OOM");
723723
724724 inline for (fields) |field| {
725725 options.appendAssumeCapacity(field.name);
726726 }
727727
728 break :blk options.toOwnedSlice() catch unreachable;
728 break :blk options.toOwnedSlice() catch @panic("OOM");
729729 } else null;
730730 const available_option = AvailableOption{
731731 .name = name,
......@@ -733,10 +733,10 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_
733733 .description = description,
734734 .enum_options = enum_options,
735735 };
736 if ((self.available_options_map.fetchPut(name, available_option) catch unreachable) != null) {
736 if ((self.available_options_map.fetchPut(name, available_option) catch @panic("OOM")) != null) {
737737 panic("Option '{s}' declared twice", .{name});
738738 }
739 self.available_options_list.append(available_option) catch unreachable;
739 self.available_options_list.append(available_option) catch @panic("OOM");
740740
741741 const option_ptr = self.user_input_options.getPtr(name) orelse return null;
742742 option_ptr.used = true;
......@@ -840,7 +840,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_
840840 return null;
841841 },
842842 .scalar => |s| {
843 return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch unreachable;
843 return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch @panic("OOM");
844844 },
845845 .list => |lst| return lst.items,
846846 },
......@@ -848,12 +848,12 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_
848848}
849849
850850pub fn step(self: *Build, name: []const u8, description: []const u8) *Step {
851 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
851 const step_info = self.allocator.create(TopLevelStep) catch @panic("OOM");
852852 step_info.* = TopLevelStep{
853853 .step = Step.initNoOp(.top_level, name, self.allocator),
854854 .description = self.dupe(description),
855855 };
856 self.top_level_steps.append(step_info) catch unreachable;
856 self.top_level_steps.append(step_info) catch @panic("OOM");
857857 return &step_info.step;
858858}
859859
......@@ -949,7 +949,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
949949 },
950950 };
951951
952 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable;
952 const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch @panic("OOM");
953953
954954 if (args.whitelist) |list| whitelist_check: {
955955 // Make sure it's a match of one of the list.
......@@ -960,7 +960,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
960960 mismatch_cpu_features = true;
961961 mismatch_triple = true;
962962
963 const t_triple = t.zigTriple(self.allocator) catch unreachable;
963 const t_triple = t.zigTriple(self.allocator) catch @panic("OOM");
964964 if (mem.eql(u8, t_triple, selected_canonicalized_triple)) {
965965 mismatch_triple = false;
966966 whitelist_item = t;
......@@ -977,7 +977,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros
977977 selected_canonicalized_triple,
978978 });
979979 for (list) |t| {
980 const t_triple = t.zigTriple(self.allocator) catch unreachable;
980 const t_triple = t.zigTriple(self.allocator) catch @panic("OOM");
981981 log.err(" {s}", .{t_triple});
982982 }
983983 } else {
......@@ -1033,22 +1033,22 @@ pub fn addUserInputOption(self: *Build, name_raw: []const u8, value_raw: []const
10331033 .scalar => |s| {
10341034 // turn it into a list
10351035 var list = ArrayList([]const u8).init(self.allocator);
1036 list.append(s) catch unreachable;
1037 list.append(value) catch unreachable;
1038 self.user_input_options.put(name, .{
1036 try list.append(s);
1037 try list.append(value);
1038 try self.user_input_options.put(name, .{
10391039 .name = name,
10401040 .value = .{ .list = list },
10411041 .used = false,
1042 }) catch unreachable;
1042 });
10431043 },
10441044 .list => |*list| {
10451045 // append to the list
1046 list.append(value) catch unreachable;
1047 self.user_input_options.put(name, .{
1046 try list.append(value);
1047 try self.user_input_options.put(name, .{
10481048 .name = name,
10491049 .value = .{ .list = list.* },
10501050 .used = false,
1051 }) catch unreachable;
1051 });
10521052 },
10531053 .flag => {
10541054 log.warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.", .{ name, value, name });
......@@ -1240,13 +1240,13 @@ pub fn addInstallFileWithDir(
12401240 if (dest_rel_path.len == 0) {
12411241 panic("dest_rel_path must be non-empty", .{});
12421242 }
1243 const install_step = self.allocator.create(InstallFileStep) catch unreachable;
1243 const install_step = self.allocator.create(InstallFileStep) catch @panic("OOM");
12441244 install_step.* = InstallFileStep.init(self, source.dupe(self), install_dir, dest_rel_path);
12451245 return install_step;
12461246}
12471247
12481248pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *InstallDirStep {
1249 const install_step = self.allocator.create(InstallDirStep) catch unreachable;
1249 const install_step = self.allocator.create(InstallDirStep) catch @panic("OOM");
12501250 install_step.* = InstallDirStep.init(self, options);
12511251 return install_step;
12521252}
......@@ -1256,7 +1256,7 @@ pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u
12561256 .dir = dir,
12571257 .path = dest_rel_path,
12581258 };
1259 self.installed_files.append(file.dupe(self)) catch unreachable;
1259 self.installed_files.append(file.dupe(self)) catch @panic("OOM");
12601260}
12611261
12621262pub fn updateFile(self: *Build, source_path: []const u8, dest_path: []const u8) !void {
......@@ -1289,16 +1289,15 @@ pub fn truncateFile(self: *Build, dest_path: []const u8) !void {
12891289}
12901290
12911291pub fn pathFromRoot(self: *Build, rel_path: []const u8) []u8 {
1292 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
1292 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch @panic("OOM");
12931293}
12941294
1295/// Shorthand for `std.fs.path.join(Build.allocator, paths) catch unreachable`
12961295pub fn pathJoin(self: *Build, paths: []const []const u8) []u8 {
1297 return fs.path.join(self.allocator, paths) catch unreachable;
1296 return fs.path.join(self.allocator, paths) catch @panic("OOM");
12981297}
12991298
13001299pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 {
1301 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
1300 return fmt_lib.allocPrint(self.allocator, format, args) catch @panic("OOM");
13021301}
13031302
13041303pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 {
......@@ -1442,7 +1441,7 @@ pub fn exec(self: *Build, argv: []const []const u8) ![]u8 {
14421441}
14431442
14441443pub fn addSearchPrefix(self: *Build, search_prefix: []const u8) void {
1445 self.search_prefixes.append(self.dupePath(search_prefix)) catch unreachable;
1444 self.search_prefixes.append(self.dupePath(search_prefix)) catch @panic("OOM");
14461445}
14471446
14481447pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
......@@ -1457,7 +1456,7 @@ pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8)
14571456 return fs.path.resolve(
14581457 self.allocator,
14591458 &[_][]const u8{ base_dir, dest_rel_path },
1460 ) catch unreachable;
1459 ) catch @panic("OOM");
14611460}
14621461
14631462pub const Dependency = struct {
......@@ -1509,14 +1508,14 @@ fn dependencyInner(
15091508 comptime build_zig: type,
15101509 args: anytype,
15111510) *Dependency {
1512 const sub_builder = b.createChild(name, build_root, args) catch unreachable;
1513 sub_builder.runBuild(build_zig) catch unreachable;
1511 const sub_builder = b.createChild(name, build_root, args) catch @panic("unhandled error");
1512 sub_builder.runBuild(build_zig) catch @panic("unhandled error");
15141513
15151514 if (sub_builder.validateUserInputDidItFail()) {
15161515 std.debug.dumpCurrentStackTrace(@returnAddress());
15171516 }
15181517
1519 const dep = b.allocator.create(Dependency) catch unreachable;
1518 const dep = b.allocator.create(Dependency) catch @panic("OOM");
15201519 dep.* = .{ .builder = sub_builder };
15211520 return dep;
15221521}
lib/std/Build/CheckFileStep.zig+1-1
......@@ -18,7 +18,7 @@ pub fn create(
1818 source: std.Build.FileSource,
1919 expected_matches: []const []const u8,
2020) *CheckFileStep {
21 const self = builder.allocator.create(CheckFileStep) catch unreachable;
21 const self = builder.allocator.create(CheckFileStep) catch @panic("OOM");
2222 self.* = CheckFileStep{
2323 .builder = builder,
2424 .step = Step.init(.check_file, "CheckFile", builder.allocator, make),
lib/std/Build/CheckObjectStep.zig+6-6
......@@ -24,7 +24,7 @@ obj_format: std.Target.ObjectFormat,
2424
2525pub fn create(builder: *std.Build, source: std.Build.FileSource, obj_format: std.Target.ObjectFormat) *CheckObjectStep {
2626 const gpa = builder.allocator;
27 const self = gpa.create(CheckObjectStep) catch unreachable;
27 const self = gpa.create(CheckObjectStep) catch @panic("OOM");
2828 self.* = .{
2929 .builder = builder,
3030 .step = Step.init(.check_file, "CheckObject", gpa, make),
......@@ -228,14 +228,14 @@ const Check = struct {
228228 self.actions.append(.{
229229 .tag = .match,
230230 .phrase = self.builder.dupe(phrase),
231 }) catch unreachable;
231 }) catch @panic("OOM");
232232 }
233233
234234 fn notPresent(self: *Check, phrase: []const u8) void {
235235 self.actions.append(.{
236236 .tag = .not_present,
237237 .phrase = self.builder.dupe(phrase),
238 }) catch unreachable;
238 }) catch @panic("OOM");
239239 }
240240
241241 fn computeCmp(self: *Check, phrase: []const u8, expected: ComputeCompareExpected) void {
......@@ -243,7 +243,7 @@ const Check = struct {
243243 .tag = .compute_cmp,
244244 .phrase = self.builder.dupe(phrase),
245245 .expected = expected,
246 }) catch unreachable;
246 }) catch @panic("OOM");
247247 }
248248};
249249
......@@ -251,7 +251,7 @@ const Check = struct {
251251pub fn checkStart(self: *CheckObjectStep, phrase: []const u8) void {
252252 var new_check = Check.create(self.builder);
253253 new_check.match(phrase);
254 self.checks.append(new_check) catch unreachable;
254 self.checks.append(new_check) catch @panic("OOM");
255255}
256256
257257/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)`.
......@@ -293,7 +293,7 @@ pub fn checkComputeCompare(
293293) void {
294294 var new_check = Check.create(self.builder);
295295 new_check.computeCmp(program, expected);
296 self.checks.append(new_check) catch unreachable;
296 self.checks.append(new_check) catch @panic("OOM");
297297}
298298
299299fn make(step: *Step) !void {
lib/std/Build/CompileStep.zig+63-58
......@@ -312,7 +312,7 @@ pub fn create(builder: *std.Build, options: Options) *CompileStep {
312312 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
313313 }
314314
315 const self = builder.allocator.create(CompileStep) catch unreachable;
315 const self = builder.allocator.create(CompileStep) catch @panic("OOM");
316316 self.* = CompileStep{
317317 .strip = null,
318318 .unwind_tables = null,
......@@ -364,7 +364,7 @@ pub fn create(builder: *std.Build, options: Options) *CompileStep {
364364 .output_h_path_source = GeneratedFile{ .step = &self.step },
365365 .output_pdb_path_source = GeneratedFile{ .step = &self.step },
366366
367 .target_info = NativeTargetInfo.detect(self.target) catch unreachable,
367 .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"),
368368 };
369369 self.computeOutFileNames();
370370 if (root_src) |rs| rs.addStepDependencies(&self.step);
......@@ -387,7 +387,7 @@ fn computeOutFileNames(self: *CompileStep) void {
387387 .static => .Static,
388388 }) else null,
389389 .version = self.version,
390 }) catch unreachable;
390 }) catch @panic("OOM");
391391
392392 if (self.kind == .lib) {
393393 if (self.linkage != null and self.linkage.? == .static) {
......@@ -439,7 +439,7 @@ pub fn installRaw(self: *CompileStep, dest_filename: []const u8, options: Instal
439439pub fn installHeader(a: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
440440 const install_file = a.builder.addInstallHeaderFile(src_path, dest_rel_path);
441441 a.builder.getInstallStep().dependOn(&install_file.step);
442 a.installed_headers.append(&install_file.step) catch unreachable;
442 a.installed_headers.append(&install_file.step) catch @panic("OOM");
443443}
444444
445445pub fn installHeadersDirectory(
......@@ -460,7 +460,7 @@ pub fn installHeadersDirectoryOptions(
460460) void {
461461 const install_dir = a.builder.addInstallDirectory(options);
462462 a.builder.getInstallStep().dependOn(&install_dir.step);
463 a.installed_headers.append(&install_dir.step) catch unreachable;
463 a.installed_headers.append(&install_dir.step) catch @panic("OOM");
464464}
465465
466466pub fn installLibraryHeaders(a: *CompileStep, l: *CompileStep) void {
......@@ -472,7 +472,7 @@ pub fn installLibraryHeaders(a: *CompileStep, l: *CompileStep) void {
472472 const step_copy = switch (step.id) {
473473 inline .install_file, .install_dir => |id| blk: {
474474 const T = id.Type();
475 const ptr = a.builder.allocator.create(T) catch unreachable;
475 const ptr = a.builder.allocator.create(T) catch @panic("OOM");
476476 ptr.* = step.cast(T).?.*;
477477 ptr.override_source_builder = ptr.builder;
478478 ptr.builder = a.builder;
......@@ -480,10 +480,10 @@ pub fn installLibraryHeaders(a: *CompileStep, l: *CompileStep) void {
480480 },
481481 else => unreachable,
482482 };
483 a.installed_headers.append(step_copy) catch unreachable;
483 a.installed_headers.append(step_copy) catch @panic("OOM");
484484 install_step.dependOn(step_copy);
485485 }
486 a.installed_headers.appendSlice(l.installed_headers.items) catch unreachable;
486 a.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM");
487487}
488488
489489/// Creates a `RunStep` with an executable built with `addExecutable`.
......@@ -532,19 +532,19 @@ pub fn setLinkerScriptPath(self: *CompileStep, source: FileSource) void {
532532}
533533
534534pub fn linkFramework(self: *CompileStep, framework_name: []const u8) void {
535 self.frameworks.put(self.builder.dupe(framework_name), .{}) catch unreachable;
535 self.frameworks.put(self.builder.dupe(framework_name), .{}) catch @panic("OOM");
536536}
537537
538538pub fn linkFrameworkNeeded(self: *CompileStep, framework_name: []const u8) void {
539539 self.frameworks.put(self.builder.dupe(framework_name), .{
540540 .needed = true,
541 }) catch unreachable;
541 }) catch @panic("OOM");
542542}
543543
544544pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {
545545 self.frameworks.put(self.builder.dupe(framework_name), .{
546546 .weak = true,
547 }) catch unreachable;
547 }) catch @panic("OOM");
548548}
549549
550550/// Returns whether the library, executable, or object depends on a particular system library.
......@@ -596,12 +596,12 @@ pub fn linkLibCpp(self: *CompileStep) void {
596596/// `name` and `value` need not live longer than the function call.
597597pub fn defineCMacro(self: *CompileStep, name: []const u8, value: ?[]const u8) void {
598598 const macro = std.Build.constructCMacro(self.builder.allocator, name, value);
599 self.c_macros.append(macro) catch unreachable;
599 self.c_macros.append(macro) catch @panic("OOM");
600600}
601601
602602/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
603603pub fn defineCMacroRaw(self: *CompileStep, name_and_value: []const u8) void {
604 self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;
604 self.c_macros.append(self.builder.dupe(name_and_value)) catch @panic("OOM");
605605}
606606
607607/// This one has no integration with anything, it just puts -lname on the command line.
......@@ -614,7 +614,7 @@ pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {
614614 .weak = false,
615615 .use_pkg_config = .no,
616616 },
617 }) catch unreachable;
617 }) catch @panic("OOM");
618618}
619619
620620/// This one has no integration with anything, it just puts -needed-lname on the command line.
......@@ -627,7 +627,7 @@ pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {
627627 .weak = false,
628628 .use_pkg_config = .no,
629629 },
630 }) catch unreachable;
630 }) catch @panic("OOM");
631631}
632632
633633/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the
......@@ -640,7 +640,7 @@ pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void {
640640 .weak = true,
641641 .use_pkg_config = .no,
642642 },
643 }) catch unreachable;
643 }) catch @panic("OOM");
644644}
645645
646646/// This links against a system library, exclusively using pkg-config to find the library.
......@@ -653,7 +653,7 @@ pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8)
653653 .weak = false,
654654 .use_pkg_config = .force,
655655 },
656 }) catch unreachable;
656 }) catch @panic("OOM");
657657}
658658
659659/// This links against a system library, exclusively using pkg-config to find the library.
......@@ -666,7 +666,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons
666666 .weak = false,
667667 .use_pkg_config = .force,
668668 },
669 }) catch unreachable;
669 }) catch @panic("OOM");
670670}
671671
672672/// Run pkg-config for the given library name and parse the output, returning the arguments
......@@ -797,7 +797,7 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {
797797 .weak = opts.weak,
798798 .use_pkg_config = .yes,
799799 },
800 }) catch unreachable;
800 }) catch @panic("OOM");
801801}
802802
803803pub fn setNamePrefix(self: *CompileStep, text: []const u8) void {
......@@ -817,7 +817,7 @@ pub fn setTestRunner(self: *CompileStep, path: ?[]const u8) void {
817817
818818/// Handy when you have many C/C++ source files and want them all to have the same flags.
819819pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void {
820 const c_source_files = self.builder.allocator.create(CSourceFiles) catch unreachable;
820 const c_source_files = self.builder.allocator.create(CSourceFiles) catch @panic("OOM");
821821
822822 const files_copy = self.builder.dupeStrings(files);
823823 const flags_copy = self.builder.dupeStrings(flags);
......@@ -826,7 +826,7 @@ pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []c
826826 .files = files_copy,
827827 .flags = flags_copy,
828828 };
829 self.link_objects.append(.{ .c_source_files = c_source_files }) catch unreachable;
829 self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM");
830830}
831831
832832pub fn addCSourceFile(self: *CompileStep, file: []const u8, flags: []const []const u8) void {
......@@ -837,9 +837,9 @@ pub fn addCSourceFile(self: *CompileStep, file: []const u8, flags: []const []con
837837}
838838
839839pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {
840 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;
840 const c_source_file = self.builder.allocator.create(CSourceFile) catch @panic("OOM");
841841 c_source_file.* = source.dupe(self.builder);
842 self.link_objects.append(.{ .c_source_file = c_source_file }) catch unreachable;
842 self.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM");
843843 source.source.addStepDependencies(&self.step);
844844}
845845
......@@ -893,12 +893,12 @@ pub fn getOutputPdbSource(self: *CompileStep) FileSource {
893893pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void {
894894 self.link_objects.append(.{
895895 .assembly_file = .{ .path = self.builder.dupe(path) },
896 }) catch unreachable;
896 }) catch @panic("OOM");
897897}
898898
899899pub fn addAssemblyFileSource(self: *CompileStep, source: FileSource) void {
900900 const source_duped = source.dupe(self.builder);
901 self.link_objects.append(.{ .assembly_file = source_duped }) catch unreachable;
901 self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM");
902902 source_duped.addStepDependencies(&self.step);
903903}
904904
......@@ -907,7 +907,7 @@ pub fn addObjectFile(self: *CompileStep, source_file: []const u8) void {
907907}
908908
909909pub fn addObjectFileSource(self: *CompileStep, source: FileSource) void {
910 self.link_objects.append(.{ .static_path = source.dupe(self.builder) }) catch unreachable;
910 self.link_objects.append(.{ .static_path = source.dupe(self.builder) }) catch @panic("OOM");
911911 source.addStepDependencies(&self.step);
912912}
913913
......@@ -922,11 +922,11 @@ pub const addLibPath = @compileError("deprecated, use addLibraryPath");
922922pub const addFrameworkDir = @compileError("deprecated, use addFrameworkPath");
923923
924924pub fn addSystemIncludePath(self: *CompileStep, path: []const u8) void {
925 self.include_dirs.append(IncludeDir{ .raw_path_system = self.builder.dupe(path) }) catch unreachable;
925 self.include_dirs.append(IncludeDir{ .raw_path_system = self.builder.dupe(path) }) catch @panic("OOM");
926926}
927927
928928pub fn addIncludePath(self: *CompileStep, path: []const u8) void {
929 self.include_dirs.append(IncludeDir{ .raw_path = self.builder.dupe(path) }) catch unreachable;
929 self.include_dirs.append(IncludeDir{ .raw_path = self.builder.dupe(path) }) catch @panic("OOM");
930930}
931931
932932pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) void {
......@@ -935,19 +935,19 @@ pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) voi
935935}
936936
937937pub fn addLibraryPath(self: *CompileStep, path: []const u8) void {
938 self.lib_paths.append(self.builder.dupe(path)) catch unreachable;
938 self.lib_paths.append(self.builder.dupe(path)) catch @panic("OOM");
939939}
940940
941941pub fn addRPath(self: *CompileStep, path: []const u8) void {
942 self.rpaths.append(self.builder.dupe(path)) catch unreachable;
942 self.rpaths.append(self.builder.dupe(path)) catch @panic("OOM");
943943}
944944
945945pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void {
946 self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;
946 self.framework_dirs.append(self.builder.dupe(dir_path)) catch @panic("OOM");
947947}
948948
949949pub fn addPackage(self: *CompileStep, package: Pkg) void {
950 self.packages.append(self.builder.dupePkg(package)) catch unreachable;
950 self.packages.append(self.builder.dupePkg(package)) catch @panic("OOM");
951951 self.addRecursiveBuildDeps(package);
952952}
953953
......@@ -1010,7 +1010,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {
10101010
10111011pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {
10121012 assert(self.kind == .@"test");
1013 const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch unreachable;
1013 const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch @panic("OOM");
10141014 for (args) |arg, i| {
10151015 duped_args[i] = if (arg) |a| self.builder.dupe(a) else null;
10161016 }
......@@ -1019,8 +1019,8 @@ pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {
10191019
10201020fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {
10211021 self.step.dependOn(&other.step);
1022 self.link_objects.append(.{ .other_step = other }) catch unreachable;
1023 self.include_dirs.append(.{ .other_step = other }) catch unreachable;
1022 self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");
1023 self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");
10241024}
10251025
10261026fn makePackageCmd(self: *CompileStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void {
......@@ -1051,7 +1051,7 @@ fn make(step: *Step) !void {
10511051 var zig_args = ArrayList([]const u8).init(builder.allocator);
10521052 defer zig_args.deinit();
10531053
1054 zig_args.append(builder.zig_exe) catch unreachable;
1054 try zig_args.append(builder.zig_exe);
10551055
10561056 const cmd = switch (self.kind) {
10571057 .lib => "build-lib",
......@@ -1060,7 +1060,7 @@ fn make(step: *Step) !void {
10601060 .@"test" => "test",
10611061 .test_exe => "test",
10621062 };
1063 zig_args.append(cmd) catch unreachable;
1063 try zig_args.append(cmd);
10641064
10651065 if (builder.color != .auto) {
10661066 try zig_args.append("--color");
......@@ -1265,12 +1265,12 @@ fn make(step: *Step) !void {
12651265 try zig_args.append("--debug-compile-errors");
12661266 }
12671267
1268 if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
1269 if (builder.verbose_air) zig_args.append("--verbose-air") catch unreachable;
1270 if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
1271 if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable;
1272 if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable;
1273 if (builder.verbose_llvm_cpu_features) zig_args.append("--verbose-llvm-cpu-features") catch unreachable;
1268 if (builder.verbose_cimport) try zig_args.append("--verbose-cimport");
1269 if (builder.verbose_air) try zig_args.append("--verbose-air");
1270 if (builder.verbose_llvm_ir) try zig_args.append("--verbose-llvm-ir");
1271 if (builder.verbose_link or self.verbose_link) try zig_args.append("--verbose-link");
1272 if (builder.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc");
1273 if (builder.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features");
12741274
12751275 if (self.emit_analysis.getArg(builder, "emit-analysis")) |arg| try zig_args.append(arg);
12761276 if (self.emit_asm.getArg(builder, "emit-asm")) |arg| try zig_args.append(arg);
......@@ -1336,7 +1336,7 @@ fn make(step: *Step) !void {
13361336
13371337 switch (self.optimize) {
13381338 .Debug => {}, // Skip since it's the default.
1339 else => zig_args.append(builder.fmt("-O{s}", .{@tagName(self.optimize)})) catch unreachable,
1339 else => try zig_args.append(builder.fmt("-O{s}", .{@tagName(self.optimize)})),
13401340 }
13411341
13421342 try zig_args.append("--cache-dir");
......@@ -1345,8 +1345,8 @@ fn make(step: *Step) !void {
13451345 try zig_args.append("--global-cache-dir");
13461346 try zig_args.append(builder.pathFromRoot(builder.global_cache_root));
13471347
1348 zig_args.append("--name") catch unreachable;
1349 zig_args.append(self.name) catch unreachable;
1348 try zig_args.append("--name");
1349 try zig_args.append(self.name);
13501350
13511351 if (self.linkage) |some| switch (some) {
13521352 .dynamic => try zig_args.append("-dynamic"),
......@@ -1354,8 +1354,8 @@ fn make(step: *Step) !void {
13541354 };
13551355 if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic) {
13561356 if (self.version) |version| {
1357 zig_args.append("--version") catch unreachable;
1358 zig_args.append(builder.fmt("{}", .{version})) catch unreachable;
1357 try zig_args.append("--version");
1358 try zig_args.append(builder.fmt("{}", .{version}));
13591359 }
13601360
13611361 if (self.target.isDarwin()) {
......@@ -1651,13 +1651,13 @@ fn make(step: *Step) !void {
16511651 const name = entry.key_ptr.*;
16521652 const info = entry.value_ptr.*;
16531653 if (info.needed) {
1654 zig_args.append("-needed_framework") catch unreachable;
1654 try zig_args.append("-needed_framework");
16551655 } else if (info.weak) {
1656 zig_args.append("-weak_framework") catch unreachable;
1656 try zig_args.append("-weak_framework");
16571657 } else {
1658 zig_args.append("-framework") catch unreachable;
1658 try zig_args.append("-framework");
16591659 }
1660 zig_args.append(name) catch unreachable;
1660 try zig_args.append(name);
16611661 }
16621662 } else {
16631663 if (self.framework_dirs.items.len > 0) {
......@@ -1748,7 +1748,7 @@ fn make(step: *Step) !void {
17481748 // Slow path for arguments that need to be escaped. We'll need to allocate and copy
17491749 var escaped = try ArrayList(u8).initCapacity(args_arena.allocator(), arg.len + 1);
17501750 const writer = escaped.writer();
1751 writer.writeAll(arg[0..arg_idx]) catch unreachable;
1751 try writer.writeAll(arg[0..arg_idx]);
17521752 for (arg[arg_idx..]) |to_escape| {
17531753 if (to_escape == '\\' or to_escape == '"') try writer.writeByte('\\');
17541754 try writer.writeByte(to_escape);
......@@ -1874,23 +1874,28 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {
18741874 return vcpkg_path;
18751875}
18761876
1877pub fn doAtomicSymLinks(allocator: Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
1877pub fn doAtomicSymLinks(
1878 allocator: Allocator,
1879 output_path: []const u8,
1880 filename_major_only: []const u8,
1881 filename_name_only: []const u8,
1882) !void {
18781883 const out_dir = fs.path.dirname(output_path) orelse ".";
18791884 const out_basename = fs.path.basename(output_path);
18801885 // sym link for libfoo.so.1 to libfoo.so.1.2.3
1881 const major_only_path = fs.path.join(
1886 const major_only_path = try fs.path.join(
18821887 allocator,
18831888 &[_][]const u8{ out_dir, filename_major_only },
1884 ) catch unreachable;
1889 );
18851890 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
18861891 log.err("Unable to symlink {s} -> {s}", .{ major_only_path, out_basename });
18871892 return err;
18881893 };
18891894 // sym link for libfoo.so to libfoo.so.1
1890 const name_only_path = fs.path.join(
1895 const name_only_path = try fs.path.join(
18911896 allocator,
18921897 &[_][]const u8{ out_dir, filename_name_only },
1893 ) catch unreachable;
1898 );
18941899 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
18951900 log.err("Unable to symlink {s} -> {s}", .{ name_only_path, filename_major_only });
18961901 return err;
lib/std/Build/EmulatableRunStep.zig+4-4
......@@ -47,7 +47,7 @@ hide_foreign_binaries_warning: bool,
4747/// Asserts given artifact is an executable.
4848pub fn create(builder: *std.Build, name: []const u8, artifact: *CompileStep) *EmulatableRunStep {
4949 std.debug.assert(artifact.kind == .exe or artifact.kind == .test_exe);
50 const self = builder.allocator.create(EmulatableRunStep) catch unreachable;
50 const self = builder.allocator.create(EmulatableRunStep) catch @panic("OOM");
5151
5252 const option_name = "hide-foreign-warnings";
5353 const hide_warnings = if (builder.available_options_map.get(option_name) == null) warn: {
......@@ -154,9 +154,9 @@ fn warnAboutForeignBinaries(step: *EmulatableRunStep) void {
154154 const builder = step.builder;
155155 const artifact = step.exe;
156156
157 const host_name = builder.host.target.zigTriple(builder.allocator) catch unreachable;
158 const foreign_name = artifact.target.zigTriple(builder.allocator) catch unreachable;
159 const target_info = std.zig.system.NativeTargetInfo.detect(artifact.target) catch unreachable;
157 const host_name = builder.host.target.zigTriple(builder.allocator) catch @panic("unhandled error");
158 const foreign_name = artifact.target.zigTriple(builder.allocator) catch @panic("unhandled error");
159 const target_info = std.zig.system.NativeTargetInfo.detect(artifact.target) catch @panic("unhandled error");
160160 const need_cross_glibc = artifact.target.isGnuLibC() and artifact.is_linking_libc;
161161 switch (builder.host.getExternalExecutor(target_info, .{
162162 .qemu_fixes_dl = need_cross_glibc and builder.glibc_runtimes_dir != null,
lib/std/Build/FmtStep.zig+2-2
......@@ -9,12 +9,12 @@ builder: *std.Build,
99argv: [][]const u8,
1010
1111pub fn create(builder: *std.Build, paths: []const []const u8) *FmtStep {
12 const self = builder.allocator.create(FmtStep) catch unreachable;
12 const self = builder.allocator.create(FmtStep) catch @panic("OOM");
1313 const name = "zig fmt";
1414 self.* = FmtStep{
1515 .step = Step.init(.fmt, name, builder.allocator, make),
1616 .builder = builder,
17 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,
17 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch @panic("OOM"),
1818 };
1919
2020 self.argv[0] = builder.zig_exe;
lib/std/Build/InstallArtifactStep.zig+1-1
......@@ -16,7 +16,7 @@ h_dir: ?InstallDir,
1616pub fn create(builder: *std.Build, artifact: *CompileStep) *InstallArtifactStep {
1717 if (artifact.install_step) |s| return s;
1818
19 const self = builder.allocator.create(InstallArtifactStep) catch unreachable;
19 const self = builder.allocator.create(InstallArtifactStep) catch @panic("OOM");
2020 self.* = InstallArtifactStep{
2121 .builder = builder,
2222 .step = Step.init(.install_artifact, builder.fmt("install {s}", .{artifact.step.name}), builder.allocator, make),
lib/std/Build/InstallRawStep.zig+2-2
......@@ -44,7 +44,7 @@ pub fn create(
4444 dest_filename: []const u8,
4545 options: CreateOptions,
4646) *InstallRawStep {
47 const self = builder.allocator.create(InstallRawStep) catch unreachable;
47 const self = builder.allocator.create(InstallRawStep) catch @panic("OOM");
4848 self.* = InstallRawStep{
4949 .step = Step.init(.install_raw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
5050 .builder = builder,
......@@ -82,7 +82,7 @@ fn make(step: *Step) !void {
8282 const full_dest_path = b.getInstallPath(self.dest_dir, self.dest_filename);
8383 self.output_file.path = full_dest_path;
8484
85 fs.cwd().makePath(b.getInstallPath(self.dest_dir, "")) catch unreachable;
85 try fs.cwd().makePath(b.getInstallPath(self.dest_dir, ""));
8686
8787 var argv_list = std.ArrayList([]const u8).init(b.allocator);
8888 try argv_list.appendSlice(&.{ b.zig_exe, "objcopy" });
lib/std/Build/OptionsStep.zig+33-29
......@@ -19,7 +19,7 @@ artifact_args: std.ArrayList(OptionArtifactArg),
1919file_source_args: std.ArrayList(OptionFileSourceArg),
2020
2121pub fn create(builder: *std.Build) *OptionsStep {
22 const self = builder.allocator.create(OptionsStep) catch unreachable;
22 const self = builder.allocator.create(OptionsStep) catch @panic("OOM");
2323 self.* = .{
2424 .builder = builder,
2525 .step = Step.init(.options, "options", builder.allocator, make),
......@@ -34,44 +34,48 @@ pub fn create(builder: *std.Build) *OptionsStep {
3434}
3535
3636pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: T) void {
37 return addOptionFallible(self, T, name, value) catch @panic("unhandled error");
38}
39
40fn addOptionFallible(self: *OptionsStep, comptime T: type, name: []const u8, value: T) !void {
3741 const out = self.contents.writer();
3842 switch (T) {
3943 []const []const u8 => {
40 out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{std.zig.fmtId(name)}) catch unreachable;
44 try out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{std.zig.fmtId(name)});
4145 for (value) |slice| {
42 out.print(" \"{}\",\n", .{std.zig.fmtEscapes(slice)}) catch unreachable;
46 try out.print(" \"{}\",\n", .{std.zig.fmtEscapes(slice)});
4347 }
44 out.writeAll("};\n") catch unreachable;
48 try out.writeAll("};\n");
4549 return;
4650 },
4751 [:0]const u8 => {
48 out.print("pub const {}: [:0]const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
52 try out.print("pub const {}: [:0]const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) });
4953 return;
5054 },
5155 []const u8 => {
52 out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
56 try out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) });
5357 return;
5458 },
5559 ?[:0]const u8 => {
56 out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
60 try out.print("pub const {}: ?[:0]const u8 = ", .{std.zig.fmtId(name)});
5761 if (value) |payload| {
58 out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
62 try out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)});
5963 } else {
60 out.writeAll("null;\n") catch unreachable;
64 try out.writeAll("null;\n");
6165 }
6266 return;
6367 },
6468 ?[]const u8 => {
65 out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
69 try out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)});
6670 if (value) |payload| {
67 out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
71 try out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)});
6872 } else {
69 out.writeAll("null;\n") catch unreachable;
73 try out.writeAll("null;\n");
7074 }
7175 return;
7276 },
7377 std.builtin.Version => {
74 out.print(
78 try out.print(
7579 \\pub const {}: @import("std").builtin.Version = .{{
7680 \\ .major = {d},
7781 \\ .minor = {d},
......@@ -84,11 +88,11 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value:
8488 value.major,
8589 value.minor,
8690 value.patch,
87 }) catch unreachable;
91 });
8892 return;
8993 },
9094 std.SemanticVersion => {
91 out.print(
95 try out.print(
9296 \\pub const {}: @import("std").SemanticVersion = .{{
9397 \\ .major = {d},
9498 \\ .minor = {d},
......@@ -100,38 +104,38 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value:
100104 value.major,
101105 value.minor,
102106 value.patch,
103 }) catch unreachable;
107 });
104108 if (value.pre) |some| {
105 out.print(" .pre = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
109 try out.print(" .pre = \"{}\",\n", .{std.zig.fmtEscapes(some)});
106110 }
107111 if (value.build) |some| {
108 out.print(" .build = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
112 try out.print(" .build = \"{}\",\n", .{std.zig.fmtEscapes(some)});
109113 }
110 out.writeAll("};\n") catch unreachable;
114 try out.writeAll("};\n");
111115 return;
112116 },
113117 else => {},
114118 }
115119 switch (@typeInfo(T)) {
116120 .Enum => |enum_info| {
117 out.print("pub const {} = enum {{\n", .{std.zig.fmtId(@typeName(T))}) catch unreachable;
121 try out.print("pub const {} = enum {{\n", .{std.zig.fmtId(@typeName(T))});
118122 inline for (enum_info.fields) |field| {
119 out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable;
123 try out.print(" {},\n", .{std.zig.fmtId(field.name)});
120124 }
121 out.writeAll("};\n") catch unreachable;
122 out.print("pub const {}: {s} = {s}.{s};\n", .{
125 try out.writeAll("};\n");
126 try out.print("pub const {}: {s} = {s}.{s};\n", .{
123127 std.zig.fmtId(name),
124128 std.zig.fmtId(@typeName(T)),
125129 std.zig.fmtId(@typeName(T)),
126130 std.zig.fmtId(@tagName(value)),
127 }) catch unreachable;
131 });
128132 return;
129133 },
130134 else => {},
131135 }
132 out.print("pub const {}: {s} = ", .{ std.zig.fmtId(name), @typeName(T) }) catch unreachable;
133 printLiteral(out, value, 0) catch unreachable;
134 out.writeAll(";\n") catch unreachable;
136 try out.print("pub const {}: {s} = ", .{ std.zig.fmtId(name), @typeName(T) });
137 try printLiteral(out, value, 0);
138 try out.writeAll(";\n");
135139}
136140
137141// TODO: non-recursive?
......@@ -189,14 +193,14 @@ pub fn addOptionFileSource(
189193 self.file_source_args.append(.{
190194 .name = name,
191195 .source = source.dupe(self.builder),
192 }) catch unreachable;
196 }) catch @panic("OOM");
193197 source.addStepDependencies(&self.step);
194198}
195199
196200/// The value is the path in the cache dir.
197201/// Adds a dependency automatically.
198202pub fn addOptionArtifact(self: *OptionsStep, name: []const u8, artifact: *CompileStep) void {
199 self.artifact_args.append(.{ .name = self.builder.dupe(name), .artifact = artifact }) catch unreachable;
203 self.artifact_args.append(.{ .name = self.builder.dupe(name), .artifact = artifact }) catch @panic("OOM");
200204 self.step.dependOn(&artifact.step);
201205}
202206
lib/std/Build/RunStep.zig+12-12
......@@ -54,7 +54,7 @@ pub const Arg = union(enum) {
5454};
5555
5656pub fn create(builder: *std.Build, name: []const u8) *RunStep {
57 const self = builder.allocator.create(RunStep) catch unreachable;
57 const self = builder.allocator.create(RunStep) catch @panic("OOM");
5858 self.* = RunStep{
5959 .builder = builder,
6060 .step = Step.init(base_id, name, builder.allocator, make),
......@@ -67,19 +67,19 @@ pub fn create(builder: *std.Build, name: []const u8) *RunStep {
6767}
6868
6969pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {
70 self.argv.append(Arg{ .artifact = artifact }) catch unreachable;
70 self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");
7171 self.step.dependOn(&artifact.step);
7272}
7373
7474pub fn addFileSourceArg(self: *RunStep, file_source: std.Build.FileSource) void {
7575 self.argv.append(Arg{
7676 .file_source = file_source.dupe(self.builder),
77 }) catch unreachable;
77 }) catch @panic("OOM");
7878 file_source.addStepDependencies(&self.step);
7979}
8080
8181pub fn addArg(self: *RunStep, arg: []const u8) void {
82 self.argv.append(Arg{ .bytes = self.builder.dupe(arg) }) catch unreachable;
82 self.argv.append(Arg{ .bytes = self.builder.dupe(arg) }) catch @panic("OOM");
8383}
8484
8585pub fn addArgs(self: *RunStep, args: []const []const u8) void {
......@@ -89,7 +89,7 @@ pub fn addArgs(self: *RunStep, args: []const []const u8) void {
8989}
9090
9191pub fn clearEnvironment(self: *RunStep) void {
92 const new_env_map = self.builder.allocator.create(EnvMap) catch unreachable;
92 const new_env_map = self.builder.allocator.create(EnvMap) catch @panic("OOM");
9393 new_env_map.* = EnvMap.init(self.builder.allocator);
9494 self.env_map = new_env_map;
9595}
......@@ -107,9 +107,9 @@ pub fn addPathDirInternal(step: *Step, builder: *std.Build, search_path: []const
107107
108108 if (prev_path) |pp| {
109109 const new_path = builder.fmt("{s}" ++ [1]u8{fs.path.delimiter} ++ "{s}", .{ pp, search_path });
110 env_map.put(key, new_path) catch unreachable;
110 env_map.put(key, new_path) catch @panic("OOM");
111111 } else {
112 env_map.put(key, builder.dupePath(search_path)) catch unreachable;
112 env_map.put(key, builder.dupePath(search_path)) catch @panic("OOM");
113113 }
114114}
115115
......@@ -124,8 +124,8 @@ fn getEnvMapInternal(step: *Step, allocator: Allocator) *EnvMap {
124124 else => unreachable,
125125 };
126126 return maybe_env_map orelse {
127 const env_map = allocator.create(EnvMap) catch unreachable;
128 env_map.* = process.getEnvMap(allocator) catch unreachable;
127 const env_map = allocator.create(EnvMap) catch @panic("OOM");
128 env_map.* = process.getEnvMap(allocator) catch @panic("unhandled error");
129129 switch (step.id) {
130130 .run => step.cast(RunStep).?.env_map = env_map,
131131 .emulatable_run => step.cast(RunStep).?.env_map = env_map,
......@@ -140,7 +140,7 @@ pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8
140140 env_map.put(
141141 self.builder.dupe(key),
142142 self.builder.dupe(value),
143 ) catch unreachable;
143 ) catch @panic("unhandled error");
144144}
145145
146146pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
......@@ -234,7 +234,7 @@ pub fn runCommand(
234234
235235 switch (stdout_action) {
236236 .expect_exact, .expect_matches => {
237 stdout = child.stdout.?.reader().readAllAlloc(builder.allocator, max_stdout_size) catch unreachable;
237 stdout = try child.stdout.?.reader().readAllAlloc(builder.allocator, max_stdout_size);
238238 },
239239 .inherit, .ignore => {},
240240 }
......@@ -244,7 +244,7 @@ pub fn runCommand(
244244
245245 switch (stderr_action) {
246246 .expect_exact, .expect_matches => {
247 stderr = child.stderr.?.reader().readAllAlloc(builder.allocator, max_stdout_size) catch unreachable;
247 stderr = try child.stderr.?.reader().readAllAlloc(builder.allocator, max_stdout_size);
248248 },
249249 .inherit, .ignore => {},
250250 }
lib/std/Build/Step.zig+2-2
......@@ -57,7 +57,7 @@ pub fn init(
5757) Step {
5858 return Step{
5959 .id = id,
60 .name = allocator.dupe(u8, name) catch unreachable,
60 .name = allocator.dupe(u8, name) catch @panic("OOM"),
6161 .makeFn = makeFn,
6262 .dependencies = std.ArrayList(*Step).init(allocator),
6363 .loop_flag = false,
......@@ -77,7 +77,7 @@ pub fn make(self: *Step) !void {
7777}
7878
7979pub fn dependOn(self: *Step, other: *Step) void {
80 self.dependencies.append(other) catch unreachable;
80 self.dependencies.append(other) catch @panic("OOM");
8181}
8282
8383fn makeNoOp(self: *Step) anyerror!void {
lib/std/Build/TranslateCStep.zig+6-6
......@@ -28,7 +28,7 @@ pub const Options = struct {
2828};
2929
3030pub fn create(builder: *std.Build, options: Options) *TranslateCStep {
31 const self = builder.allocator.create(TranslateCStep) catch unreachable;
31 const self = builder.allocator.create(TranslateCStep) catch @panic("OOM");
3232 const source = options.source_file.dupe(builder);
3333 self.* = TranslateCStep{
3434 .step = Step.init(.translate_c, "translate-c", builder.allocator, make),
......@@ -67,7 +67,7 @@ pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *Comp
6767}
6868
6969pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
70 self.include_dirs.append(self.builder.dupePath(include_dir)) catch unreachable;
70 self.include_dirs.append(self.builder.dupePath(include_dir)) catch @panic("OOM");
7171}
7272
7373pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {
......@@ -78,12 +78,12 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8)
7878/// `name` and `value` need not live longer than the function call.
7979pub fn defineCMacro(self: *TranslateCStep, name: []const u8, value: ?[]const u8) void {
8080 const macro = std.Build.constructCMacro(self.builder.allocator, name, value);
81 self.c_macros.append(macro) catch unreachable;
81 self.c_macros.append(macro) catch @panic("OOM");
8282}
8383
8484/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
8585pub fn defineCMacroRaw(self: *TranslateCStep, name_and_value: []const u8) void {
86 self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;
86 self.c_macros.append(self.builder.dupe(name_and_value)) catch @panic("OOM");
8787}
8888
8989fn make(step: *Step) !void {
......@@ -129,8 +129,8 @@ fn make(step: *Step) !void {
129129 self.output_dir = fs.path.dirname(output_path).?;
130130 }
131131
132 self.output_file.path = fs.path.join(
132 self.output_file.path = try fs.path.join(
133133 self.builder.allocator,
134134 &[_][]const u8{ self.output_dir.?, self.out_basename },
135 ) catch unreachable;
135 );
136136}
lib/std/Build/WriteFileStep.zig+3-3
......@@ -28,7 +28,7 @@ pub fn init(builder: *std.Build) WriteFileStep {
2828}
2929
3030pub fn add(self: *WriteFileStep, basename: []const u8, bytes: []const u8) void {
31 const node = self.builder.allocator.create(std.TailQueue(File).Node) catch unreachable;
31 const node = self.builder.allocator.create(std.TailQueue(File).Node) catch @panic("unhandled error");
3232 node.* = .{
3333 .data = .{
3434 .source = std.Build.GeneratedFile{ .step = &self.step },
......@@ -106,10 +106,10 @@ fn make(step: *Step) !void {
106106 });
107107 return err;
108108 };
109 node.data.source.path = fs.path.join(
109 node.data.source.path = try fs.path.join(
110110 self.builder.allocator,
111111 &[_][]const u8{ self.output_dir, node.data.basename },
112 ) catch unreachable;
112 );
113113 }
114114 }
115115}