aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Target/Query.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-10 12:04:27 +0200
committerGitHub <noreply@github.com>2025-07-10 12:04:27 +0200
commit1a998886c863a1829d649f196093f1058cd9cf13 (patch)
treedb1b3b0a043a113cfb6544e8103cb64f8e4e4d8f /lib/std/Target/Query.zig
parent5b4b033236a7bed19c90faf7fefbc1990911cfef (diff)
parent10d6db5d7d1fb62ee2915a7ad2c7feb771ea3bbb (diff)
downloadzig-1a998886c863a1829d649f196093f1058cd9cf13.tar.gz
zig-1a998886c863a1829d649f196093f1058cd9cf13.zip
Merge pull request #24329 from ziglang/writergate
Deprecates all existing std.io readers and writers in favor of the newly provided std.io.Reader and std.io.Writer which are non-generic and have the buffer above the vtable - in other words the buffer is in the interface, not the implementation. This means that although Reader and Writer are no longer generic, they are still transparent to optimization; all of the interface functions have a concrete hot path operating on the buffer, and only make vtable calls when the buffer is full.
Diffstat (limited to 'lib/std/Target/Query.zig')
-rw-r--r--lib/std/Target/Query.zig41
1 files changed, 20 insertions, 21 deletions
diff --git a/lib/std/Target/Query.zig b/lib/std/Target/Query.zig
index e453b70e5c..2d3b0f4436 100644
--- a/lib/std/Target/Query.zig
+++ b/lib/std/Target/Query.zig
@@ -394,25 +394,24 @@ pub fn canDetectLibC(self: Query) bool {
/// Formats a version with the patch component omitted if it is zero,
/// unlike SemanticVersion.format which formats all its version components regardless.
-fn formatVersion(version: SemanticVersion, writer: anytype) !void {
+fn formatVersion(version: SemanticVersion, gpa: Allocator, list: *std.ArrayListUnmanaged(u8)) !void {
if (version.patch == 0) {
- try writer.print("{d}.{d}", .{ version.major, version.minor });
+ try list.print(gpa, "{d}.{d}", .{ version.major, version.minor });
} else {
- try writer.print("{d}.{d}.{d}", .{ version.major, version.minor, version.patch });
+ try list.print(gpa, "{d}.{d}.{d}", .{ version.major, version.minor, version.patch });
}
}
-pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
- if (self.isNativeTriple())
- return allocator.dupe(u8, "native");
+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 = std.ArrayList(u8).init(allocator);
- defer result.deinit();
+ var result: std.ArrayListUnmanaged(u8) = .empty;
+ defer result.deinit(gpa);
- try result.writer().print("{s}-{s}", .{ arch_name, os_name });
+ 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.
@@ -420,11 +419,11 @@ pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
switch (min) {
.none => {},
.semver => |v| {
- try result.writer().writeAll(".");
- try formatVersion(v, result.writer());
+ try result.appendSlice(gpa, ".");
+ try formatVersion(v, gpa, &result);
},
.windows => |v| {
- try result.writer().print("{s}", .{v});
+ try result.print(gpa, "{d}", .{v});
},
}
}
@@ -432,39 +431,39 @@ pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 {
switch (max) {
.none => {},
.semver => |v| {
- try result.writer().writeAll("...");
- try formatVersion(v, result.writer());
+ 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.writer().print("..{s}", .{v});
+ try result.print(gpa, "..{d}", .{v});
},
}
}
if (self.glibc_version) |v| {
const name = if (self.abi) |abi| @tagName(abi) else "gnu";
- try result.ensureUnusedCapacity(name.len + 2);
+ try result.ensureUnusedCapacity(gpa, name.len + 2);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
result.appendAssumeCapacity('.');
- try formatVersion(v, result.writer());
+ 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(name.len + 2);
+ try result.ensureUnusedCapacity(gpa, name.len + 2);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
result.appendAssumeCapacity('.');
- try result.writer().print("{d}", .{lvl});
+ try result.print(gpa, "{d}", .{lvl});
} else if (self.abi) |abi| {
const name = @tagName(abi);
- try result.ensureUnusedCapacity(name.len + 1);
+ try result.ensureUnusedCapacity(gpa, name.len + 1);
result.appendAssumeCapacity('-');
result.appendSliceAssumeCapacity(name);
}
- return result.toOwnedSlice();
+ return result.toOwnedSlice(gpa);
}
/// Renders the query into a textual representation that can be parsed via the