Skip to content

Commit a0bfc8c

Browse files
authored
Merge pull request swiftlang#9061 from ian-twilightcoder/enable_builtin_modules
[cherry-pick swift/release/6.0][clang][modules] Enable built-in modules for the upcoming Apple releases
2 parents 2069024 + 4091c4b commit a0bfc8c

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,22 +3081,45 @@ bool Darwin::isAlignedAllocationUnavailable() const {
30813081
return TargetVersion < alignedAllocMinVersion(OS);
30823082
}
30833083

3084-
static bool sdkSupportsBuiltinModules(const Darwin::DarwinPlatformKind &TargetPlatform, const std::optional<DarwinSDKInfo> &SDKInfo) {
3084+
static bool sdkSupportsBuiltinModules(
3085+
const Darwin::DarwinPlatformKind &TargetPlatform,
3086+
const Darwin::DarwinEnvironmentKind &TargetEnvironment,
3087+
const std::optional<DarwinSDKInfo> &SDKInfo) {
3088+
if (TargetEnvironment == Darwin::NativeEnvironment ||
3089+
TargetEnvironment == Darwin::Simulator ||
3090+
TargetEnvironment == Darwin::MacCatalyst) {
3091+
// Standard xnu/Mach/Darwin based environments
3092+
// depend on the SDK version.
3093+
} else {
3094+
// All other environments support builtin modules from the start.
3095+
return true;
3096+
}
3097+
30853098
if (!SDKInfo)
3099+
// If there is no SDK info, assume this is building against a
3100+
// pre-SDK version of macOS (i.e. before Mac OS X 10.4). Those
3101+
// don't support modules anyway, but the headers definitely
3102+
// don't support builtin modules either. It might also be some
3103+
// kind of degenerate build environment, err on the side of
3104+
// the old behavior which is to not use builtin modules.
30863105
return false;
30873106

30883107
VersionTuple SDKVersion = SDKInfo->getVersion();
30893108
switch (TargetPlatform) {
3109+
// Existing SDKs added support for builtin modules in the fall
3110+
// 2024 major releases.
30903111
case Darwin::MacOS:
3091-
return SDKVersion >= VersionTuple(99U);
3112+
return SDKVersion >= VersionTuple(15U);
30923113
case Darwin::IPhoneOS:
3093-
return SDKVersion >= VersionTuple(99U);
3114+
return SDKVersion >= VersionTuple(18U);
30943115
case Darwin::TvOS:
3095-
return SDKVersion >= VersionTuple(99U);
3116+
return SDKVersion >= VersionTuple(18U);
30963117
case Darwin::WatchOS:
3097-
return SDKVersion >= VersionTuple(99U);
3118+
return SDKVersion >= VersionTuple(11U);
30983119
case Darwin::XROS:
3099-
return SDKVersion >= VersionTuple(99U);
3120+
return SDKVersion >= VersionTuple(2U);
3121+
3122+
// New SDKs support builtin modules from the start.
31003123
default:
31013124
return true;
31023125
}
@@ -3136,7 +3159,7 @@ void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
31363159
// i.e. when the builtin stdint.h is in the Darwin module too, the cycle
31373160
// goes away. Note that -fbuiltin-headers-in-system-modules does nothing
31383161
// to fix the same problem with C++ headers, and is generally fragile.
3139-
if (!sdkSupportsBuiltinModules(TargetPlatform, SDKInfo))
3162+
if (!sdkSupportsBuiltinModules(TargetPlatform, TargetEnvironment, SDKInfo))
31403163
CC1Args.push_back("-fbuiltin-headers-in-system-modules");
31413164
}
31423165

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"Version":"23.0", "MaximumDeploymentTarget": "23.0.99"}

clang/test/Driver/darwin-builtin-modules.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: %clang -isysroot %S/Inputs/iPhoneOS13.0.sdk -target arm64-apple-ios13.0 -### %s 2>&1 | FileCheck %s
77
// CHECK: -fbuiltin-headers-in-system-modules
88

9-
// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target x86_64-apple-macos98.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
10-
// RUN: %clang -isysroot %S/Inputs/MacOSX99.0.sdk -target x86_64-apple-macos99.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
9+
// RUN: %clang -isysroot %S/Inputs/MacOSX15.0.sdk -target x86_64-apple-macos14.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
10+
// RUN: %clang -isysroot %S/Inputs/MacOSX15.0.sdk -target x86_64-apple-macos15.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
11+
// RUN: %clang -isysroot %S/Inputs/DriverKit23.0.sdk -target arm64-apple-driverkit23.0 -### %s 2>&1 | FileCheck --check-prefix=CHECK_FUTURE %s
1112
// CHECK_FUTURE-NOT: -fbuiltin-headers-in-system-modules

0 commit comments

Comments
 (0)