Source
pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
if (self.isNativeTriple())
return allocator.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 = std.ArrayList(u8).init(allocator);
defer result.deinit();
try result.writer().print("{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.writer().writeAll(".");
try formatVersion(v, result.writer());
},
.windows => |v| {
try result.writer().print("{s}", .{v});
},
}
}
if (self.os_version_max) |max| {
switch (max) {
.none => {},
.semver => |v| {
try result.writer().writeAll("...");
try formatVersion(v, result.writer());
},
.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.writer().print("..{s}", .{v});
},
}
}
if (self.glibc_version) |v| {
const name = if (self.abi) |abi| @tagName(abi) else "gnu";
try result.ensureUnusedCapacity(name.len + 2);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
result.appendAssumeCapacity('.');
try formatVersion(v, result.writer());
} else if (self.android_api_level) |lvl| {
const name = if (self.abi) |abi| @tagName(abi) else "android";
try result.ensureUnusedCapacity(name.len + 2);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
result.appendAssumeCapacity('.');
try result.writer().print("{d}", .{lvl});
} else if (self.abi) |abi| {
const name = @tagName(abi);
try result.ensureUnusedCapacity(name.len + 1);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
}
return result.toOwnedSlice();
}