From 5586a1f4eef7103398c595aed451157a07d15e27 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 18 Apr 2026 20:58:45 +0200 Subject: [PATCH] zig fetch: add option to overwrite the package directory --- src/main.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index a43eb44334186ee610da835ae0f4396bace053a7..4ca73ff06ae538702cb3b3d77c5366e49a298a0e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7032,6 +7032,7 @@ const usage_fetch = \\Options: \\ -h, --help Print this help and exit \\ --global-cache-dir [path] Override path to global Zig cache directory + \\ --pkg-dir [path] Override path to package directory \\ --debug-hash Print verbose hash information to stdout \\ --save Add the fetched package to build.zig.zon \\ --save=[name] Add the fetched package to build.zig.zon as name @@ -7052,6 +7053,7 @@ fn cmdFetch( const color: Color = .auto; var opt_path_or_url: ?[]const u8 = null; var override_global_cache_dir: ?[]const u8 = EnvVar.ZIG_GLOBAL_CACHE_DIR.get(environ_map); + var override_pkg_dir: ?[]const u8 = null; var debug_hash: bool = false; var save: union(enum) { no, @@ -7071,6 +7073,10 @@ fn cmdFetch( if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); i += 1; override_global_cache_dir = args[i]; + } else if (mem.eql(u8, arg, "--pkg-dir")) { + if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); + i += 1; + override_pkg_dir = args[i]; } else if (mem.eql(u8, arg, "--debug-hash")) { debug_hash = true; } else if (mem.eql(u8, arg, "--save")) { @@ -7132,7 +7138,7 @@ fn cmdFetch( .local_cache = local_cache_path, .root_pkg_path = .{ .root_dir = build_root.directory, - .sub_path = "zig-pkg", + .sub_path = override_pkg_dir orelse "zig-pkg", }, .recursive = false, .read_only = false, -- 2.54.0