structstd.Build.Cache.HashHelper[src]

Fields

Functions

FunctionaddBytes[src]

pub fn addBytes(hh: *HashHelper, bytes: []const u8) void

Record a slice of bytes as a dependency of the process being cached.

Parameters

bytes: []const u8

Source Code

Source code
pub fn addBytes(hh: *HashHelper, bytes: []const u8) void {
    hh.hasher.update(mem.asBytes(&bytes.len));
    hh.hasher.update(bytes);
}

FunctionaddOptionalBytes[src]

pub fn addOptionalBytes(hh: *HashHelper, optional_bytes: ?[]const u8) void

Parameters

optional_bytes: ?[]const u8

Source Code

Source code
pub fn addOptionalBytes(hh: *HashHelper, optional_bytes: ?[]const u8) void {
    hh.add(optional_bytes != null);
    hh.addBytes(optional_bytes orelse return);
}

FunctionaddListOfBytes[src]

pub fn addListOfBytes(hh: *HashHelper, list_of_bytes: []const []const u8) void

Parameters

list_of_bytes: []const []const u8

Source Code

Source code
pub fn addListOfBytes(hh: *HashHelper, list_of_bytes: []const []const u8) void {
    hh.add(list_of_bytes.len);
    for (list_of_bytes) |bytes| hh.addBytes(bytes);
}

FunctionaddOptionalListOfBytes[src]

pub fn addOptionalListOfBytes(hh: *HashHelper, optional_list_of_bytes: ?[]const []const u8) void

Parameters

optional_list_of_bytes: ?[]const []const u8

Source Code

Source code
pub fn addOptionalListOfBytes(hh: *HashHelper, optional_list_of_bytes: ?[]const []const u8) void {
    hh.add(optional_list_of_bytes != null);
    hh.addListOfBytes(optional_list_of_bytes orelse return);
}

Functionadd[src]

pub fn add(hh: *HashHelper, x: anytype) void

Convert the input value into bytes and record it as a dependency of the process being cached.

Parameters

Source Code

Source code
pub fn add(hh: *HashHelper, x: anytype) void {
    switch (@TypeOf(x)) {
        std.SemanticVersion => {
            hh.add(x.major);
            hh.add(x.minor);
            hh.add(x.patch);
        },
        std.Target.Os.TaggedVersionRange => {
            switch (x) {
                .hurd => |hurd| {
                    hh.add(hurd.range.min);
                    hh.add(hurd.range.max);
                    hh.add(hurd.glibc);
                },
                .linux => |linux| {
                    hh.add(linux.range.min);
                    hh.add(linux.range.max);
                    hh.add(linux.glibc);
                    hh.add(linux.android);
                },
                .windows => |windows| {
                    hh.add(windows.min);
                    hh.add(windows.max);
                },
                .semver => |semver| {
                    hh.add(semver.min);
                    hh.add(semver.max);
                },
                .none => {},
            }
        },
        std.zig.BuildId => switch (x) {
            .none, .fast, .uuid, .sha1, .md5 => hh.add(std.meta.activeTag(x)),
            .hexstring => |hex_string| hh.addBytes(hex_string.toSlice()),
        },
        else => switch (@typeInfo(@TypeOf(x))) {
            .bool, .int, .@"enum", .array => hh.addBytes(mem.asBytes(&x)),
            else => @compileError("unable to hash type " ++ @typeName(@TypeOf(x))),
        },
    }
}

FunctionaddOptional[src]

pub fn addOptional(hh: *HashHelper, optional: anytype) void

Parameters

Source Code

Source code
pub fn addOptional(hh: *HashHelper, optional: anytype) void {
    hh.add(optional != null);
    hh.add(optional orelse return);
}

Functionpeek[src]

pub fn peek(hh: HashHelper) [hex_digest_len]u8

Returns a hex encoded hash of the inputs, without modifying state.

Parameters

Source Code

Source code
pub fn peek(hh: HashHelper) [hex_digest_len]u8 {
    var copy = hh;
    return copy.final();
}

FunctionpeekBin[src]

pub fn peekBin(hh: HashHelper) BinDigest

Parameters

Source Code

Source code
pub fn peekBin(hh: HashHelper) BinDigest {
    var copy = hh;
    var bin_digest: BinDigest = undefined;
    copy.hasher.final(&bin_digest);
    return bin_digest;
}

Functionfinal[src]

pub fn final(hh: *HashHelper) HexDigest

