diff --git a/lib/std/std.zig b/lib/std/std.zig index 4236b29298..56b75e5656 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -48,7 +48,6 @@ pub const base64 = @import("base64.zig"); pub const build = @import("build.zig"); pub const builtin = @import("builtin.zig"); pub const c = @import("c.zig"); -pub const cache_hash = @import("cache_hash.zig"); pub const coff = @import("coff.zig"); pub const compress = @import("compress.zig"); pub const crypto = @import("crypto.zig"); diff --git a/lib/std/cache_hash.zig b/src-self-hosted/Cache.zig similarity index 97% rename from lib/std/cache_hash.zig rename to src-self-hosted/Cache.zig index 2075bedc22..b41c0a312f 100644 --- a/lib/std/cache_hash.zig +++ b/src-self-hosted/Cache.zig @@ -1,9 +1,9 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2015-2020 Zig Contributors -// This file is part of [zig](https://ziglang.org/), which is MIT licensed. -// The MIT license requires this copyright notice to be included in all copies -// and substantial portions of the software. -const std = @import("std.zig"); +gpa: *Allocator, +manifest_dir: fs.Dir, +hash: HashHelper = .{}, + +const Cache = @This(); +const std = @import("std"); const crypto = std.crypto; const fs = std.fs; const base64 = std.base64; @@ -13,6 +13,17 @@ const mem = std.mem; const fmt = std.fmt; const Allocator = std.mem.Allocator; +/// Be sure to call `CacheHash.deinit` after successful initialization. +pub fn obtain(cache: *const Cache) CacheHash { + return CacheHash{ + .cache = cache, + .hash = cache.hash, + .manifest_file = null, + .manifest_dirty = false, + .b64_digest = undefined, + }; +} + pub const base64_encoder = fs.base64_encoder; pub const base64_decoder = fs.base64_decoder; /// 16 would be 128 bits - Even with 2^54 cache entries, the probably of a collision would be under 10^-6 @@ -50,23 +61,6 @@ pub const File = struct { } }; -pub const Cache = struct { - gpa: *Allocator, - manifest_dir: fs.Dir, - hash: HashHelper = .{}, - - /// Be sure to call `CacheHash.deinit` after successful initialization. - pub fn obtain(cache: *const Cache) CacheHash { - return CacheHash{ - .cache = cache, - .hash = cache.hash, - .manifest_file = null, - .manifest_dirty = false, - .b64_digest = undefined, - }; - } -}; - pub const HashHelper = struct { hasher: Hasher = hasher_init, diff --git a/src-self-hosted/Compilation.zig b/src-self-hosted/Compilation.zig index 1f42c87849..606eefa4ee 100644 --- a/src-self-hosted/Compilation.zig +++ b/src-self-hosted/Compilation.zig @@ -17,6 +17,7 @@ const LibCInstallation = @import("libc_installation.zig").LibCInstallation; const glibc = @import("glibc.zig"); const fatal = @import("main.zig").fatal; const Module = @import("Module.zig"); +const Cache = @import("Cache.zig"); /// General-purpose allocator. Used for both temporary and long-term storage. gpa: *Allocator, @@ -46,7 +47,7 @@ disable_c_depfile: bool, c_source_files: []const CSourceFile, clang_argv: []const []const u8, -cache_parent: *std.cache_hash.Cache, +cache_parent: *Cache, /// Path to own executable for invoking `zig clang`. self_exe_path: ?[]const u8, zig_lib_directory: Directory, @@ -78,7 +79,7 @@ owned_link_dir: ?std.fs.Dir, pub const InnerError = Module.InnerError; pub const CRTFile = struct { - lock: std.cache_hash.Lock, + lock: Cache.Lock, full_object_path: []const u8, fn deinit(self: *CRTFile, gpa: *Allocator) void { @@ -128,7 +129,7 @@ pub const CObject = struct { /// This is a file system lock on the cache hash manifest representing this /// object. It prevents other invocations of the Zig compiler from interfering /// with this object until released. - lock: std.cache_hash.Lock, + lock: Cache.Lock, }, /// There will be a corresponding ErrorMsg in Compilation.failed_c_objects. failure, @@ -404,7 +405,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { // find the same binary and incrementally update it even if there are modified source files. // We do this even if outputting to the current directory because we need somewhere to store // incremental compilation metadata. - const cache = try arena.create(std.cache_hash.Cache); + const cache = try arena.create(Cache); cache.* = .{ .gpa = gpa, .manifest_dir = try options.zig_cache_directory.handle.makeOpenPath("h", .{}), diff --git a/src-self-hosted/introspect.zig b/src-self-hosted/introspect.zig index 8041142a67..067326ebb6 100644 --- a/src-self-hosted/introspect.zig +++ b/src-self-hosted/introspect.zig @@ -1,7 +1,6 @@ const std = @import("std"); const mem = std.mem; const fs = std.fs; -const CacheHash = std.cache_hash.CacheHash; const Compilation = @import("Compilation.zig"); /// Returns the sub_path that worked, or `null` if none did. diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig index 832015faae..a7393cc913 100644 --- a/src-self-hosted/link.zig +++ b/src-self-hosted/link.zig @@ -6,6 +6,7 @@ const fs = std.fs; const trace = @import("tracy.zig").trace; const Package = @import("Package.zig"); const Type = @import("type.zig").Type; +const Cache = @import("Cache.zig"); const build_options = @import("build_options"); const LibCInstallation = @import("libc_installation.zig").LibCInstallation; @@ -92,7 +93,7 @@ pub const File = struct { /// Prevents other processes from clobbering files in the output directory /// of this linking operation. - lock: ?std.cache_hash.Lock = null, + lock: ?Cache.Lock = null, pub const LinkBlock = union { elf: Elf.TextBlock, @@ -239,7 +240,7 @@ pub const File = struct { } } - pub fn toOwnedLock(self: *File) std.cache_hash.Lock { + pub fn toOwnedLock(self: *File) Cache.Lock { const lock = self.lock.?; self.lock = null; return lock;