Commit c42439dff9

Jakub Konka <kubkon@jakubkonka.com>
2021-11-24 20:34:13
Pass inferred cpu_arch to defaultVersionRange
This is mainly because arm64 macOS doesn't support all versions supported by x86_64 macOS. This is just a temporary thing until both architectures support the same set of OSes.
1 parent 42a351e
Changed files (4)
lib/std/zig/cross_target.zig
@@ -375,7 +375,7 @@ pub const CrossTarget = struct {
         // `builtin.os` works when doing `zig build` because Zig generates a build executable using
         // native OS version range. However this will not be accurate otherwise, and
         // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
-        var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange() else builtin.os;
+        var adjusted_os = if (self.os_tag) |os_tag| os_tag.defaultVersionRange(self.getCpuArch()) else builtin.os;
 
         if (self.os_version_min) |min| switch (min) {
             .none => {},
lib/std/zig/system.zig
@@ -238,7 +238,7 @@ pub const NativeTargetInfo = struct {
     /// deinitialization method.
     /// TODO Remove the Allocator requirement from this function.
     pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
-        var os = cross_target.getOsTag().defaultVersionRange();
+        var os = cross_target.getOsTag().defaultVersionRange(cross_target.getCpuArch());
         if (cross_target.os_tag == null) {
             switch (builtin.target.os.tag) {
                 .linux => {
lib/std/target.zig
@@ -81,10 +81,10 @@ pub const Target = struct {
                 }
             }
 
-            pub fn defaultVersionRange(tag: Tag) Os {
+            pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch) Os {
                 return .{
                     .tag = tag,
-                    .version_range = VersionRange.default(tag),
+                    .version_range = VersionRange.default(tag, arch),
                 };
             }
         };
@@ -226,7 +226,7 @@ pub const Target = struct {
 
             /// The default `VersionRange` represents the range that the Zig Standard Library
             /// bases its abstractions on.
-            pub fn default(tag: Tag) VersionRange {
+            pub fn default(tag: Tag, arch: Cpu.Arch) VersionRange {
                 switch (tag) {
                     .freestanding,
                     .ananas,
@@ -266,12 +266,22 @@ pub const Target = struct {
                             .max = .{ .major = 13, .minor = 0 },
                         },
                     },
-                    .macos => return .{
-                        .semver = .{
-                            .min = .{ .major = 10, .minor = 13 },
-                            .max = .{ .major = 12, .minor = 0 },
+                    .macos => return switch (arch) {
+                        .aarch64 => VersionRange{
+                            .semver = .{
+                                .min = .{ .major = 11, .minor = 6 },
+                                .max = .{ .major = 12, .minor = 0 },
+                            },
                         },
+                        .x86_64 => VersionRange{
+                            .semver = .{
+                                .min = .{ .major = 10, .minor = 13 },
+                                .max = .{ .major = 12, .minor = 0 },
+                            },
+                        },
+                        else => unreachable,
                     },
+
                     .ios => return .{
                         .semver = .{
                             .min = .{ .major = 12, .minor = 0 },
src/stage1/codegen.cpp
@@ -9305,7 +9305,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
     buf_appendf(contents, "pub const abi = std.Target.Abi.%s;\n", cur_abi);
     buf_appendf(contents, "pub const cpu = std.Target.Cpu.baseline(.%s);\n", cur_arch);
     buf_appendf(contents, "pub const stage2_arch: std.Target.Cpu.Arch = .%s;\n", cur_arch);
-    buf_appendf(contents, "pub const os = std.Target.Os.Tag.defaultVersionRange(.%s);\n", cur_os);
+    buf_appendf(contents, "pub const os = std.Target.Os.Tag.defaultVersionRange(.%s, .%s);\n", cur_os, cur_arch);
     buf_appendf(contents,
         "pub const target = std.Target{\n"
         "    .cpu = cpu,\n"