authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-04 21:59:23+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-05 03:17:57-05:00
logaebf20cc9a0469a778d6276d3797525660746e91
treebb8f4697f6565b1d33d2b93436316973f5d8ab44
parent941d3a2bb1213b04399fe772aaf88c35d043af01

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 files changed, 7 insertions(+), 4 deletions(-)

lib/compiler_rt/os_version_check.zig+7-4
...@@ -2,10 +2,13 @@ const std = @import("std");...@@ -2,10 +2,13 @@ const std = @import("std");
2const testing = std.testing;2const testing = std.testing;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;5const panic = @import("common.zig").panic;
6
7const have_availability_version_check = builtin.os.tag.isDarwin() and
8 builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 15, .patch = 0 }).compare(.gte);
69
7comptime {10comptime {
8 if (builtin.os.tag.isDarwin()) {11 if (have_availability_version_check) {
9 @export(__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = linkage });12 @export(__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = linkage });
10 }13 }
11}14}
...@@ -25,7 +28,7 @@ comptime {...@@ -25,7 +28,7 @@ comptime {
25// the newer codepath, which merely calls out to the Darwin _availability_version_check API which is28// the newer codepath, which merely calls out to the Darwin _availability_version_check API which is
26// available on macOS 10.15+, iOS 13+, tvOS 13+ and watchOS 6+.29// available on macOS 10.15+, iOS 13+, tvOS 13+ and watchOS 6+.
2730
28const __isPlatformVersionAtLeast = if (builtin.os.tag.isDarwin()) struct {31const __isPlatformVersionAtLeast = if (have_availability_version_check) struct {
29 inline fn constructVersion(major: u32, minor: u32, subminor: u32) u32 {32 inline fn constructVersion(major: u32, minor: u32, subminor: u32) u32 {
30 return ((major & 0xffff) << 16) | ((minor & 0xff) << 8) | (subminor & 0xff);33 return ((major & 0xffff) << 16) | ((minor & 0xff) << 8) | (subminor & 0xff);
31 }34 }
...@@ -50,7 +53,7 @@ const __isPlatformVersionAtLeast = if (builtin.os.tag.isDarwin()) struct {...@@ -50,7 +53,7 @@ const __isPlatformVersionAtLeast = if (builtin.os.tag.isDarwin()) struct {
50}.__isPlatformVersionAtLeast else struct {};53}.__isPlatformVersionAtLeast else struct {};
5154
52test "isPlatformVersionAtLeast" {55test "isPlatformVersionAtLeast" {
53 if (!comptime builtin.os.tag.isDarwin()) return error.SkipZigTest;56 if (!have_availability_version_check) return error.SkipZigTest;
5457
55 // Note: this test depends on the actual host OS version since it is merely calling into the58 // Note: this test depends on the actual host OS version since it is merely calling into the
56 // native Darwin API.59 // native Darwin API.