authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-04 14:00:15-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-10-04 14:00:15-07:00
log9fca80941cd3f7dfd46157413a760dda5716f91a
tree08ea6034f1fa8619cddd8c60daa72cb58cccea68
parent7c74edec8d7d97677033d8a688e02ee32d82ab43
parente0fdbfb705d1c8184eb3664e1d540f90031f7dd5
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21532 from marler8997/putDependencyCacheInGraph

Put dependency cache in graph

1 files changed, 6 insertions(+), 12 deletions(-)

lib/std/Build.zig+6-12
......@@ -90,9 +90,6 @@ modules: std.StringArrayHashMap(*Module),
9090
9191named_writefiles: std.StringArrayHashMap(*Step.WriteFile),
9292named_lazy_paths: std.StringArrayHashMap(LazyPath),
93/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child
94/// `Build`s.
95initialized_deps: *InitializedDepMap,
9693/// The hash of this instance's package. `""` means that this is the root package.
9794pkg_hash: []const u8,
9895/// A mapping from dependency names to package hashes.
......@@ -125,6 +122,7 @@ pub const Graph = struct {
125122 host: ResolvedTarget,
126123 incremental: ?bool = null,
127124 random_seed: u32 = 0,
125 dependency_cache: InitializedDepMap = .empty,
128126};
129127
130128const AvailableDeps = []const struct { []const u8, []const u8 };
......@@ -144,7 +142,7 @@ const SystemLibraryMode = enum {
144142 declared_enabled,
145143};
146144
147const InitializedDepMap = std.HashMap(InitializedDepKey, *Dependency, InitializedDepContext, std.hash_map.default_max_load_percentage);
145const InitializedDepMap = std.HashMapUnmanaged(InitializedDepKey, *Dependency, InitializedDepContext, std.hash_map.default_max_load_percentage);
148146const InitializedDepKey = struct {
149147 build_root_string: []const u8,
150148 user_input_options: UserInputOptionsMap,
......@@ -252,8 +250,6 @@ pub fn create(
252250 available_deps: AvailableDeps,
253251) !*Build {
254252 const arena = graph.arena;
255 const initialized_deps = try arena.create(InitializedDepMap);
256 initialized_deps.* = InitializedDepMap.initContext(arena, .{ .allocator = arena });
257253
258254 const b = try arena.create(Build);
259255 b.* = .{
......@@ -304,7 +300,6 @@ pub fn create(
304300 .modules = .init(arena),
305301 .named_writefiles = .init(arena),
306302 .named_lazy_paths = .init(arena),
307 .initialized_deps = initialized_deps,
308303 .pkg_hash = "",
309304 .available_deps = available_deps,
310305 .release_mode = .off,
......@@ -398,7 +393,6 @@ fn createChildOnly(
398393 .modules = .init(allocator),
399394 .named_writefiles = .init(allocator),
400395 .named_lazy_paths = .init(allocator),
401 .initialized_deps = parent.initialized_deps,
402396 .pkg_hash = pkg_hash,
403397 .available_deps = pkg_deps,
404398 .release_mode = parent.release_mode,
......@@ -2127,10 +2121,10 @@ fn dependencyInner(
21272121 args: anytype,
21282122) *Dependency {
21292123 const user_input_options = userInputOptionsFromArgs(b.allocator, args);
2130 if (b.initialized_deps.get(.{
2124 if (b.graph.dependency_cache.getContext(.{
21312125 .build_root_string = build_root_string,
21322126 .user_input_options = user_input_options,
2133 })) |dep|
2127 }, .{ .allocator = b.graph.arena })) |dep|
21342128 return dep;
21352129
21362130 const build_root: std.Build.Cache.Directory = .{
......@@ -2155,10 +2149,10 @@ fn dependencyInner(
21552149 const dep = b.allocator.create(Dependency) catch @panic("OOM");
21562150 dep.* = .{ .builder = sub_builder };
21572151
2158 b.initialized_deps.put(.{
2152 b.graph.dependency_cache.putContext(b.graph.arena, .{
21592153 .build_root_string = build_root_string,
21602154 .user_input_options = user_input_options,
2161 }, dep) catch @panic("OOM");
2155 }, dep, .{ .allocator = b.graph.arena }) catch @panic("OOM");
21622156 return dep;
21632157}
21642158