DoxigAlpha

zigTriple

Function parameters

Parameters

#

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
parseCpuArch
Similar to `parse` except instead of fully parsing, it only determines the CPU
parseVersion
Similar to `SemanticVersion.parse`, but with following changes:
serializeCpu
Renders the query into a textual representation that can be parsed via the

Source

Implementation

#
pub fn zigTriple(self: Query, gpa: Allocator) Allocator.Error![]u8 {
    if (self.isNativeTriple()) return gpa.dupe(u8, "native");

    const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
    const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";

    var result: ArrayList(u8) = .empty;
    defer result.deinit(gpa);

    try result.print(gpa, "{s}-{s}", .{ arch_name, os_name });

    // The zig target syntax does not allow specifying a max os version with no min, so
    // if either are present, we need the min.
    if (self.os_version_min) |min| {
        switch (min) {
            .none => {},
            .semver => |v| {
                try result.appendSlice(gpa, ".");
                try formatVersion(v, gpa, &result);
            },
            .windows => |v| {
                try result.print(gpa, "{f}", .{v});
            },
        }
    }
    if (self.os_version_max) |max| {
        switch (max) {
            .none => {},
            .semver => |v| {
                try result.appendSlice(gpa, "...");
                try formatVersion(v, gpa, &result);
            },
            .windows => |v| {
                // This is counting on a custom format() function defined on `WindowsVersion`
                // to add a prefix '.' and make there be a total of three dots.
                try result.print(gpa, "..{f}", .{v});
            },
        }
    }

    if (self.glibc_version) |v| {
        const name = if (self.abi) |abi| @tagName(abi) else "gnu";
        try result.ensureUnusedCapacity(gpa, name.len + 2);
        result.appendAssumeCapacity('-');
        result.appendSliceAssumeCapacity(name);
        result.appendAssumeCapacity('.');
        try formatVersion(v, gpa, &result);
    } else if (self.android_api_level) |lvl| {
        const name = if (self.abi) |abi| @tagName(abi) else "android";
        try result.ensureUnusedCapacity(gpa, name.len + 2);
        result.appendAssumeCapacity('-');
        result.appendSliceAssumeCapacity(name);
        result.appendAssumeCapacity('.');
        try result.print(gpa, "{d}", .{lvl});
    } else if (self.abi) |abi| {
        const name = @tagName(abi);
        try result.ensureUnusedCapacity(gpa, name.len + 1);
        result.appendAssumeCapacity('-');
        result.appendSliceAssumeCapacity(name);
    }

    return result.toOwnedSlice(gpa);
}