Skip to content

Introduce visionOS Platform #72834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ set(SWIFT_DARWIN_EMBEDDED_VARIANTS "^(iphoneos|iphonesimulator|appletvos|appletv
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
# ...
# endif()
set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX")
set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX" "XROS" "XROS_SIMULATOR")

set(SWIFT_APPLE_PLATFORMS ${SWIFT_DARWIN_PLATFORMS})
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
Expand Down Expand Up @@ -543,6 +543,9 @@ set(SWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS "11.0" CACHE STRING
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS "4.0" CACHE STRING
"Minimum deployment target version for watchOS")

set(SWIFT_DARWIN_DEPLOYMENT_VERSION_XROS "1.0" CACHE STRING
"Minimum deployment target version for xrOS")

#
# Compatibility library deployment versions
#
Expand All @@ -551,6 +554,7 @@ set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_XROS "1.0")
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_MACCATALYST "13.1")

#
Expand Down Expand Up @@ -596,7 +600,7 @@ option(SWIFT_REPORT_STATISTICS
FALSE)

# Only Darwin platforms enable ObjC interop by default.
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*|XROS*)")
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default TRUE)
else()
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default FALSE)
Expand Down Expand Up @@ -1136,7 +1140,7 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")

elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*|XROS*)")

set(SWIFT_HOST_VARIANT "macosx" CACHE STRING
"Deployment OS for Swift host tools (the compiler) [macosx, iphoneos].")
Expand Down
30 changes: 29 additions & 1 deletion cmake/modules/DarwinSDKs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64;arm64")
set(SUPPORTED_WATCHOS_ARCHS "armv7k;arm64_32")
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;x86_64;arm64")
set(SUPPORTED_OSX_ARCHS "x86_64;arm64")
set(SUPPORTED_XROS_ARCHS "arm64;arm64e")
set(SUPPORTED_XROS_SIMULATOR_ARCHS "arm64")

is_sdk_requested(OSX swift_build_osx)
if(swift_build_osx)
Expand Down Expand Up @@ -50,7 +52,8 @@ if(swift_build_freestanding AND (SWIFT_FREESTANDING_FLAVOR STREQUAL "apple"))
endif()

# Compatible cross-compile SDKS for Darwin OSes: IOS, IOS_SIMULATOR, TVOS,
# TVOS_SIMULATOR, WATCHOS, WATCHOS_SIMULATOR (archs hardcoded below).
# TVOS_SIMULATOR, WATCHOS, WATCHOS_SIMULATOR, XROS, XROS_SIMULATOR
# (archs hardcoded below).

is_sdk_requested(IOS swift_build_ios)
if(swift_build_ios)
Expand Down Expand Up @@ -120,3 +123,28 @@ if(swift_build_watchos_simulator)
configure_target_variant(WATCHOS_SIMULATOR-RA "watchOS Release+Asserts" WATCHOS_SIMULATOR RA "Release+Asserts")
configure_target_variant(WATCHOS_SIMULATOR-R "watchOS Release" WATCHOS_SIMULATOR R "Release")
endif()

is_sdk_requested(XROS swift_build_xros)
if(swift_build_xros)
configure_sdk_darwin(
XROS "xrOS" "${SWIFT_DARWIN_DEPLOYMENT_VERSION_XROS}"
xros xros xros "${SUPPORTED_XROS_ARCHS}")
configure_target_variant(XROS-DA "xrOS Debug+Asserts" XROS DA "Debug+Asserts")
configure_target_variant(XROS-RA "xrOS Release+Asserts" XROS RA "Release+Asserts")
configure_target_variant(XROS-R "xrOS Release" XROS R "Release")
endif()

is_sdk_requested(XROS_SIMULATOR swift_build_xros_simulator)
if(swift_build_xros_simulator)
configure_sdk_darwin(
XROS_SIMULATOR "xrOS Simulator" "${SWIFT_DARWIN_DEPLOYMENT_VERSION_XROS}"
xrsimulator xros xros-simulator
"${SUPPORTED_XROS_SIMULATOR_ARCHS}")

