Files
swift-mirror/stdlib/public/runtime/BackDeployment.cpp
Zoe Carver 7eff49c1b6 [cxx-interop] [nfc] Remove swift namespace from SwiftShims in C++ mode. (#32715)
Most SwiftShims were put in the swift namespace in C++ mode which broke certain things when importing them in a swift file in C++ mode. This was OK when they were only imported as part of the swift runtime but, now they are used in C++ mode both in the swift runtime and when C++ interop is enabled.

This broke when C++ interop was enabled because the `Swift` module contains references to symbols in the SwiftShims headers which are built without C++ interop enabled (no "swift" namespace). But, when C++ interop is enabled, the SwiftShims headers would put everything in the swift namespace meaning the symbols couldn't be found in the global namespace. Then, the compiler would error when trying to deserialize the Swift module.
2020-07-08 08:43:26 -07:00

65 lines
2.0 KiB
C++

//===--- BackDeployment.cpp - Support for running on older OS versions. ---===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/Runtime/BackDeployment.h"
#include "swift/Runtime/Config.h"
#include "../SwiftShims/FoundationShims.h"
#include <stdlib.h>
#if defined(__APPLE__) && defined(__MACH__)
#if SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE
static unsigned long long computeIsSwiftMask() {
if (swift::_swift_isBackDeploying())
return 1ULL;
return 2ULL;
}
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
extern "C" unsigned long long
_swift_classIsSwiftMask = computeIsSwiftMask();
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
#endif // SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE
static _SwiftNSOperatingSystemVersion swiftInOSVersion = {
#if __MAC_OS_X_VERSION_MIN_REQUIRED
10, 14, 4
// WatchOS also pretends to be iOS, so check it first.
#elif __WATCH_OS_VERSION_MIN_REQUIRED
5, 2, 0
#elif __IPHONE_OS_VERSION_MIN_REQUIRED || __TV_OS_VERSION_MIN_REQUIRED
12, 2, 0
#else
9999, 0, 0
#endif
};
static bool versionLessThan(_SwiftNSOperatingSystemVersion lhs,
_SwiftNSOperatingSystemVersion rhs) {
if (lhs.majorVersion < rhs.majorVersion) return true;
if (lhs.majorVersion > rhs.majorVersion) return false;
if (lhs.minorVersion < rhs.minorVersion) return true;
if (lhs.minorVersion > rhs.minorVersion) return false;
if (lhs.patchVersion < rhs.patchVersion) return true;
return false;
}
SWIFT_RUNTIME_STDLIB_INTERNAL
int _swift_isBackDeploying() {
auto version = _swift_stdlib_operatingSystemVersion();
return versionLessThan(version, swiftInOSVersion);
}
#endif