Commit aebf20cc9a

Jacob Young <jacobly0@users.noreply.github.com>
2024-02-04 21:59:23
compiler_rt: avoid referencing symbol on versions where it doesn't exist
This change causes `__isPlatformVersionAtLeast` to no longer exist in compiler_rt when targetting a min os version earlier than 10.15, which is earlier than the default os version and so only affects builds that explicitly target an older version than Zig officially supports.
1 parent 941d3a2
Changed files (1)
lib
lib/compiler_rt/os_version_check.zig
@@ -2,10 +2,13 @@ const std = @import("std");
 const testing = std.testing;
 const builtin = @import("builtin");
 const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const panic = @import("common.zig").panic;
+
+const have_availability_version_check = builtin.os.tag.isDarwin() and
+    builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 15, .patch = 0 }).compare(.gte);
 
 comptime {
-    if (builtin.os.tag.isDarwin()) {
+    if (have_availability_version_check) {
         @export(__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = linkage });
     }
 }
@@ -25,7 +28,7 @@ comptime {
 // the newer codepath, which merely calls out to the Darwin _availability_version_check API which is
 // available on macOS 10.15+, iOS 13+, tvOS 13+ and watchOS 6+.
 
-const __isPlatformVersionAtLeast = if (builtin.os.tag.isDarwin()) struct {
+const __isPlatformVersionAtLeast = if (have_availability_version_check) struct {
     inline fn constructVersion(major: u32, minor: u32, subminor: u32) u32 {
         return ((major & 0xffff) << 16) | ((minor & 0xff) << 8) | (subminor & 0xff);
     }
@@ -50,7 +53,7 @@ const __isPlatformVersionAtLeast = if (builtin.os.tag.isDarwin()) struct {
 }.__isPlatformVersionAtLeast else struct {};
 
 test "isPlatformVersionAtLeast" {
-    if (!comptime builtin.os.tag.isDarwin()) return error.SkipZigTest;
+    if (!have_availability_version_check) return error.SkipZigTest;
 
     // Note: this test depends on the actual host OS version since it is merely calling into the
     // native Darwin API.