configure_target_variant(
XROS_SIMULATOR-DA "xrOS Simulator Debug+Asserts" XROS_SIMULATOR DA "Debug+Asserts")
configure_target_variant(
XROS_SIMULATOR-RA "xrOS Simulator Release+Asserts" XROS_SIMULATOR RA "Release+Asserts")
configure_target_variant(
XROS_SIMULATOR-R "xrOS Simulator Release" XROS_SIMULATOR R "Release")
endif()
2 changes: 1 addition & 1 deletion cmake/modules/StandaloneOverlay.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ set(CMAKE_INSTALL_PREFIX


set(SWIFT_DARWIN_PLATFORMS
OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR)
OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR XROS XROS_SIMULATOR)

# Flags used to indicate we are building a standalone overlay.
# FIXME: We should cut this down to a single flag.
Expand Down
10 changes: 10 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "swift/Basic/BlockList.h"
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/DarwinSDKInfo.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
Expand Down Expand Up @@ -948,6 +949,12 @@ class ASTContext final {
return getMultiPayloadEnumTagSinglePayloadAvailability();
}

/// Test support utility for loading a platform remap file
/// in case an SDK is not specified to the compilation.
const clang::DarwinSDKInfo::RelatedTargetVersionMapping *
getAuxiliaryDarwinPlatformRemapInfo(
clang::DarwinSDKInfo::OSEnvPair Kind) const;

//===--------------------------------------------------------------------===//
// Diagnostics Helper functions
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -1511,6 +1518,9 @@ class ASTContext final {
/// Provide context-level uniquing for SIL lowered type layouts and boxes.
friend SILLayout;
friend SILBoxType;

public:
clang::DarwinSDKInfo *getDarwinSDKInfo() const;
};

} // end namespace swift
Expand Down
34 changes: 34 additions & 0 deletions include/swift/AST/Availability.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace swift {
class ASTContext;
class AvailableAttr;
class BackDeployedAttr;
class Decl;

/// A lattice of version ranges of the form [x.y.z, +Inf).
Expand Down Expand Up @@ -380,6 +381,39 @@ class AvailabilityInference {

static AvailabilityContext
annotatedAvailableRangeForAttr(const SpecializeAttr *attr, ASTContext &ctx);

/// For the attribute's introduction version, update the platform and version
/// values to the re-mapped platform's, if using a fallback platform.
/// Returns `true` if a remap occured.
static bool updateIntroducedPlatformForFallback(
const AvailableAttr *attr, const ASTContext &Ctx,
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);

/// For the attribute's deprecation version, update the platform and version
/// values to the re-mapped platform's, if using a fallback platform.
/// Returns `true` if a remap occured.
static bool updateDeprecatedPlatformForFallback(
const AvailableAttr *attr, const ASTContext &Ctx,
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);

/// For the attribute's obsoletion version, update the platform and version
/// values to the re-mapped platform's, if using a fallback platform.
/// Returns `true` if a remap occured.
static bool updateObsoletedPlatformForFallback(
const AvailableAttr *attr, const ASTContext &Ctx,
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);

static void updatePlatformStringForFallback(
const AvailableAttr *attr, const ASTContext &Ctx,
llvm::StringRef &Platform);

/// For the attribute's before version, update the platform and version
/// values to the re-mapped platform's, if using a fallback platform.
/// Returns `true` if a remap occured.
static bool updateBeforePlatformForFallback(const BackDeployedAttr *attr,
const ASTContext &Ctx,
llvm::StringRef &Platform,
llvm::VersionTuple &PlatformVer);
};

/// Given a declaration upon which an availability attribute would appear in
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/PlatformKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ inline bool isApplicationExtensionPlatform(PlatformKind Platform) {
/// triple will be used rather than the target to determine whether the
/// platform is active.
bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
bool ForTargetVariant = false);
bool ForTargetVariant = false, bool ForRuntimeQuery = false);

