@@ -2923,22 +2923,47 @@ bool Darwin::isAlignedAllocationUnavailable() const {
2923
2923
return TargetVersion < alignedAllocMinVersion (OS);
2924
2924
}
2925
2925
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
+
2927
2942
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.
2928
2949
return false ;
2929
2950
2930
2951
VersionTuple SDKVersion = SDKInfo->getVersion ();
2931
2952
switch (TargetPlatform) {
2953
+ // Existing SDKs added support for builtin modules in the fall
2954
+ // 2024 major releases.
2932
2955
case Darwin::MacOS:
2933
- return SDKVersion >= VersionTuple (99U );
2956
+ return SDKVersion >= VersionTuple (15U );
2934
2957
case Darwin::IPhoneOS:
2935
- return SDKVersion >= VersionTuple (99U );
2958
+ return SDKVersion >= VersionTuple (18U );
2936
2959
case Darwin::TvOS:
2937
- return SDKVersion >= VersionTuple (99U );
2960
+ return SDKVersion >= VersionTuple (18U );
2938
2961
case Darwin::WatchOS:
2939
- return SDKVersion >= VersionTuple (99U );
2962
+ return SDKVersion >= VersionTuple (11U );
2940
2963
case Darwin::XROS:
2941
- return SDKVersion >= VersionTuple (99U );
2964
+ return SDKVersion >= VersionTuple (2U );
2965
+
2966
+ // New SDKs support builtin modules from the start.
2942
2967
default :
2943
2968
return true ;
2944
2969
}
@@ -3030,7 +3055,7 @@ void Darwin::addClangTargetOptions(
3030
3055
// i.e. when the builtin stdint.h is in the Darwin module too, the cycle
3031
3056
// goes away. Note that -fbuiltin-headers-in-system-modules does nothing
3032
3057
// to fix the same problem with C++ headers, and is generally fragile.
3033
- if (!sdkSupportsBuiltinModules (TargetPlatform, SDKInfo))
3058
+ if (!sdkSupportsBuiltinModules (TargetPlatform, TargetEnvironment, SDKInfo))
3034
3059
CC1Args.push_back (" -fbuiltin-headers-in-system-modules" );
3035
3060
3036
3061
if (!DriverArgs.hasArgNoClaim (options::OPT_fdefine_target_os_macros,
0 commit comments