Commit 373e53d7c5

kcbanner <kcbanner@gmail.com>
2024-07-14 01:04:55
Compile: Pass the default --zig-lib-dir along to child processes main: print the self_exe_path when `findZigLibDirFromSelfExe` fails in all cases
1 parent bc28454
Changed files (2)
lib
std
Build
src
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);
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;