authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-20 11:32:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-20 16:38:05-07:00
logf887bea4d34da6e4dcfdf1eb18cca6afca3dc546
treefee4c27f9b7c2eec84303e0d4ac01ce7efec439d
parent5586a1f4eef7103398c595aed451157a07d15e27

fix overridden pkg dir path

the previous code made it relative to the build directory also add a corresponding env var and logic for build command

2 files changed, 14 insertions(+), 4 deletions(-)

lib/std/zig.zig+1
...@@ -744,6 +744,7 @@ pub fn parseTargetQueryOrReportFatalError(...@@ -744,6 +744,7 @@ pub fn parseTargetQueryOrReportFatalError(
744pub const EnvVar = enum {744pub const EnvVar = enum {
745 ZIG_GLOBAL_CACHE_DIR,745 ZIG_GLOBAL_CACHE_DIR,
746 ZIG_LOCAL_CACHE_DIR,746 ZIG_LOCAL_CACHE_DIR,
747 ZIG_LOCAL_PKG_DIR,
747 ZIG_LIB_DIR,748 ZIG_LIB_DIR,
748 ZIG_LIBC,749 ZIG_LIBC,
749 ZIG_BUILD_RUNNER,750 ZIG_BUILD_RUNNER,
src/main.zig+13-4
...@@ -4958,6 +4958,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -4958,6 +4958,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
4958 var override_lib_dir: ?[]const u8 = EnvVar.ZIG_LIB_DIR.get(environ_map);4958 var override_lib_dir: ?[]const u8 = EnvVar.ZIG_LIB_DIR.get(environ_map);
4959 var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map);4959 var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map);
4960 var override_local_cache_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_CACHE_DIR.get(environ_map);4960 var override_local_cache_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_CACHE_DIR.get(environ_map);
4961 var override_pkg_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_PKG_DIR.get(environ_map);
4961 var override_build_runner: ?[]const u8 = EnvVar.ZIG_BUILD_RUNNER.get(environ_map);4962 var override_build_runner: ?[]const u8 = EnvVar.ZIG_BUILD_RUNNER.get(environ_map);
4962 var child_argv: std.ArrayList([]const u8) = .empty;4963 var child_argv: std.ArrayList([]const u8) = .empty;
4963 var forks: std.ArrayList(Fork) = .empty;4964 var forks: std.ArrayList(Fork) = .empty;
...@@ -5048,6 +5049,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5048,6 +5049,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5048 i += 1;5049 i += 1;
5049 override_local_cache_dir = args[i];5050 override_local_cache_dir = args[i];
5050 continue;5051 continue;
5052 } else if (mem.eql(u8, arg, "--pkg-dir")) {
5053 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
5054 i += 1;
5055 override_pkg_dir = args[i];
5056 continue;
5051 } else if (mem.eql(u8, arg, "--global-cache-dir")) {5057 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
5052 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});5058 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
5053 i += 1;5059 i += 1;
...@@ -5340,7 +5346,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5340,7 +5346,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5340 .http_client = &http_client,5346 .http_client = &http_client,
5341 .global_cache = dirs.global_cache,5347 .global_cache = dirs.global_cache,
5342 .local_cache = .{ .root_dir = dirs.local_cache, .sub_path = "" },5348 .local_cache = .{ .root_dir = dirs.local_cache, .sub_path = "" },
5343 .root_pkg_path = .{ .root_dir = build_root.directory, .sub_path = "zig-pkg" },5349 .root_pkg_path = if (override_pkg_dir) |cwd_rel_path| .initCwd(cwd_rel_path) else .{
5350 .root_dir = build_root.directory,
5351 .sub_path = "zig-pkg",
5352 },
5344 .read_only = false,5353 .read_only = false,
5345 .recursive = true,5354 .recursive = true,
5346 .debug_hash = false,5355 .debug_hash = false,
...@@ -7053,7 +7062,7 @@ fn cmdFetch(...@@ -7053,7 +7062,7 @@ fn cmdFetch(
7053 const color: Color = .auto;7062 const color: Color = .auto;
7054 var opt_path_or_url: ?[]const u8 = null;7063 var opt_path_or_url: ?[]const u8 = null;
7055 var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map);7064 var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map);
7056 var override_pkg_dir: ?[]const u8 = null;7065 var override_pkg_dir: ?[]const u8 = EnvVar.ZIG_LOCAL_PKG_DIR.get(environ_map);
7057 var debug_hash: bool = false;7066 var debug_hash: bool = false;
7058 var save: union(enum) {7067 var save: union(enum) {
7059 no,7068 no,
...@@ -7136,9 +7145,9 @@ fn cmdFetch(...@@ -7136,9 +7145,9 @@ fn cmdFetch(
7136 .http_client = &http_client,7145 .http_client = &http_client,
7137 .global_cache = global_cache_directory,7146 .global_cache = global_cache_directory,
7138 .local_cache = local_cache_path,7147 .local_cache = local_cache_path,
7139 .root_pkg_path = .{7148 .root_pkg_path = if (override_pkg_dir) |cwd_rel_path| .initCwd(cwd_rel_path) else .{
7140 .root_dir = build_root.directory,7149 .root_dir = build_root.directory,
7141 .sub_path = override_pkg_dir orelse "zig-pkg",7150 .sub_path = "zig-pkg",
7142 },7151 },
7143 .recursive = false,7152 .recursive = false,
7144 .read_only = false,7153 .read_only = false,