Commit cbefd354a6

Jakub Konka <kubkon@jakubkonka.com>
2022-05-22 11:30:52
Bump support macOS versions; clean up allocs in llvm.targetTriple
1 parent e306d04
Changed files (2)
lib
src
codegen
lib/std/target.zig
@@ -269,19 +269,18 @@ pub const Target = struct {
                     .macos => return switch (arch) {
                         .aarch64 => VersionRange{
                             .semver = .{
-                                .min = .{ .major = 11, .minor = 6 },
-                                .max = .{ .major = 12, .minor = 0 },
+                                .min = .{ .major = 11, .minor = 6, .patch = 6 },
+                                .max = .{ .major = 12, .minor = 4 },
                             },
                         },
                         .x86_64 => VersionRange{
                             .semver = .{
-                                .min = .{ .major = 10, .minor = 13 },
-                                .max = .{ .major = 12, .minor = 0 },
+                                .min = .{ .major = 10, .minor = 15, .patch = 7 },
+                                .max = .{ .major = 12, .minor = 4 },
                             },
                         },
                         else => unreachable,
                     },
-
                     .ios => return .{
                         .semver = .{
                             .min = .{ .major = 12, .minor = 0 },
src/codegen/llvm.zig
@@ -26,6 +26,9 @@ const x86_64_abi = @import("../arch/x86_64/abi.zig");
 const Error = error{ OutOfMemory, CodegenFail };
 
 pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 {
+    var llvm_triple = std.ArrayList(u8).init(allocator);
+    defer llvm_triple.deinit();
+
     const llvm_arch = switch (target.cpu.arch) {
         .arm => "arm",
         .armeb => "armeb",
@@ -85,78 +88,64 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 {
         .spirv32 => return error.@"LLVM backend does not support SPIR-V",
         .spirv64 => return error.@"LLVM backend does not support SPIR-V",
     };
-
-    var arena = std.heap.ArenaAllocator.init(allocator);
-    defer arena.deinit();
-
-    const llvm_os = blk: {
-        if (target.os.tag.isDarwin()) {
-            const min_version = target.os.version_range.semver.min;
-            const llvm_os = switch (target.os.tag) {
-                .macos => "macosx",
-                .ios => "ios",
-                .tvos => "tvos",
-                .watchos => "watchos",
-                else => unreachable,
-            };
-            break :blk try std.fmt.allocPrintZ(arena.allocator(), "{s}{d}.{d}.{d}", .{
-                llvm_os,
-                min_version.major,
-                min_version.minor,
-                min_version.patch,
-            });
-        }
-
-        const llvm_os = switch (target.os.tag) {
-            .freestanding => "unknown",
-            .ananas => "ananas",
-            .cloudabi => "cloudabi",
-            .dragonfly => "dragonfly",
-            .freebsd => "freebsd",
-            .fuchsia => "fuchsia",
-            .kfreebsd => "kfreebsd",
-            .linux => "linux",
-            .lv2 => "lv2",
-            .netbsd => "netbsd",
-            .openbsd => "openbsd",
-            .solaris => "solaris",
-            .windows => "windows",
-            .zos => "zos",
-            .haiku => "haiku",
-            .minix => "minix",
-            .rtems => "rtems",
-            .nacl => "nacl",
-            .aix => "aix",
-            .cuda => "cuda",
-            .nvcl => "nvcl",
-            .amdhsa => "amdhsa",
-            .ps4 => "ps4",
-            .elfiamcu => "elfiamcu",
-            .mesa3d => "mesa3d",
-            .contiki => "contiki",
-            .amdpal => "amdpal",
-            .hermit => "hermit",
-            .hurd => "hurd",
-            .wasi => "wasi",
-            .emscripten => "emscripten",
-            .uefi => "windows",
-
-            .opencl,
-            .glsl450,
-            .vulkan,
-            .plan9,
-            .other,
-            => "unknown",
-
-            .macos,
-            .ios,
-            .tvos,
-            .watchos,
-            => unreachable,
-        };
-
-        break :blk llvm_os;
+    try llvm_triple.appendSlice(llvm_arch);
+    try llvm_triple.appendSlice("-unknown-");
+
+    const llvm_os = switch (target.os.tag) {
+        .freestanding => "unknown",
+        .ananas => "ananas",
+        .cloudabi => "cloudabi",
+        .dragonfly => "dragonfly",
+        .freebsd => "freebsd",
+        .fuchsia => "fuchsia",
+        .kfreebsd => "kfreebsd",
+        .linux => "linux",
+        .lv2 => "lv2",
+        .netbsd => "netbsd",
+        .openbsd => "openbsd",
+        .solaris => "solaris",
+        .windows => "windows",
+        .zos => "zos",
+        .haiku => "haiku",
+        .minix => "minix",
+        .rtems => "rtems",
+        .nacl => "nacl",
+        .aix => "aix",
+        .cuda => "cuda",
+        .nvcl => "nvcl",
+        .amdhsa => "amdhsa",
+        .ps4 => "ps4",
+        .elfiamcu => "elfiamcu",
+        .mesa3d => "mesa3d",
+        .contiki => "contiki",
+        .amdpal => "amdpal",
+        .hermit => "hermit",
+        .hurd => "hurd",
+        .wasi => "wasi",
+        .emscripten => "emscripten",
+        .uefi => "windows",
+        .macos => "macosx",
+        .ios => "ios",
+        .tvos => "tvos",
+        .watchos => "watchos",
+        .opencl,
+        .glsl450,
+        .vulkan,
+        .plan9,
+        .other,
+        => "unknown",
     };
+    try llvm_triple.appendSlice(llvm_os);
+
+    if (target.os.tag.isDarwin()) {
+        const min_version = target.os.version_range.semver.min;
+        try llvm_triple.writer().print("{d}.{d}.{d}", .{
+            min_version.major,
+            min_version.minor,
+            min_version.patch,
+        });
+    }
+    try llvm_triple.append('-');
 
     const llvm_abi = switch (target.abi) {
         .none => "unknown",
@@ -182,8 +171,9 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 {
         .simulator => "simulator",
         .macabi => "macabi",
     };
+    try llvm_triple.appendSlice(llvm_abi);
 
-    return std.fmt.allocPrintZ(allocator, "{s}-unknown-{s}-{s}", .{ llvm_arch, llvm_os, llvm_abi });
+    return llvm_triple.toOwnedSliceSentinel(0);
 }
 
 pub const Object = struct {