From 373e53d7c5940c875a3423a6797f7b5d4a7f36c8 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Sat, 13 Jul 2024 19:04:55 -0400 Subject: [PATCH] Compile: Pass the default --zig-lib-dir along to child processes main: print the self_exe_path when `findZigLibDirFromSelfExe` fails in all cases --- lib/std/Build/Step/Compile.zig | 11 +++++++++-- src/main.zig | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 504025e3d4..89862e7501 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -1635,9 +1635,16 @@ fn getZigArgs(compile: *Compile) ![][]const u8 { }); } - if (compile.zig_lib_dir) |dir| { + const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir| + dir.getPath2(b, step) + else if (b.graph.zig_lib_directory.path) |_| + b.fmt("{}", .{b.graph.zig_lib_directory}) + else + null; + + if (opt_zig_lib_dir) |zig_lib_dir| { try zig_args.append("--zig-lib-dir"); - try zig_args.append(dir.getPath2(b, step)); + try zig_args.append(zig_lib_dir); } try addFlag(&zig_args, "PIE", compile.pie); diff --git a/src/main.zig b/src/main.zig index 39f07e982b..6ccf4f50be 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2710,7 +2710,7 @@ fn buildOutputType( break :d getWasiPreopen("/lib"); } else if (self_exe_path) |p| { break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| { - fatal("unable to find zig installation directory: {s}", .{@errorName(err)}); + fatal("unable to find zig installation directory '{s}': {s}", .{ p, @errorName(err) }); }; } else { unreachable; @@ -7403,7 +7403,7 @@ fn findTemplates(gpa: Allocator, arena: Allocator) Templates { fatal("unable to find self exe path: {s}", .{@errorName(err)}); }; var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| { - fatal("unable to find zig installation directory: {s}", .{@errorName(err)}); + fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) }); }; const s = fs.path.sep_str;