|
| 1 | +//===--- BackDeployment.cpp - Support for running on older OS versions. ---===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "swift/Runtime/BackDeployment.h" |
| 14 | +#include "swift/Runtime/Config.h" |
| 15 | +#include "../SwiftShims/FoundationShims.h" |
| 16 | +#include <stdlib.h> |
| 17 | + |
| 18 | +#if defined(__APPLE__) && defined(__MACH__) |
| 19 | + |
| 20 | +#if SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE |
| 21 | +static unsigned long long computeIsSwiftMask() { |
| 22 | + if (swift::_swift_isBackDeploying()) |
| 23 | + return 1ULL; |
| 24 | + return 2ULL; |
| 25 | +} |
| 26 | + |
| 27 | +SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN |
| 28 | +extern "C" unsigned long long |
| 29 | +_swift_classIsSwiftMask = computeIsSwiftMask(); |
| 30 | +SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END |
| 31 | +#endif // SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE |
| 32 | + |
| 33 | +static swift::_SwiftNSOperatingSystemVersion swiftInOSVersion = { |
| 34 | +#if __MAC_OS_X_VERSION_MIN_REQUIRED |
| 35 | + 10, 14, 4 |
| 36 | +// WatchOS also pretends to be iOS, so check it first. |
| 37 | +#elif __WATCH_OS_VERSION_MIN_REQUIRED |
| 38 | + 5, 2, 0 |
| 39 | +#elif __IPHONE_OS_VERSION_MIN_REQUIRED || __TV_OS_VERSION_MIN_REQUIRED |
| 40 | + 12, 2, 0 |
| 41 | +#else |
| 42 | + 9999, 0, 0 |
| 43 | +#endif |
| 44 | +}; |
| 45 | + |
| 46 | +static bool versionLessThan(swift::_SwiftNSOperatingSystemVersion lhs, |
| 47 | + swift::_SwiftNSOperatingSystemVersion rhs) { |
| 48 | + if (lhs.majorVersion < rhs.majorVersion) return true; |
| 49 | + if (lhs.majorVersion > rhs.majorVersion) return false; |
| 50 | + |
| 51 | + if (lhs.minorVersion < rhs.minorVersion) return true; |
| 52 | + if (lhs.minorVersion > rhs.minorVersion) return false; |
| 53 | + |
| 54 | + if (lhs.patchVersion < rhs.patchVersion) return true; |
| 55 | + |
| 56 | + return false; |
| 57 | +} |
| 58 | + |
| 59 | +SWIFT_RUNTIME_STDLIB_INTERNAL |
| 60 | +int _swift_isBackDeploying() { |
| 61 | + auto version = swift::_swift_stdlib_operatingSystemVersion(); |
| 62 | + return versionLessThan(version, swiftInOSVersion); |
| 63 | +} |
| 64 | +#endif |
0 commit comments