Skip to content

Commit 5184310

Browse files
committed
Document a bit more how the SDK version actually works
1 parent 612796c commit 5184310

File tree

1 file changed

+39
-7
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+39
-7
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,11 +2959,12 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
29592959
}
29602960
}
29612961

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:
29632963
/// - The architecture.
29642964
/// - The operating system (and that it's an Apple platform).
2965-
/// - The deployment target.
29662965
/// - The environment / ABI.
2966+
/// - The deployment target.
2967+
/// - The SDK version.
29672968
fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29682969
if !sess.target.is_like_osx {
29692970
return;
@@ -3039,7 +3040,36 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30393040
let (major, minor, patch) = current_apple_deployment_target(&sess.target);
30403041
let min_version = format!("{major}.{minor}.{patch}");
30413042

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.
3045+
// - By system frameworks to change certain behaviour. For example, the default value of
3046+
// `-[NSView wantsBestResolutionOpenGLSurface]` is `YES` when the SDK version is >= 10.15.
3047+
// <https://developer.apple.com/documentation/appkit/nsview/1414938-wantsbestresolutionopenglsurface?language=objc>
3048+
//
3049+
// We do not currently know the actual SDK version though, so we have a few options:
3050+
// 1. Use the minimum version supported by rustc.
3051+
// 2. Use the same as the deployment target.
3052+
// 3. Use an arbitary recent version.
3053+
// 4. Omit the version.
3054+
//
3055+
// The first option is too low / too conservative, and means that users will not get the
3056+
// same behaviour from a binary compiled with rustc as with one compiled by clang.
3057+
//
3058+
// The second option is similarly conservative, and also wrong since if the user specified a
3059+
// higher deployment target than the SDK they're compiling/linking with, the runtime might
3060+
// make invalid assumptions about the capabilities of the binary.
3061+
//
3062+
// The third option requires that `rustc` is periodically kept up to date with Apple's SDK
3063+
// version, and is also wrong for similar reasons as above.
3064+
//
3065+
// The fourth option is bad because while `ld`, `otool`, `vtool` and such understand it to
3066+
// mean "absent" or `n/a`, dyld doesn't actually understand it, and will end up interpreting
3067+
// it as 0.0, which is again too low/conservative.
3068+
//
3069+
// Currently, we lie about the SDK version, and choose the second option.
3070+
//
3071+
// FIXME(madsmtm): Parse the SDK version from the SDK root instead.
3072+
// <https://github.com/rust-lang/rust/issues/129432>
30433073
let sdk_version = &*min_version;
30443074

30453075
// From the man page for ld64 (`man ld`):
@@ -3053,11 +3083,13 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
30533083
cmd.link_args(&["-platform_version", platform_name, &*min_version, sdk_version]);
30543084
} else {
30553085
// cc == Cc::Yes
3086+
//
30563087
// 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.
3088+
// communicate all the required details except for the SDK version
3089+
// (which is read by Clang itself from the SDKROOT), but that doesn't
3090+
// work on GCC, and since we don't know whether the `cc` compiler is
3091+
// Clang, GCC, or something else, we fall back to other options that
3092+
// also work on GCC when compiling for macOS.
30613093
//
30623094
// Targets other than macOS are ill-supported by GCC (it doesn't even
30633095
// support e.g. `-miphoneos-version-min`), so in those cases we can

0 commit comments

Comments
 (0)