Skip to content

Commit 8d764b1

Browse files
release/19.x: [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.
1 parent d033ae1 commit 8d764b1

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,22 +2923,47 @@ bool Darwin::isAlignedAllocationUnavailable() const {
29232923
return TargetVersion < alignedAllocMinVersion(OS);
29242924
}
29252925

2926-
static bool sdkSupportsBuiltinModules(const Darwin::DarwinPlatformKind &TargetPlatform, const std::optional<DarwinSDKInfo> &SDKInfo) {
2926+
static bool sdkSupportsBuiltinModules(
2927+
const Darwin::DarwinPlatformKind &TargetPlatform,
2928+
const Darwin::DarwinEnvironmentKind &TargetEnvironment,
2929+
const std::optional<DarwinSDKInfo> &SDKInfo) {
2930+
switch (TargetEnvironment) {
2931+
case Darwin::NativeEnvironment:
2932+
case Darwin::Simulator:
2933+
case Darwin::MacCatalyst:
2934+
// Standard xnu/Mach/Darwin based environments
2935+
// depend on the SDK version.
2936+
break;
2937+
default:
2938+
// All other environments support builtin modules from the start.
2939+
return true;
2940+
}
2941+
29272942
if (!SDKInfo)
2943+
// If there is no SDK info, assume this is building against a
2944+
// pre-SDK version of macOS (i.e. before Mac OS X 10.4). Those
2945+
// don't support modules anyway, but the headers definitely
2946+
// don't support builtin modules either. It might also be some
2947+
// kind of degenerate build environment, err on the side of
2948+
// the old behavior which is to not use builtin modules.
29282949
return false;
29292950

29302951
VersionTuple SDKVersion = SDKInfo->getVersion();
29312952
switch (TargetPlatform) {
2953+
// Existing SDKs added support for builtin modules in the fall
2954+
// 2024 major releases.
29322955
case Darwin::MacOS:
2933-
return SDKVersion >= VersionTuple(99U);
2956+
return SDKVersion >= VersionTuple(15U);
29342957
case Darwin::IPhoneOS:
2935-
return SDKVersion >= VersionTuple(99U);
2958+
return SDKVersion >= VersionTuple(18U);
29362959
case Darwin::TvOS:
2937-
return SDKVersion >= VersionTuple(99U);
2960+
return SDKVersion >= VersionTuple(18U);
29382961
case Darwin::WatchOS:
2939-
return SDKVersion >= VersionTuple(99U);
2962+
return SDKVersion >= VersionTuple(11U);
29402963
case Darwin::XROS:
2941-
return SDKVersion >= VersionTuple(99U);
2964+
return SDKVersion >= VersionTuple(2U);
2965+
2966+
// New SDKs support builtin modules from the start.
29422967
default:
29432968
return true;
29442969
}
@@ -3030,7 +3055,7 @@ void Darwin::addClangTargetOptions(
30303055
// i.e. when the builtin stdint.h is in the Darwin module too, the cycle
30313056
// goes away. Note that -fbuiltin-headers-in-system-modules does nothing
30323057
// to fix the same problem with C++ headers, and is generally fragile.
3033-
if (!sdkSupportsBuiltinModules(TargetPlatform, SDKInfo))
3058+
if (!sdkSupportsBuiltinModules(TargetPlatform, TargetEnvironment, SDKInfo))
30343059
CC1Args.push_back("-fbuiltin-headers-in-system-modules");
30353060

30363061
if (!DriverArgs.hasArgNoClaim(options::OPT_fdefine_target_os_macros,
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)