Skip to content

Commit 4447f46

Browse files
[clang][modules] Enable built-in modules for the upcoming Apple releases (llvm#102239)
The upcoming Apple SDK releases will support the clang built-in headers being in the clang built-in modules: stop passing -fbuiltin-headers-in-system-modules for those SDK versions. (cherry picked from commit 9616399)
1 parent ba34f8a commit 4447f46

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,20 +2984,45 @@ bool Darwin::isAlignedAllocationUnavailable() const {
29842984
return TargetVersion < alignedAllocMinVersion(OS);
29852985
}
29862986

2987-
static bool sdkSupportsBuiltinModules(const Darwin::DarwinPlatformKind &TargetPlatform, const Optional<DarwinSDKInfo> &SDKInfo) {
2987+
static bool sdkSupportsBuiltinModules(
2988+
const Darwin::DarwinPlatformKind &TargetPlatform,
2989+
const Darwin::DarwinEnvironmentKind &TargetEnvironment,
2990+
const Optional<DarwinSDKInfo> &SDKInfo) {
2991+
switch (TargetEnvironment) {
2992+
case Darwin::NativeEnvironment:
2993+
case Darwin::Simulator:
2994+
case Darwin::MacCatalyst:
2995+
// Standard xnu/Mach/Darwin based environments
2996+
// depend on the SDK version.
2997+
break;
2998+
default:
2999+
// All other environments support builtin modules from the start.
3000+
return true;
3001+
}
3002+
29883003
if (!SDKInfo)
3004+
// If there is no SDK info, assume this is building against a
3005+
// pre-SDK version of macOS (i.e. before Mac OS X 10.4). Those
3006+
// don't support modules anyway, but the headers definitely
3007+
// don't support builtin modules either. It might also be some
3008+
// kind of degenerate build environment, err on the side of
3009+
// the old behavior which is to not use builtin modules.
29893010
return false;
29903011

29913012
VersionTuple SDKVersion = SDKInfo->getVersion();
29923013
switch (TargetPlatform) {
3014+
// Existing SDKs added support for builtin modules in the fall
3015+
// 2024 major releases.
29933016
case Darwin::MacOS:
2994-
return SDKVersion >= VersionTuple(99U);
3017+
return SDKVersion >= VersionTuple(15U);
29953018
case Darwin::IPhoneOS:
2996-
return SDKVersion >= VersionTuple(99U);
3019+
return SDKVersion >= VersionTuple(18U);
29973020
case Darwin::TvOS:
2998-
return SDKVersion >= VersionTuple(99U);
3021+
return SDKVersion >= VersionTuple(18U);
29993022
case Darwin::WatchOS:
3000-
return SDKVersion >= VersionTuple(99U);
3023+
return SDKVersion >= VersionTuple(11U);
3024+
3025+
// New SDKs support builtin modules from the start.
30013026
default:
30023027
return true;
30033028
}
@@ -3086,7 +3111,7 @@ void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
30863111
// i.e. when the builtin stdint.h is in the Darwin module too, the cycle
30873112
// goes away. Note that -fbuiltin-headers-in-system-modules does nothing
30883113
// to fix the same problem with C++ headers, and is generally fragile.
3089-
if (!sdkSupportsBuiltinModules(TargetPlatform, SDKInfo))
3114+
if (!sdkSupportsBuiltinModules(TargetPlatform, TargetEnvironment, SDKInfo))
30903115
CC1Args.push_back("-fbuiltin-headers-in-system-modules");
30913116
}
30923117

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)