@@ -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
0 commit comments