diff --git a/lib/std/target.zig b/lib/std/target.zig index 8e1b9f8736..3f18791eb9 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -967,15 +967,15 @@ pub const Target = struct { pub const stack_align = 16; - pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 { + pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator); } - pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![:0]u8 { - return std.fmt.allocPrint0(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); + pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { + return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); } - pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 { + pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); } diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index bea69b3978..9099519274 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -495,16 +495,18 @@ pub const CrossTarget = struct { return self.isNativeCpu() and self.isNativeOs() and self.abi == null; } - pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { + pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { if (self.isNative()) { - return mem.dupeZ(allocator, u8, "native"); + return mem.dupe(allocator, 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 = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name }); - defer result.deinit(); + var result = std.ArrayList(u8).init(allocator); + errdefer result.deinit(); + + try result.outStream().print("{}-{}", .{ 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. @@ -532,13 +534,13 @@ pub const CrossTarget = struct { return result.toOwnedSlice(); } - pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 { + pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { // TODO is there anything else worthy of the description that is not // already captured in the triple? return self.zigTriple(allocator); } - pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 { + pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); } @@ -549,7 +551,7 @@ pub const CrossTarget = struct { pub const VcpkgLinkage = std.builtin.LinkMode; /// Returned slice must be freed by the caller. - pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![:0]u8 { + pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 { const arch = switch (self.getCpuArch()) { .i386 => "x86", .x86_64 => "x64", @@ -580,7 +582,7 @@ pub const CrossTarget = struct { .Dynamic => "", }; - return std.fmt.allocPrint0(allocator, "{}-{}{}", .{ arch, os, static_suffix }); + return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix }); } pub const Executor = union(enum) {