authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-09 21:16:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:14-07:00
log59f5df3af9c31ffef33862c15bcbce6b4227ff1f
treea6321812881b388d68b74cecafde3eb48f21654e
parent29cfd47d6509fc6ee1a165b3bc03180f6cf351a5

std.Build: use Cache hash helper for package prefix dirs

Previously this code used SipHash(1, 3) directly; now that we have the cache system available in the build system, borrow the same implementation as is being used everywhere else.

1 files changed, 8 insertions(+), 11 deletions(-)

lib/std/Build.zig+8-11
...@@ -384,20 +384,17 @@ fn applyArgs(b: *Build, args: anytype) !void {...@@ -384,20 +384,17 @@ fn applyArgs(b: *Build, args: anytype) !void {
384 },384 },
385 }385 }
386 }386 }
387 const Hasher = std.crypto.auth.siphash.SipHash128(1, 3);387
388 // Create an installation directory local to this package. This will be used when
389 // dependant packages require a standard prefix, such as include directories for C headers.
390 var hash = b.cache.hash;
388 // Random bytes to make unique. Refresh this with new random bytes when391 // Random bytes to make unique. Refresh this with new random bytes when
389 // implementation is modified in a non-backwards-compatible way.392 // implementation is modified in a non-backwards-compatible way.
390 var hash = Hasher.init("ZaEsvQ5ClaA2IdH9");393 hash.add(@as(u32, 0xd8cb0055));
391 hash.update(b.dep_prefix);394 hash.addBytes(b.dep_prefix);
392 // TODO additionally update the hash with `args`.395 // TODO additionally update the hash with `args`.
393396 const digest = hash.final();
394 var digest: [16]u8 = undefined;397 const install_prefix = try b.cache_root.join(b.allocator, &.{ "i", &digest });
395 hash.final(&digest);
396 var hash_basename: [digest.len * 2]u8 = undefined;
397 _ = std.fmt.bufPrint(&hash_basename, "{s}", .{std.fmt.fmtSliceHexLower(&digest)}) catch
398 unreachable;
399
400 const install_prefix = try b.cache_root.join(b.allocator, &.{ "i", &hash_basename });
401 b.resolveInstallPrefix(install_prefix, .{});398 b.resolveInstallPrefix(install_prefix, .{});
402}399}
403400