| author | |
| committer | |
| log | 27c1f2b3a04960d9e8701f420560cc53e8e5f1dd |
| tree | 26c93802f5ede792cb5c1111e8b270a777b5d9d2 |
| parent | b4b1daf0012c3007b762df31028fa35f5f68bd09 |
`--fetch` flag now has additional optional parameter, which specifies
how lazy dependencies should be fetched:
* `needed` — lazy dependencies are fetched only if they are required
for current build configuration to work. Default and works same
as old `--fetch` flag.
* `all` — lazy dependencies are always fetched. If `--system` flag
is used after that, it's guaranteed that **any** build configuration
will not require additional download of dependencies during build.
Helpful for distro packagers and CI systems:
https://www.github.com/ziglang/zig/issues/14597#issuecomment-1426827495
If none is passed, behaviour is same as if `needed` was passed.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>3 files changed, 26 insertions(+), 2 deletions(-)
lib/compiler/build_runner.zig+3-1| ... | ... | @@ -1293,7 +1293,9 @@ fn usage(b: *std.Build, out_stream: anytype) !void { |
| 1293 | 1293 | \\ -j<N> Limit concurrent jobs (default is to use all CPU cores) |
| 1294 | 1294 | \\ --maxrss <bytes> Limit memory usage (default is to use available memory) |
| 1295 | 1295 | \\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss |
| 1296 | \\ --fetch Exit after fetching dependency tree | |
| 1296 | \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit | |
| 1297 | \\ needed (Default) Lazy dependencies are fetched as needed | |
| 1298 | \\ all Lazy dependencies are always fetched | |
| 1297 | 1299 | \\ --watch Continuously rebuild when source files are modified |
| 1298 | 1300 | \\ --fuzz Continuously search for unit test failures |
| 1299 | 1301 | \\ --debounce <ms> Delay before rebuilding after changed file detected |
src/Package/Fetch.zig+13-1| ... | ... | @@ -114,10 +114,18 @@ pub const JobQueue = struct { |
| 114 | 114 | /// If this is true, `recursive` must be false. |
| 115 | 115 | debug_hash: bool, |
| 116 | 116 | work_around_btrfs_bug: bool, |
| 117 | mode: Mode, | |
| 117 | 118 | /// Set of hashes that will be additionally fetched even if they are marked |
| 118 | 119 | /// as lazy. |
| 119 | 120 | unlazy_set: UnlazySet = .{}, |
| 120 | 121 | |
| 122 | pub const Mode = enum { | |
| 123 | /// Non-lazy dependencies are always fetched. | |
| 124 | /// Lazy dependencies are fetched only when needed. | |
| 125 | needed, | |
| 126 | /// Both non-lazy and lazy dependencies are always fetched. | |
| 127 | all, | |
| 128 | }; | |
| 121 | 129 | pub const Table = std.AutoArrayHashMapUnmanaged(Package.Hash, *Fetch); |
| 122 | 130 | pub const UnlazySet = std.AutoArrayHashMapUnmanaged(Package.Hash, void); |
| 123 | 131 | |
| ... | ... | @@ -754,7 +762,10 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { |
| 754 | 762 | .location_tok = dep.location_tok, |
| 755 | 763 | .hash_tok = dep.hash_tok, |
| 756 | 764 | .name_tok = dep.name_tok, |
| 757 | .lazy_status = if (dep.lazy) .available else .eager, | |
| 765 | .lazy_status = switch (f.job_queue.mode) { | |
| 766 | .needed => if (dep.lazy) .available else .eager, | |
| 767 | .all => .eager, | |
| 768 | }, | |
| 758 | 769 | .parent_package_root = f.package_root, |
| 759 | 770 | .parent_manifest_ast = &f.manifest_ast, |
| 760 | 771 | .prog_node = f.prog_node, |
| ... | ... | @@ -2325,6 +2336,7 @@ const TestFetchBuilder = struct { |
| 2325 | 2336 | .read_only = false, |
| 2326 | 2337 | .debug_hash = false, |
| 2327 | 2338 | .work_around_btrfs_bug = false, |
| 2339 | .mode = .needed, | |
| 2328 | 2340 | }; |
| 2329 | 2341 | |
| 2330 | 2342 | self.fetch = .{ |
src/main.zig+10| ... | ... | @@ -4843,6 +4843,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4843 | 4843 | var verbose_cimport = false; |
| 4844 | 4844 | var verbose_llvm_cpu_features = false; |
| 4845 | 4845 | var fetch_only = false; |
| 4846 | var fetch_mode: Package.Fetch.JobQueue.Mode = .needed; | |
| 4846 | 4847 | var system_pkg_dir_path: ?[]const u8 = null; |
| 4847 | 4848 | var debug_target: ?[]const u8 = null; |
| 4848 | 4849 | |
| ... | ... | @@ -4924,6 +4925,13 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4924 | 4925 | reference_trace = 256; |
| 4925 | 4926 | } else if (mem.eql(u8, arg, "--fetch")) { |
| 4926 | 4927 | fetch_only = true; |
| 4928 | } else if (mem.startsWith(u8, arg, "--fetch=")) { | |
| 4929 | fetch_only = true; | |
| 4930 | const sub_arg = arg["--fetch=".len..]; | |
| 4931 | fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse | |
| 4932 | fatal("expected [needed|all] after '--fetch=', found '{s}'", .{ | |
| 4933 | sub_arg, | |
| 4934 | }); | |
| 4927 | 4935 | } else if (mem.eql(u8, arg, "--system")) { |
| 4928 | 4936 | if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); |
| 4929 | 4937 | i += 1; |
| ... | ... | @@ -5208,6 +5216,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5208 | 5216 | .debug_hash = false, |
| 5209 | 5217 | .work_around_btrfs_bug = work_around_btrfs_bug, |
| 5210 | 5218 | .unlazy_set = unlazy_set, |
| 5219 | .mode = fetch_mode, | |
| 5211 | 5220 | }; |
| 5212 | 5221 | defer job_queue.deinit(); |
| 5213 | 5222 | |
| ... | ... | @@ -7130,6 +7139,7 @@ fn cmdFetch( |
| 7130 | 7139 | .read_only = false, |
| 7131 | 7140 | .debug_hash = debug_hash, |
| 7132 | 7141 | .work_around_btrfs_bug = work_around_btrfs_bug, |
| 7142 | .mode = .all, | |
| 7133 | 7143 | }; |
| 7134 | 7144 | defer job_queue.deinit(); |
| 7135 | 7145 |