Skip to content

Commit babb63c

Browse files
committed
refactor: Move Apple SDK names to rustc_codegen_ssa::back::apple
1 parent 39b5847 commit babb63c

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

compiler/rustc_codegen_ssa/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ codegen_ssa_unknown_atomic_ordering = unknown ordering in atomic intrinsic
385385
386386
codegen_ssa_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified
387387
388-
codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
389-
390388
codegen_ssa_unsupported_instruction_set = target does not support `#[instruction_set]`
391389
392390
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
@@ -5,6 +5,24 @@ pub(super) use rustc_target::spec::apple::OSVersion;
55
#[cfg(test)]
66
mod tests;
77

8+
/// The lowercase, canonical name of the desired SDK for a given target.
9+
pub(super) fn sdk_name(target: &Target) -> &'static str {
10+
match (&*target.os, &*target.abi) {
11+
("macos", "") => "macosx",
12+
("ios", "") => "iphoneos",
13+
("ios", "sim") => "iphonesimulator",
14+
// Mac Catalyst uses the macOS SDK
15+
("ios", "macabi") => "macosx",
16+
("tvos", "") => "appletvos",
17+
("tvos", "sim") => "appletvsimulator",
18+
("visionos", "") => "xros",
19+
("visionos", "sim") => "xrsimulator",
20+
("watchos", "") => "watchos",
21+
("watchos", "sim") => "watchsimulator",
22+
(os, abi) => unreachable!("invalid os '{os}' / abi '{abi}' combination for Apple target"),
23+
}
24+
}
25+
826
pub(super) fn macho_platform(target: &Target) -> u32 {
927
match (&*target.os, &*target.abi) {
1028
("macos", _) => object::macho::PLATFORM_MACOS,

compiler/rustc_codegen_ssa/src/back/link.rs

+2-26
Original file line numberDiff line numberDiff line change
@@ -3200,9 +3200,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
32003200
}
32013201

32023202
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> {
3203-
let arch = &sess.target.arch;
32043203
let os = &sess.target.os;
3205-
let llvm_target = &sess.target.llvm_target;
32063204
if sess.target.vendor != "apple"
32073205
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
32083206
|| !matches!(flavor, LinkerFlavor::Darwin(..))
@@ -3214,30 +3212,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) ->
32143212
return None;
32153213
}
32163214

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

compiler/rustc_codegen_ssa/src/errors.rs

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

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

0 commit comments

Comments
 (0)