Returns a hex encoded hash of the inputs, mutating the state of the hasher.

Parameters

Source Code

Source code
pub fn final(hh: *HashHelper) HexDigest {
    var bin_digest: BinDigest = undefined;
    hh.hasher.final(&bin_digest);
    return binToHex(bin_digest);
}

FunctiononeShot[src]

pub fn oneShot(bytes: []const u8) [hex_digest_len]u8

Parameters

bytes: []const u8

Source Code

Source code
pub fn oneShot(bytes: []const u8) [hex_digest_len]u8 {
    var hasher: Hasher = hasher_init;
    hasher.update(bytes);
    var bin_digest: BinDigest = undefined;
    hasher.final(&bin_digest);
    return binToHex(bin_digest);
}

Source Code

Source code
pub const HashHelper = struct {
    hasher: Hasher = hasher_init,

    /// Record a slice of bytes as a dependency of the process being cached.
    pub fn addBytes(hh: *HashHelper, bytes: []const u8) void {
        hh.hasher.update(mem.asBytes(&bytes.len));
        hh.hasher.update(bytes);
    }

    pub fn addOptionalBytes(hh: *HashHelper, optional_bytes: ?[]const u8) void {
        hh.add(optional_bytes != null);
        hh.addBytes(optional_bytes orelse return);
    }

    pub fn addListOfBytes(hh: *HashHelper, list_of_bytes: []const []const u8) void {
        hh.add(list_of_bytes.len);
        for (list_of_bytes) |bytes| hh.addBytes(bytes);
    }

    pub fn addOptionalListOfBytes(hh: *HashHelper, optional_list_of_bytes: ?[]const []const u8) void {
        hh.add(optional_list_of_bytes != null);
        hh.addListOfBytes(optional_list_of_bytes orelse return);
    }

    /// Convert the input value into bytes and record it as a dependency of the process being cached.
    pub fn add(hh: *HashHelper, x: anytype) void {
        switch (@TypeOf(x)) {
            std.SemanticVersion => {
                hh.add(x.major);
                hh.add(x.minor);
                hh.add(x.patch);
            },
            std.Target.Os.TaggedVersionRange => {
                switch (x) {
                    .hurd => |hurd| {
                        hh.add(hurd.range.min);
                        hh.add(hurd.range.max);
                        hh.add(hurd.glibc);
                    },
                    .linux => |linux| {
                        hh.add(linux.range.min);
                        hh.add(linux.range.max);
                        hh.add(linux.glibc);
                        hh.add(linux.android);
                    },
                    .windows => |windows| {
                        hh.add(windows.min);
                        hh.add(windows.max);
                    },
                    .semver => |semver| {
                        hh.add(semver.min);
                        hh.add(semver.max);
                    },
                    .none => {},
                }
            },
            std.zig.BuildId => switch (x) {
                .none, .fast, .uuid, .sha1, .md5 => hh.add(std.meta.activeTag(x)),
                .hexstring => |hex_string| hh.addBytes(hex_string.toSlice()),
            },
            else => switch (@typeInfo(@TypeOf(x))) {
                .bool, .int, .@"enum", .array => hh.addBytes(mem.asBytes(&x)),
                else => @compileError("unable to hash type " ++ @typeName(@TypeOf(x))),
            },
        }
    }

    pub fn addOptional(hh: *HashHelper, optional: anytype) void {
        hh.add(optional != null);
        hh.add(optional orelse return);
    }

    /// Returns a hex encoded hash of the inputs, without modifying state.
    pub fn peek(hh: HashHelper) [hex_digest_len]u8 {
        var copy = hh;
        return copy.final();
    }

    pub fn peekBin(hh: HashHelper) BinDigest {
        var copy = hh;
        var bin_digest: BinDigest = undefined;
        copy.hasher.final(&bin_digest);
        return bin_digest;
    }

    /// Returns a hex encoded hash of the inputs, mutating the state of the hasher.
    pub fn final(hh: *HashHelper) HexDigest {
        var bin_digest: BinDigest = undefined;
        hh.hasher.final(&bin_digest);
        return binToHex(bin_digest);
    }

    pub fn oneShot(bytes: []const u8) [hex_digest_len]u8 {
        var hasher: Hasher = hasher_init;
        hasher.update(bytes);
        var bin_digest: BinDigest = undefined;
        hasher.final(&bin_digest);
        return binToHex(bin_digest);
    }
}