Skip to content

Commit e75a7dd

Browse files
committed
Move Mach-O platform information to rustc_codegen_ssa::back::apple
To align with the general decision to have this sort of information there instead. Also use the visionOS values added in newer `object` release.
1 parent e123315 commit e75a7dd

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

compiler/rustc_codegen_ssa/src/back/apple.rs

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ use rustc_target::spec::Target;
77
#[cfg(test)]
88
mod tests;
99

10+
pub(super) fn macho_platform(target: &Target) -> u32 {
11+
match (&*target.os, &*target.abi) {
12+
("macos", _) => object::macho::PLATFORM_MACOS,
13+
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
14+
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,
15+
("ios", _) => object::macho::PLATFORM_IOS,
16+
("watchos", "sim") => object::macho::PLATFORM_WATCHOSSIMULATOR,
17+
("watchos", _) => object::macho::PLATFORM_WATCHOS,
18+
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
19+
("tvos", _) => object::macho::PLATFORM_TVOS,
20+
("visionos", "sim") => object::macho::PLATFORM_XROSSIMULATOR,
21+
("visionos", _) => object::macho::PLATFORM_XROS,
22+
_ => unreachable!("tried to get Mach-O platform for non-Apple target"),
23+
}
24+
}
25+
1026
/// Deployment target or SDK version.
1127
///
1228
/// The size of the numbers in here are limited by Mach-O's `LC_BUILD_VERSION`.

compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ fn macho_object_build_version_for_target(sess: &Session) -> object::write::MachO
402402
(major << 16) | (minor << 8) | patch
403403
}
404404

405-
let platform =
406-
rustc_target::spec::current_apple_platform(&sess.target).expect("unknown Apple target OS");
405+
let platform = apple::macho_platform(&sess.target);
407406
let min_os = apple::deployment_target(sess);
408407

409408
let mut build_version = object::write::MachOBuildVersion::default();

compiler/rustc_target/src/spec/base/apple/mod.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::env;
33

44
use crate::spec::{
55
Cc, DebuginfoKind, FramePointer, LinkerFlavor, Lld, SplitDebuginfo, StackProbeType, StaticCow,
6-
Target, TargetOptions, cvs,
6+
TargetOptions, cvs,
77
};
88

99
#[cfg(test)]
@@ -156,23 +156,6 @@ pub(crate) fn base(
156156
(opts, unversioned_llvm_target(os, arch, abi), arch.target_arch())
157157
}
158158

159-
pub fn platform(target: &Target) -> Option<u32> {
160-
Some(match (&*target.os, &*target.abi) {
161-
("macos", _) => object::macho::PLATFORM_MACOS,
162-
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
163-
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,
164-
("ios", _) => object::macho::PLATFORM_IOS,
165-
("watchos", "sim") => object::macho::PLATFORM_WATCHOSSIMULATOR,
166-
("watchos", _) => object::macho::PLATFORM_WATCHOS,
167-
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
168-
("tvos", _) => object::macho::PLATFORM_TVOS,
169-
// FIXME: Upgrade to `object-rs` 0.33+ implementation with visionOS platform definition
170-
("visionos", "sim") => 12,
171-
("visionos", _) => 11,
172-
_ => return None,
173-
})
174-
}
175-
176159
/// Generate part of the LLVM target triple.
177160
///
178161
/// See `rustc_codegen_ssa::back::versioned_llvm_target` for the full triple passed to LLVM and

compiler/rustc_target/src/spec/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub mod abi;
5959
pub mod crt_objects;
6060

6161
mod base;
62-
pub use base::apple::platform as current_apple_platform;
6362
pub use base::avr_gnu::ef_avr_arch;
6463

6564
/// Linker is called through a C/C++ compiler.

0 commit comments

Comments
 (0)