/// Returns the target platform for the given language options.
PlatformKind targetPlatform(const LangOptions &LangOpts);
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/PlatformKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
AVAILABILITY_PLATFORM(iOS, "iOS")
AVAILABILITY_PLATFORM(tvOS, "tvOS")
AVAILABILITY_PLATFORM(watchOS, "watchOS")
AVAILABILITY_PLATFORM(visionOS, "visionOS")
AVAILABILITY_PLATFORM(macOS, "macOS")
AVAILABILITY_PLATFORM(iOSApplicationExtension, "application extensions for iOS")
AVAILABILITY_PLATFORM(tvOSApplicationExtension, "application extensions for tvOS")
AVAILABILITY_PLATFORM(watchOSApplicationExtension, "application extensions for watchOS")
AVAILABILITY_PLATFORM(visionOSApplicationExtension, "application extensions for visionOS")
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/RuntimeVersions.def
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ RUNTIME_VERSION(
PLATFORM(macOS, (14, 4, 0))
PLATFORM(iOS, (17, 4, 0))
PLATFORM(watchOS, (10, 4, 0))
PLATFORM(xrOS, (1, 0, 0))
)

RUNTIME_VERSION(
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/SearchPathOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ class SearchPathOptions {
/// A file containing a list of protocols whose conformances require const value extraction.
std::string ConstGatherProtocolListFilePath;

/// Path to the file that defines platform mapping for availability
/// version inheritance.
std::optional<std::string> PlatformAvailabilityInheritanceMapPath;

/// Debug path mappings to apply to serialized search paths. These are
/// specified in LLDB from the target.source-map entries.
PathRemapper SearchPathRemapper;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ namespace swift {
return Target.getiOSVersion();
} else if (Target.isWatchOS()) {
return Target.getOSVersion();
} else if (Target.isXROS()) {
return Target.getOSVersion();
}
return llvm::VersionTuple(/*Major=*/0, /*Minor=*/0, /*Subminor=*/0);
}
Expand Down
7 changes: 6 additions & 1 deletion include/swift/Basic/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ namespace swift {
TvOS,
TvOSSimulator,
WatchOS,
WatchOSSimulator
WatchOSSimulator,
VisionOS,
VisionOSSimulator
};

/// Returns true if the given triple represents iOS running in a simulator.
Expand All @@ -48,6 +50,9 @@ namespace swift {
/// Returns true if the given triple represents a macCatalyst environment.
bool tripleIsMacCatalystEnvironment(const llvm::Triple &triple);

/// Returns true if the given triple represents visionOS running in a simulator.
bool tripleIsVisionSimulator(const llvm::Triple &triple);

/// Determine whether the triple infers the "simulator" environment.
bool tripleInfersSimulatorEnvironment(const llvm::Triple &triple);

Expand Down
2 changes: 2 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class CompilerInvocation {

void setRuntimeResourcePath(StringRef Path);

void setPlatformAvailabilityInheritanceMapPath(StringRef Path);

/// Compute the default prebuilt module cache path for a given resource path
/// and SDK version. This function is also used by LLDB.
static std::string
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1354,4 +1354,8 @@ def module_load_mode: Separate<["-"], "module-load-mode">,
MetaVarName<"only-interface|prefer-interface|prefer-serialized|only-serialized">,
HelpText<"Module loading mode">;

def platform_availability_inheritance_map_path
: Separate<["-"], "platform-availability-inheritance-map-path">, MetaVarName<"<path>">,
HelpText<"Path of the platform inheritance platform map">;

} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ enum PlatformType {
PLATFORM_TVOSSIMULATOR = 8,
PLATFORM_WATCHOSSIMULATOR = 9,
PLATFORM_DRIVERKIT = 10,
PLATFORM_XROS = 11,
PLATFORM_XROS_SIMULATOR = 12
};

// Values for tools enum in build_tool_version.
Expand Down
40 changes: 40 additions & 0 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ struct ASTContext::Implementation {
/// The scratch context used to allocate intrinsic data on behalf of \c swift::IntrinsicInfo
std::unique_ptr<llvm::LLVMContext> IntrinsicScratchContext;

mutable std::optional<std::unique_ptr<clang::DarwinSDKInfo>> SDKInfo;

/// Memory allocation arena for the term rewriting system.
std::unique_ptr<rewriting::RewriteContext> TheRewriteContext;

Expand Down Expand Up @@ -6383,6 +6385,44 @@ bool ASTContext::isASCIIString(StringRef s) const {
return true;
}

clang::DarwinSDKInfo *ASTContext::getDarwinSDKInfo() const {
if (!getImpl().SDKInfo) {
auto SDKInfoOrErr = clang::parseDarwinSDKInfo(
*llvm::vfs::getRealFileSystem(),
SearchPathOpts.SDKPath);
if (!SDKInfoOrErr) {
llvm::handleAllErrors(SDKInfoOrErr.takeError(),
[](const llvm::ErrorInfoBase &) {
// Ignore the error for now..
});
getImpl().SDKInfo.emplace();
} else if (!*SDKInfoOrErr) {
getImpl().SDKInfo.emplace();
} else {
getImpl().SDKInfo.emplace(std::make_unique<clang::DarwinSDKInfo>(**SDKInfoOrErr));
}
}

return getImpl().SDKInfo->get();
}

const clang::DarwinSDKInfo::RelatedTargetVersionMapping
*ASTContext::getAuxiliaryDarwinPlatformRemapInfo(clang::DarwinSDKInfo::OSEnvPair Kind) const {
if (SearchPathOpts.PlatformAvailabilityInheritanceMapPath) {
auto SDKInfoOrErr = clang::parseDarwinSDKInfo(
*llvm::vfs::getRealFileSystem(),
*SearchPathOpts.PlatformAvailabilityInheritanceMapPath);
if (!SDKInfoOrErr || !*SDKInfoOrErr) {
llvm::handleAllErrors(SDKInfoOrErr.takeError(),
[](const llvm::ErrorInfoBase &) {
// Ignore the error for now..
});
}
return (*SDKInfoOrErr)->getVersionMapping(Kind);
}
return nullptr;
}

/// The special Builtin.TheTupleType, which parents tuple extensions and
/// conformances.
BuiltinTupleDecl *ASTContext::getBuiltinTupleDecl() {
Expand Down
25 changes: 23 additions & 2 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ DeclAttributes::getDeprecated(const ASTContext &ctx) const {
return AvAttr;

std::optional<llvm::VersionTuple> DeprecatedVersion = AvAttr->Deprecated;

StringRef DeprecatedPlatform = AvAttr->prettyPlatformString();
llvm::VersionTuple RemappedDeprecatedVersion;
if (AvailabilityInference::updateDeprecatedPlatformForFallback(
AvAttr, ctx, DeprecatedPlatform, RemappedDeprecatedVersion))
DeprecatedVersion = RemappedDeprecatedVersion;

if (!DeprecatedVersion.has_value())
continue;

Expand Down Expand Up @@ -2335,18 +2342,32 @@ AvailableVersionComparison AvailableAttr::getVersionAvailability(
return AvailableVersionComparison::Unavailable;

llvm::VersionTuple queryVersion = getActiveVersion(ctx);
std::optional<llvm::VersionTuple> ObsoletedVersion = Obsoleted;

StringRef ObsoletedPlatform = prettyPlatformString();
llvm::VersionTuple RemappedObsoletedVersion;
if (AvailabilityInference::updateObsoletedPlatformForFallback(
this, ctx, ObsoletedPlatform, RemappedObsoletedVersion))
ObsoletedVersion = RemappedObsoletedVersion;

// If this entity was obsoleted before or at the query platform version,
// consider it obsolete.
if (Obsoleted && *Obsoleted <= queryVersion)
if (ObsoletedVersion && *ObsoletedVersion <= queryVersion)
return AvailableVersionComparison::Obsoleted;

std::optional<llvm::VersionTuple> IntroducedVersion = Introduced;
StringRef IntroducedPlatform = prettyPlatformString();
llvm::VersionTuple RemappedIntroducedVersion;
if (AvailabilityInference::updateIntroducedPlatformForFallback(
this, ctx, IntroducedPlatform, RemappedIntroducedVersion))
IntroducedVersion = RemappedIntroducedVersion;

// If this entity was introduced after the query version and we're doing a
// platform comparison, true availability can only be determined dynamically;
// if we're doing a _language_ version check, the query version is a
// static requirement, so we treat "introduced later" as just plain
// unavailable.
if (Introduced && *Introduced > queryVersion) {
if (IntroducedVersion && *IntroducedVersion > queryVersion) {
if (isLanguageVersionSpecific() || isPackageDescriptionVersionSpecific())
return AvailableVersionComparison::Unavailable;
else
Expand Down
Loading