@@ -3081,22 +3081,47 @@ bool Darwin::isAlignedAllocationUnavailable() const {
3081
3081
return TargetVersion < alignedAllocMinVersion (OS);
3082
3082
}
3083
3083
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
+ switch (TargetEnvironment) {
3089
+ case Darwin::NativeEnvironment:
3090
+ case Darwin::Simulator:
3091
+ case Darwin::MacCatalyst:
3092
+ // Standard xnu/Mach/Darwin based environments
3093
+ // depend on the SDK version.
3094
+ break ;
3095
+ default :
3096
+ // All other environments support builtin modules from the start.
3097
+ return true ;
3098
+ }
3099
+
3085
3100
if (!SDKInfo)
3101
+ // If there is no SDK info, assume this is building against a
3102
+ // pre-SDK version of macOS (i.e. before Mac OS X 10.4). Those
3103
+ // don't support modules anyway, but the headers definitely
3104
+ // don't support builtin modules either. It might also be some
3105
+ // kind of degenerate build environment, err on the side of
3106
+ // the old behavior which is to not use builtin modules.
3086
3107
return false ;
3087
3108
3088
3109
VersionTuple SDKVersion = SDKInfo->getVersion ();
3089
3110
switch (TargetPlatform) {
3111
+ // Existing SDKs added support for builtin modules in the fall
3112
+ // 2024 major releases.
3090
3113
case Darwin::MacOS:
3091
- return SDKVersion >= VersionTuple (99U );
3114
+ return SDKVersion >= VersionTuple (15U );
3092
3115
case Darwin::IPhoneOS:
3093
- return SDKVersion >= VersionTuple (99U );
3116
+ return SDKVersion >= VersionTuple (18U );
3094
3117
case Darwin::TvOS:
3095
- return SDKVersion >= VersionTuple (99U );
3118
+ return SDKVersion >= VersionTuple (18U );
3096
3119
case Darwin::WatchOS:
3097
- return SDKVersion >= VersionTuple (99U );
3120
+ return SDKVersion >= VersionTuple (11U );
3098
3121
case Darwin::XROS:
3099
- return SDKVersion >= VersionTuple (99U );
3122
+ return SDKVersion >= VersionTuple (2U );
3123
+
3124
+ // New SDKs support builtin modules from the start.
3100
3125
default :
3101
3126
return true ;
3102
3127
}
@@ -3136,7 +3161,7 @@ void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
3136
3161
// i.e. when the builtin stdint.h is in the Darwin module too, the cycle
3137
3162
// goes away. Note that -fbuiltin-headers-in-system-modules does nothing
3138
3163
// to fix the same problem with C++ headers, and is generally fragile.
3139
- if (!sdkSupportsBuiltinModules (TargetPlatform, SDKInfo))
3164
+ if (!sdkSupportsBuiltinModules (TargetPlatform, TargetEnvironment, SDKInfo))
3140
3165
CC1Args.push_back (" -fbuiltin-headers-in-system-modules" );
3141
3166
}
3142
3167
0 commit comments