mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This patch adds a compiler entry point to the standard library that checks whether the running OS version is greater than or equal to a given version triple. The idea is that #os(...) will get SILGen'd into a call to this function. The standard library function calls a runtime function to actually get the OS version. This runtime function uses -[NSProcessInfo operatingSystemVersion] when possible, otherwise it loads the SystemVersion plist. When running under the simulator, we use an environmental variable set by the simulator to look up the version for the simulated OS and not the host OS. At the moment, there is no caching for version info. I will add this in a later patch. Swift SVN r22303
33 lines
1.1 KiB
Swift
33 lines
1.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import SwiftShims
|
|
|
|
/// Returns 1 if the running OS version is greater than or equal to
|
|
/// major.minor.patchVersion and 0 otherwise.
|
|
/// This is a magic entrypoint known to the compiler. It is called in
|
|
/// generated code for API availability checking.
|
|
public func _stdlib_isOSVersionAtLeast(
|
|
major: Builtin.Word,
|
|
minor: Builtin.Word,
|
|
patch: Builtin.Word
|
|
) -> Builtin.Int1 {
|
|
let version = _swift_stdlib_operatingSystemVersion()
|
|
|
|
let result =
|
|
(version.majorVersion >= Int(major)) &&
|
|
(version.minorVersion >= Int(minor)) &&
|
|
(version.patchVersion >= Int(patch))
|
|
|
|
return result.value
|
|
}
|