From f8a1a2c4a18a2a5f274029c4c59f3a8e83f36b6b Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 15 May 2022 17:56:51 +0200 Subject: stage2: append min version to target triple when lowering to LLVM --- src/codegen/llvm.zig | 111 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 44 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index b9c8e5437f..5f071af017 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -86,50 +86,73 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 { .spirv64 => return error.@"LLVM backend does not support SPIR-V", }; - const llvm_os = switch (target.os.tag) { - .freestanding => "unknown", - .ananas => "ananas", - .cloudabi => "cloudabi", - .dragonfly => "dragonfly", - .freebsd => "freebsd", - .fuchsia => "fuchsia", - .ios => "ios", - .kfreebsd => "kfreebsd", - .linux => "linux", - .lv2 => "lv2", - .macos => "macosx", - .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", - .tvos => "tvos", - .watchos => "watchos", - .mesa3d => "mesa3d", - .contiki => "contiki", - .amdpal => "amdpal", - .hermit => "hermit", - .hurd => "hurd", - .wasi => "wasi", - .emscripten => "emscripten", - .uefi => "windows", - - .opencl, - .glsl450, - .vulkan, - .plan9, - .other, - => "unknown", + 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(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; }; const llvm_abi = switch (target.abi) { -- cgit v1.2.3 From e306d04473818ac8b58779aa1ff20b12edb8e94a Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 20 May 2022 16:54:52 +0200 Subject: Return an error when macOS ABI is not {none, simulator, macabi} --- src/Compilation.zig | 9 +++++++++ src/codegen/llvm.zig | 5 ++++- src/link/MachO/Dylib.zig | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/codegen') diff --git a/src/Compilation.zig b/src/Compilation.zig index 2c15cb95a3..31782e732b 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1719,6 +1719,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const have_bin_emit = comp.bin_file.options.emit != null or comp.whole_bin_sub_path != null; if (have_bin_emit and !comp.bin_file.options.skip_linker_dependencies) { + if (comp.getTarget().isDarwin()) { + switch (comp.getTarget().abi) { + .none, + .simulator, + .macabi, + => {}, + else => return error.LibCUnavailable, + } + } // If we need to build glibc for the target, add work items for it. // We go through the work queue so that building can be done in parallel. if (comp.wantBuildGLibCFromSource()) { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 5f071af017..452bb9b497 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -86,6 +86,9 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 { .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; @@ -96,7 +99,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 { .watchos => "watchos", else => unreachable, }; - break :blk try std.fmt.allocPrintZ(allocator, "{s}{d}.{d}.{d}", .{ + break :blk try std.fmt.allocPrintZ(arena.allocator(), "{s}{d}.{d}.{d}", .{ llvm_os, min_version.major, min_version.minor, diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index b8b8f50e67..73e7913d71 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -305,6 +305,7 @@ const TargetMatcher = struct { const abi: ?[]const u8 = switch (target.abi) { .none => null, .simulator => "simulator", + .macabi => "maccatalyst", else => unreachable, }; if (abi) |x| { -- cgit v1.2.3 From cbefd354a662800c5bc662773146ce978631f717 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 22 May 2022 11:30:52 +0200 Subject: Bump support macOS versions; clean up allocs in llvm.targetTriple --- lib/std/target.zig | 9 ++-- src/codegen/llvm.zig | 134 ++++++++++++++++++++++++--------------------------- 2 files changed, 66 insertions(+), 77 deletions(-) (limited to 'src/codegen') diff --git a/lib/std/target.zig b/lib/std/target.zig index 27251f1d64..eae227fc37 100644 --- a/lib/std/target.zig +++ b/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 }, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 452bb9b497..6de001e5fd 100644 --- a/src/codegen/llvm.zig +++ b/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 { -- cgit v1.2.3