Skip to content

Commit 1dc37df

Browse files
committed
Simplify add_apple_sdk
Reduce indentation and avoid needless checks (checking the target OS and vendor is unnecessary).
1 parent fce0e74 commit 1dc37df

File tree

1 file changed

+20
-25
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+20
-25
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,39 +3194,34 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
31943194
}
31953195

31963196
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> {
3197-
let os = &sess.target.os;
3198-
if sess.target.vendor != "apple"
3199-
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
3200-
|| !matches!(flavor, LinkerFlavor::Darwin(..))
3201-
{
3197+
if !sess.target.is_like_darwin {
32023198
return None;
32033199
}
3204-
3205-
if os == "macos" && !matches!(flavor, LinkerFlavor::Darwin(Cc::No, _)) {
3200+
let LinkerFlavor::Darwin(cc, _) = flavor else {
3201+
return None;
3202+
};
3203+
if os == "macos" && cc != Cc::No {
3204+
// FIXME(madsmtm): Remove this branch.
32063205
return None;
32073206
}
32083207

3209-
let sdk_root = sess.time("get_apple_sdk_root", || get_apple_sdk_root(sess))?;
3208+
let sdkroot = sess.time("get_apple_sdk_root", || get_apple_sdk_root(sess))?;
32103209

3211-
match flavor {
3212-
LinkerFlavor::Darwin(Cc::Yes, _) => {
3213-
// Use `-isysroot` instead of `--sysroot`, as only the former
3214-
// makes Clang treat it as a platform SDK.
3215-
//
3216-
// This is admittedly a bit strange, as on most targets
3217-
// `-isysroot` only applies to include header files, but on Apple
3218-
// targets this also applies to libraries and frameworks.
3219-
cmd.cc_arg("-isysroot");
3220-
cmd.cc_arg(&sdk_root);
3221-
}
3222-
LinkerFlavor::Darwin(Cc::No, _) => {
3223-
cmd.link_arg("-syslibroot");
3224-
cmd.link_arg(&sdk_root);
3225-
}
3226-
_ => unreachable!(),
3210+
if cc == Cc::Yes {
3211+
// Use `-isysroot` instead of `--sysroot`, as only the former
3212+
// makes Clang treat it as a platform SDK.
3213+
//
3214+
// This is admittedly a bit strange, as on most targets
3215+
// `-isysroot` only applies to include header files, but on Apple
3216+
// targets this also applies to libraries and frameworks.
3217+
cmd.cc_arg("-isysroot");
3218+
cmd.cc_arg(&sdk_root);
3219+
} else {
3220+
cmd.link_arg("-syslibroot");
3221+
cmd.link_arg(&sdkroot);
32273222
}
32283223

3229-
Some(sdk_root)
3224+
Some(sdkroot)
32303225
}
32313226

32323227
fn get_apple_sdk_root(sess: &Session) -> Option<PathBuf> {

0 commit comments

Comments
 (0)