authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:48:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
log779b6cc63cbf1ab0f132996506a238eae72dcbf9
treee42c3573b14e21ceec05c9360d63dc9325a60a0e
parentfc7924d393c909fef785614b8273e719398db2c1

Maker: partially implement configurer cache invalidation

progress towards #35473

7 files changed, 78 insertions(+), 34 deletions(-)

build.zig+1-1
...@@ -268,7 +268,7 @@ pub fn build(b: *std.Build) !void {...@@ -268,7 +268,7 @@ pub fn build(b: *std.Build) !void {
268 }268 }
269269
270 // Ensure git version changes get picked up.270 // Ensure git version changes get picked up.
271 b.dependOnFileContents(b.graph.path(.build_root, ".git/HEAD"));271 b.dependOnFileContents(b.path(".git/HEAD"));
272272
273 const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch });273 const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch });
274274
lib/compiler/Maker.zig+50-11
...@@ -1318,7 +1318,11 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1318,7 +1318,11 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1318 }1318 }
13191319
1320 for (configuration.path_deps) |path_dep| {1320 for (configuration.path_deps) |path_dep| {
1321 try config_man.addPathPost(path_dep.toCachePath(&configuration, arena));1321 switch (path_dep.flags.mode) {
1322 .directory => {}, // TODO
1323 .contents => try config_man.addPathPost(confPathDepToCachePath(graph, &configuration, path_dep)),
1324 .metadata => {}, // TODO
1325 }
1322 }1326 }
13231327
1324 // If it is poisoned, there is no point in moving it to cached1328 // If it is poisoned, there is no point in moving it to cached
...@@ -1825,7 +1829,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {...@@ -1825,7 +1829,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {
1825 return process.cleanExit(io);1829 return process.cleanExit(io);
1826 },1830 },
1827 .minimal => {1831 .minimal => {
1828 writeSimpleTemplateFile(io, Package.Manifest.basename,1832 Templates.writeSimpleFile(io, Package.Manifest.basename,
1829 \\.{{1833 \\.{{
1830 \\ .name = .{s},1834 \\ .name = .{s},
1831 \\ .version = "0.0.1",1835 \\ .version = "0.0.1",
...@@ -1842,7 +1846,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {...@@ -1842,7 +1846,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void {
1842 else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }),1846 else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }),
1843 error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}),1847 error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}),
1844 };1848 };
1845 writeSimpleTemplateFile(io, default_build_zig_basename,1849 Templates.writeSimpleFile(io, default_build_zig_basename,
1846 \\const std = @import("std");1850 \\const std = @import("std");
1847 \\1851 \\
1848 \\pub fn build(b: *std.Build) void {{1852 \\pub fn build(b: *std.Build) void {{
...@@ -3498,7 +3502,7 @@ fn loadManifest(...@@ -3498,7 +3502,7 @@ fn loadManifest(
3498 0,3502 0,
3499 ) catch |err| switch (err) {3503 ) catch |err| switch (err) {
3500 error.FileNotFound => {3504 error.FileNotFound => {
3501 writeSimpleTemplateFile(io, Package.Manifest.basename,3505 Templates.writeSimpleFile(io, Package.Manifest.basename,
3502 \\.{{3506 \\.{{
3503 \\ .name = .{s},3507 \\ .name = .{s},
3504 \\ .version = "{s}",3508 \\ .version = "{s}",
...@@ -3658,12 +3662,47 @@ const Templates = struct {...@@ -3658,12 +3662,47 @@ const Templates = struct {
3658 .buffer = std.array_list.Managed(u8).init(gpa),3662 .buffer = std.array_list.Managed(u8).init(gpa),
3659 };3663 };
3660 }3664 }
3665
3666 fn writeSimpleFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void {
3667 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
3668 defer f.close(io);
3669 var buf: [4096]u8 = undefined;
3670 var fw = f.writer(io, &buf);
3671 try fw.interface.print(format, args);
3672 try fw.interface.flush();
3673 }
3661};3674};
3662fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void {3675
3663 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });3676fn confPathDepToCachePath(graph: *const Graph, c: *const Configuration, path_dep: Configuration.PathDep) Path {
3664 defer f.close(io);3677 const sub_path = path_dep.sub.slice(c);
3665 var buf: [4096]u8 = undefined;3678 return switch (path_dep.flags.base) {
3666 var fw = f.writer(io, &buf);3679 .cwd => .{
3667 try fw.interface.print(format, args);3680 .root_dir = .cwd(),
3668 try fw.interface.flush();3681 .sub_path = sub_path,
3682 },
3683 .local_cache => .{
3684 .root_dir = graph.local_cache_root,
3685 .sub_path = sub_path,
3686 },
3687 .global_cache => .{
3688 .root_dir = graph.global_cache_root,
3689 .sub_path = sub_path,
3690 },
3691 .build_root => .{
3692 .root_dir = switch (path_dep.pkg.unwrap().?) {
3693 .root => graph.build_root_directory,
3694 _ => @panic("TODO"),
3695 },
3696 .sub_path = sub_path,
3697 },
3698 .zig_lib => .{
3699 .root_dir = graph.zig_lib_directory,
3700 .sub_path = sub_path,
3701 },
3702 .zig_exe => @panic("TODO"),
3703 .install_prefix => @panic("TODO"),
3704 .install_lib => @panic("TODO"),
3705 .install_bin => @panic("TODO"),
3706 .install_include => @panic("TODO"),
3707 };
3669}3708}
lib/compiler/Maker/Graph.zig-1
...@@ -4,7 +4,6 @@ const Graph = @This();...@@ -4,7 +4,6 @@ const Graph = @This();
4const std = @import("std");4const std = @import("std");
5const Io = std.Io;5const Io = std.Io;
6const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
7const Configuration = std.Build.Configuration;
8const Path = std.Build.Cache.Path;7const Path = std.Build.Cache.Path;
9const Directory = std.Build.Cache.Directory;8const Directory = std.Build.Cache.Directory;
109
lib/compiler/configurer.zig+2-3
...@@ -633,8 +633,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -633,8 +633,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
633 var s: Serialize = .{ .wc = wc, .arena = arena };633 var s: Serialize = .{ .wc = wc, .arena = arena };
634634
635 try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len);635 try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len);
636 // TODO remove this636 for (
637 if (false) for (
638 graph.configure_dependencies.items,637 graph.configure_dependencies.items,
639 wc.path_deps.addManyAsSliceAssumeCapacity(graph.configure_dependencies.items.len),638 wc.path_deps.addManyAsSliceAssumeCapacity(graph.configure_dependencies.items.len),
640 ) |src, *dest| {639 ) |src, *dest| {
...@@ -662,7 +661,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -662,7 +661,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
662 .dependency => |d| .init(try s.builderToPackage(d.dependency.builder)),661 .dependency => |d| .init(try s.builderToPackage(d.dependency.builder)),
663 },662 },
664 };663 };
665 };664 }
666665
667 // Starting from all top-level steps in `b`, traverse the entire step graph666 // Starting from all top-level steps in `b`, traverse the entire step graph
668 // and add all step dependencies implied by module graphs.667 // and add all step dependencies implied by module graphs.
lib/std/Build.zig+1
...@@ -177,6 +177,7 @@ pub const Graph = struct {...@@ -177,6 +177,7 @@ pub const Graph = struct {
177 /// A path whose components and contents are known at some point during177 /// A path whose components and contents are known at some point during
178 /// `Step` resolution, relative to the provided base directory.178 /// `Step` resolution, relative to the provided base directory.
179 pub fn path(graph: *Graph, base: Configuration.LazyPath.Relative.Base, sub_path: []const u8) LazyPath {179 pub fn path(graph: *Graph, base: Configuration.LazyPath.Relative.Base, sub_path: []const u8) LazyPath {
180 assert(base != .build_root);
180 return .{ .relative = .{181 return .{ .relative = .{
181 .base = base,182 .base = base,
182 .sub_path = @This().dupePath(graph, sub_path),183 .sub_path = @This().dupePath(graph, sub_path),
lib/std/Build/Cache.zig+23-11
...@@ -70,6 +70,15 @@ pub const PrefixedPath = struct {...@@ -70,6 +70,15 @@ pub const PrefixedPath = struct {
70 }70 }
71};71};
7272
73fn findPrefixPath(cache: *const Cache, path: Path) !PrefixedPath {
74 const gpa = cache.gpa;
75 const resolved_path = try std.fs.path.resolve(gpa, &.{
76 cache.cwd, path.root_dir.path orelse ".", path.subPathOrDot(),
77 });
78 errdefer gpa.free(resolved_path);
79 return findPrefixResolved(cache, resolved_path);
80}
81
73fn findPrefix(cache: *const Cache, file_path: []const u8) !PrefixedPath {82fn findPrefix(cache: *const Cache, file_path: []const u8) !PrefixedPath {
74 const gpa = cache.gpa;83 const gpa = cache.gpa;
75 const resolved_path = try std.fs.path.resolve(gpa, &.{file_path});84 const resolved_path = try std.fs.path.resolve(gpa, &.{file_path});
...@@ -998,13 +1007,22 @@ pub const Manifest = struct {...@@ -998,13 +1007,22 @@ pub const Manifest = struct {
998 /// This is useful for processes that don't know the all the files that are1007 /// This is useful for processes that don't know the all the files that are
999 /// depended on ahead of time. For example, a source file that can import1008 /// depended on ahead of time. For example, a source file that can import
1000 /// other files will need to be recompiled if the imported file is changed.1009 /// other files will need to be recompiled if the imported file is changed.
1001 pub fn addFilePost(self: *Manifest, file_path: []const u8) !void {1010 pub fn addFilePost(man: *Manifest, file_path: []const u8) !void {
1002 assert(self.manifest_file != null);1011 assert(man.manifest_file != null);
1003 const gpa = self.cache.gpa;1012 const gpa = man.cache.gpa;
1004 const prefixed_path = try self.cache.findPrefix(file_path);1013 const prefixed_path = try man.cache.findPrefix(file_path);
1005 var keep = false;1014 var keep = false;
1006 defer if (!keep) gpa.free(prefixed_path.sub_path);1015 defer if (!keep) gpa.free(prefixed_path.sub_path);
1007 keep = try addPrefixedPathPost(self, prefixed_path);1016 keep = try addPrefixedPathPost(man, prefixed_path);
1017 }
1018
1019 pub fn addPathPost(man: *Manifest, path: Path) !void {
1020 assert(man.manifest_file != null);
1021 const gpa = man.cache.gpa;
1022 const prefixed_path: PrefixedPath = try man.cache.findPrefixPath(path);
1023 var keep = false;
1024 defer if (!keep) gpa.free(prefixed_path.sub_path);
1025 keep = try addPrefixedPathPost(man, prefixed_path);
1008 }1026 }
10091027
1010 /// Low level function. `prefixed_path` references cloned memory. Returns1028 /// Low level function. `prefixed_path` references cloned memory. Returns
...@@ -1034,12 +1052,6 @@ pub const Manifest = struct {...@@ -1034,12 +1052,6 @@ pub const Manifest = struct {
1034 return true;1052 return true;
1035 }1053 }
10361054
1037 pub fn addPathPost(man: *Manifest, path: Path) !void {
1038 _ = man;
1039 _ = path;
1040 std.log.err("TODO Build.Cache.addPathPost", .{});
1041 }
1042
1043 /// Like `addFilePost` but when the file contents have already been loaded from disk.1055 /// Like `addFilePost` but when the file contents have already been loaded from disk.
1044 pub fn addFilePostContents(1056 pub fn addFilePostContents(
1045 self: *Manifest,1057 self: *Manifest,
lib/std/Build/Configuration.zig+1-7
...@@ -1557,6 +1557,7 @@ pub const LazyPath = union(@This().Tag) {...@@ -1557,6 +1557,7 @@ pub const LazyPath = union(@This().Tag) {
1557 cwd,1557 cwd,
1558 local_cache,1558 local_cache,
1559 global_cache,1559 global_cache,
1560 /// Must not be used with Relative since package index is missing.
1560 build_root,1561 build_root,
1561 zig_exe,1562 zig_exe,
1562 zig_lib,1563 zig_lib,
...@@ -1876,13 +1877,6 @@ pub const PathDep = extern struct {...@@ -1876,13 +1877,6 @@ pub const PathDep = extern struct {
1876 };1877 };
18771878
1878 pub const Mode = enum(u8) { directory, contents, metadata };1879 pub const Mode = enum(u8) { directory, contents, metadata };
1879
1880 pub fn toCachePath(path: PathDep, c: *const Configuration, arena: Allocator) std.Build.Cache.Path {
1881 _ = c;
1882 _ = arena;
1883 _ = path;
1884 if (true) @panic("TODO Configuration.PathDep.toCachePath");
1885 }
1886};1880};
18871881
1888pub const InstallDestDir = enum(u32) {1882pub const InstallDestDir = enum(u32) {