diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-06-27 20:05:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-07 22:43:51 -0700 |
| commit | 0e37ff0d591dd75ceec9208196bec29efaec607a (patch) | |
| tree | c126fa823a1f3864e9c363aac70e3a3db0219957 /lib/std/Target/Query.zig | |
| parent | 0b3f0124dc33403d329fb8ee63a93215d9af1f1e (diff) | |
| download | zig-0e37ff0d591dd75ceec9208196bec29efaec607a.tar.gz zig-0e37ff0d591dd75ceec9208196bec29efaec607a.zip | |
std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API
make std.testing.expectFmt work at compile-time
std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.
Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
- anytype -> *std.io.Writer
- inferred error set -> error{WriteFailed}
- options -> (deleted)
* std.fmt.Formatted
- now takes context type explicitly
- no fmt string
Diffstat (limited to 'lib/std/Target/Query.zig')
| -rw-r--r-- | lib/std/Target/Query.zig | 41 |
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 |
