| ... | ... | @@ -124,6 +124,9 @@ host: NativeTargetInfo, |
| 124 | 124 | dep_prefix: []const u8 = "", |
| 125 | 125 | |
| 126 | 126 | modules: std.StringArrayHashMap(*Module), |
| 127 | /// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child |
| 128 | /// `Build`s. |
| 129 | initialized_deps: *std.StringHashMap(*Dependency), |
| 127 | 130 | |
| 128 | 131 | pub const ExecError = error{ |
| 129 | 132 | ReadFailure, |
| ... | ... | @@ -209,6 +212,9 @@ pub fn create( |
| 209 | 212 | const env_map = try allocator.create(EnvMap); |
| 210 | 213 | env_map.* = try process.getEnvMap(allocator); |
| 211 | 214 | |
| 215 | const initialized_deps = try allocator.create(std.StringHashMap(*Dependency)); |
| 216 | initialized_deps.* = std.StringHashMap(*Dependency).init(allocator); |
| 217 | |
| 212 | 218 | const self = try allocator.create(Build); |
| 213 | 219 | self.* = .{ |
| 214 | 220 | .zig_exe = zig_exe, |
| ... | ... | @@ -261,6 +267,7 @@ pub fn create( |
| 261 | 267 | .args = null, |
| 262 | 268 | .host = host, |
| 263 | 269 | .modules = std.StringArrayHashMap(*Module).init(allocator), |
| 270 | .initialized_deps = initialized_deps, |
| 264 | 271 | }; |
| 265 | 272 | try self.top_level_steps.put(allocator, self.install_tls.step.name, &self.install_tls); |
| 266 | 273 | try self.top_level_steps.put(allocator, self.uninstall_tls.step.name, &self.uninstall_tls); |
| ... | ... | @@ -345,6 +352,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc |
| 345 | 352 | .host = parent.host, |
| 346 | 353 | .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }), |
| 347 | 354 | .modules = std.StringArrayHashMap(*Module).init(allocator), |
| 355 | .initialized_deps = parent.initialized_deps, |
| 348 | 356 | }; |
| 349 | 357 | try child.top_level_steps.put(allocator, child.install_tls.step.name, &child.install_tls); |
| 350 | 358 | try child.top_level_steps.put(allocator, child.uninstall_tls.step.name, &child.uninstall_tls); |
| ... | ... | @@ -1560,6 +1568,11 @@ pub fn dependencyInner( |
| 1560 | 1568 | comptime build_zig: type, |
| 1561 | 1569 | args: anytype, |
| 1562 | 1570 | ) *Dependency { |
| 1571 | if (b.initialized_deps.get(build_root_string)) |dep| { |
| 1572 | // TODO: check args are the same |
| 1573 | return dep; |
| 1574 | } |
| 1575 | |
| 1563 | 1576 | const build_root: std.Build.Cache.Directory = .{ |
| 1564 | 1577 | .path = build_root_string, |
| 1565 | 1578 | .handle = std.fs.cwd().openDir(build_root_string, .{}) catch |err| { |
| ... | ... | @@ -1578,6 +1591,9 @@ pub fn dependencyInner( |
| 1578 | 1591 | |
| 1579 | 1592 | const dep = b.allocator.create(Dependency) catch @panic("OOM"); |
| 1580 | 1593 | dep.* = .{ .builder = sub_builder }; |
| 1594 | |
| 1595 | b.initialized_deps.put(build_root_string, dep) catch @panic("OOM"); |
| 1596 | |
| 1581 | 1597 | return dep; |
| 1582 | 1598 | } |
| 1583 | 1599 | |