@@ -2959,11 +2959,12 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
2959
2959
}
2960
2960
}
2961
2961
2962
- /// We need to communicate four things to the linker on Apple/Darwin targets:
2962
+ /// We need to communicate five things to the linker on Apple/Darwin targets:
2963
2963
/// - The architecture.
2964
2964
/// - The operating system (and that it's an Apple platform).
2965
- /// - The deployment target.
2966
2965
/// - The environment / ABI.
2966
+ /// - The deployment target.
2967
+ /// - The SDK version.
2967
2968
fn add_apple_link_args ( cmd : & mut dyn Linker , sess : & Session , flavor : LinkerFlavor ) {
2968
2969
if !sess. target . is_like_osx {
2969
2970
return ;
@@ -3039,7 +3040,38 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
3039
3040
let ( major, minor, patch) = current_apple_deployment_target ( & sess. target ) ;
3040
3041
let min_version = format ! ( "{major}.{minor}.{patch}" ) ;
3041
3042
3042
- // Lie about the SDK version, we don't know it here
3043
+ // The SDK version is used at runtime when compiling with a newer SDK / version of Xcode:
3044
+ // - By dyld to give extra warnings and errors, see e.g.:
3045
+ // <https://github.com/apple-oss-distributions/dyld/blob/dyld-1165.3/common/MachOFile.cpp#L3029>
3046
+ // <https://github.com/apple-oss-distributions/dyld/blob/dyld-1165.3/common/MachOFile.cpp#L3738-L3857>
3047
+ // - By system frameworks to change certain behaviour. For example, the default value of
3048
+ // `-[NSView wantsBestResolutionOpenGLSurface]` is `YES` when the SDK version is >= 10.15.
3049
+ // <https://developer.apple.com/documentation/appkit/nsview/1414938-wantsbestresolutionopenglsurface?language=objc>
3050
+ //
3051
+ // We do not currently know the actual SDK version though, so we have a few options:
3052
+ // 1. Use the minimum version supported by rustc.
3053
+ // 2. Use the same as the deployment target.
3054
+ // 3. Use an arbitary recent version.
3055
+ // 4. Omit the version.
3056
+ //
3057
+ // The first option is too low / too conservative, and means that users will not get the
3058
+ // same behaviour from a binary compiled with rustc as with one compiled by clang.
3059
+ //
3060
+ // The second option is similarly conservative, and also wrong since if the user specified a
3061
+ // higher deployment target than the SDK they're compiling/linking with, the runtime might
3062
+ // make invalid assumptions about the capabilities of the binary.
3063
+ //
3064
+ // The third option requires that `rustc` is periodically kept up to date with Apple's SDK
3065
+ // version, and is also wrong for similar reasons as above.
3066
+ //
3067
+ // The fourth option is bad because while `ld`, `otool`, `vtool` and such understand it to
3068
+ // mean "absent" or `n/a`, dyld doesn't actually understand it, and will end up interpreting
3069
+ // it as 0.0, which is again too low/conservative.
3070
+ //
3071
+ // Currently, we lie about the SDK version, and choose the second option.
3072
+ //
3073
+ // FIXME(madsmtm): Parse the SDK version from the SDK root instead.
3074
+ // <https://github.com/rust-lang/rust/issues/129432>
3043
3075
let sdk_version = & * min_version;
3044
3076
3045
3077
// From the man page for ld64 (`man ld`):
@@ -3053,11 +3085,13 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
3053
3085
cmd. link_args ( & [ "-platform_version" , platform_name, & * min_version, sdk_version] ) ;
3054
3086
} else {
3055
3087
// cc == Cc::Yes
3088
+ //
3056
3089
// We'd _like_ to use `-target` everywhere, since that can uniquely
3057
- // communicate all the required details, but that doesn't work on GCC,
3058
- // and since we don't know whether the `cc` compiler is Clang, GCC, or
3059
- // something else, we fall back to other options that also work on GCC
3060
- // when compiling for macOS.
3090
+ // communicate all the required details except for the SDK version
3091
+ // (which is read by Clang itself from the SDKROOT), but that doesn't
3092
+ // work on GCC, and since we don't know whether the `cc` compiler is
3093
+ // Clang, GCC, or something else, we fall back to other options that
3094
+ // also work on GCC when compiling for macOS.
3061
3095
//
3062
3096
// Targets other than macOS are ill-supported by GCC (it doesn't even
3063
3097
// support e.g. `-miphoneos-version-min`), so in those cases we can
0 commit comments