Skip to content

Commit 713becd

Browse files
committed
refactor: Move Apple SDK names to rustc_codegen_ssa::back::apple
1 parent 7d49ae9 commit 713becd

File tree

4 files changed

+21
-36
lines changed

4 files changed

+21
-36
lines changed

compiler/rustc_codegen_ssa/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ codegen_ssa_unknown_atomic_ordering = unknown ordering in atomic intrinsic
391391
392392
codegen_ssa_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified
393393
394-
codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
395-
396394
codegen_ssa_unsupported_instruction_set = target does not support `#[instruction_set]`
397395
398396
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target

compiler/rustc_codegen_ssa/src/back/apple.rs

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ use crate::errors::AppleDeploymentTarget;
1111
#[cfg(test)]
1212
mod tests;
1313

14+
/// The canonical name of the desired SDK for a given target.
15+
pub(super) fn sdk_name(target: &Target) -> &'static str {
16+
match (&*target.os, &*target.abi) {
17+
("macos", "") => "MacOSX",
18+
("ios", "") => "iPhoneOS",
19+
("ios", "sim") => "iPhoneSimulator",
20+
// Mac Catalyst uses the macOS SDK
21+
("ios", "macabi") => "MacOSX",
22+
("tvos", "") => "AppleTVOS",
23+
("tvos", "sim") => "AppleTVSimulator",
24+
("visionos", "") => "XROS",
25+
("visionos", "sim") => "XRSimulator",
26+
("watchos", "") => "WatchOS",
27+
("watchos", "sim") => "WatchSimulator",
28+
(os, abi) => unreachable!("invalid os '{os}' / abi '{abi}' combination for Apple target"),
29+
}
30+
}
31+
1432
pub(super) fn macho_platform(target: &Target) -> u32 {
1533
match (&*target.os, &*target.abi) {
1634
("macos", _) => object::macho::PLATFORM_MACOS,

compiler/rustc_codegen_ssa/src/back/link.rs

+3-27
Original file line numberDiff line numberDiff line change
@@ -3201,9 +3201,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
32013201
}
32023202

32033203
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> {
3204-
let arch = &sess.target.arch;
32053204
let os = &sess.target.os;
3206-
let llvm_target = &sess.target.llvm_target;
32073205
if sess.target.vendor != "apple"
32083206
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
32093207
|| !matches!(flavor, LinkerFlavor::Darwin(..))
@@ -3215,31 +3213,9 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) ->
32153213
return None;
32163214
}
32173215

3218-
let sdk_name = match (arch.as_ref(), os.as_ref()) {
3219-
("aarch64", "tvos") if llvm_target.ends_with("-simulator") => "appletvsimulator",
3220-
("aarch64", "tvos") => "appletvos",
3221-
("x86_64", "tvos") => "appletvsimulator",
3222-
("arm", "ios") => "iphoneos",
3223-
("aarch64", "ios") if llvm_target.contains("macabi") => "macosx",
3224-
("aarch64", "ios") if llvm_target.ends_with("-simulator") => "iphonesimulator",
3225-
("aarch64", "ios") => "iphoneos",
3226-
("x86", "ios") => "iphonesimulator",
3227-
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx",
3228-
("x86_64", "ios") => "iphonesimulator",
3229-
("x86_64", "watchos") => "watchsimulator",
3230-
("arm64_32", "watchos") => "watchos",
3231-
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
3232-
("aarch64", "watchos") => "watchos",
3233-
("aarch64", "visionos") if llvm_target.ends_with("-simulator") => "xrsimulator",
3234-
("aarch64", "visionos") => "xros",
3235-
("arm", "watchos") => "watchos",
3236-
(_, "macos") => "macosx",
3237-
_ => {
3238-
sess.dcx().emit_err(errors::UnsupportedArch { arch, os });
3239-
return None;
3240-
}
3241-
};
3242-
let sdk_root = match get_apple_sdk_root(sdk_name) {
3216+
let sdk_name = apple::sdk_name(&sess.target).to_lowercase();
3217+
3218+
let sdk_root = match get_apple_sdk_root(&sdk_name) {
32433219
Ok(s) => s,
32443220
Err(e) => {
32453221
sess.dcx().emit_err(e);

compiler/rustc_codegen_ssa/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,6 @@ pub enum ExtractBundledLibsError<'a> {
738738
ExtractSection { rlib: &'a Path, error: Box<dyn std::error::Error> },
739739
}
740740

741-
#[derive(Diagnostic)]
742-
#[diag(codegen_ssa_unsupported_arch)]
743-
pub(crate) struct UnsupportedArch<'a> {
744-
pub arch: &'a str,
745-
pub os: &'a str,
746-
}
747-
748741
#[derive(Diagnostic)]
749742
pub(crate) enum AppleDeploymentTarget {
750743
#[diag(codegen_ssa_apple_deployment_target_invalid)]

0 commit comments

Comments
 (0)