Skip to content

Commit f272fc3

Browse files
committed
Auto merge of rust-lang#103503 - thomcc:tvos-support, r=workingjubilee
Support Apple tvOS in libstd This target has existed in the compiler for a while, was `no_std`-only previously (even requiring `#![feature(restricted_std)]`). Apple tvOS is essentially the same as iOS, down to using the same version numbering, so there's no reason for this to be a `no_std`-only target the way it is currently. Not yet tested much (I have an Apple TV, but haven't tested that this can deploy and run programs on it, nor the simulator). Uses the implementation strategy as the watchOS support in rust-lang#98101 and etc. That is, no `std::os::` interfaces aside from those in `std::os::unix`. Includes an update to libc in order to pull in rust-lang/libc#2958.
2 parents 065a1f5 + af0662f commit f272fc3

File tree

33 files changed

+313
-50
lines changed

33 files changed

+313
-50
lines changed

compiler/rustc_target/src/spec/aarch64_apple_tvos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::apple_base::{opts, Arch};
1+
use super::apple_base::{opts, tvos_llvm_target, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Arm64;
66
Target {
7-
llvm_target: "arm64-apple-tvos".into(),
7+
llvm_target: tvos_llvm_target(arch).into(),
88
pointer_width: 64,
99
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1010
arch: arch.target_arch(),

compiler/rustc_target/src/spec/apple/tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ fn macos_link_environment_unmodified() {
3030
for target in all_macos_targets {
3131
// macOS targets should only remove information for cross-compiling, but never
3232
// for the host.
33-
assert_eq!(target.link_env_remove, crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET"]);
33+
assert_eq!(
34+
target.link_env_remove,
35+
crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET", "TVOS_DEPLOYMENT_TARGET"],
36+
);
3437
}
3538
}

compiler/rustc_target/src/spec/apple_base.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
240240
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
241241
// may occur when we're linking a custom build script while targeting iOS for example.
242242
if let Ok(sdkroot) = env::var("SDKROOT") {
243-
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform")
243+
if sdkroot.contains("iPhoneOS.platform")
244+
|| sdkroot.contains("iPhoneSimulator.platform")
245+
|| sdkroot.contains("AppleTVOS.platform")
246+
|| sdkroot.contains("AppleTVSimulator.platform")
247+
|| sdkroot.contains("WatchOS.platform")
248+
|| sdkroot.contains("WatchSimulator.platform")
244249
{
245250
env_remove.push("SDKROOT".into())
246251
}
@@ -249,6 +254,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
249254
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
250255
// although this is apparently ignored when using the linker at "/usr/bin/ld".
251256
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
257+
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
252258
env_remove.into()
253259
} else {
254260
// Otherwise if cross-compiling for a different OS/SDK, remove any part
@@ -299,6 +305,16 @@ fn tvos_lld_platform_version() -> String {
299305
format!("{major}.{minor}")
300306
}
301307

308+
pub fn tvos_llvm_target(arch: Arch) -> String {
309+
let (major, minor) = tvos_deployment_target();
310+
format!("{}-apple-tvos{}.{}.0", arch.target_name(), major, minor)
311+
}
312+
313+
pub fn tvos_sim_llvm_target(arch: Arch) -> String {
314+
let (major, minor) = tvos_deployment_target();
315+
format!("{}-apple-tvos{}.{}.0-simulator", arch.target_name(), major, minor)
316+
}
317+
302318
fn watchos_deployment_target() -> (u32, u32) {
303319
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
304320
from_set_deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))

compiler/rustc_target/src/spec/x86_64_apple_tvos.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use super::apple_base::{opts, Arch};
1+
use super::apple_base::{opts, tvos_sim_llvm_target, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::X86_64_sim;
66
Target {
7-
llvm_target: "x86_64-apple-tvos".into(),
7+
llvm_target: tvos_sim_llvm_target(arch).into(),
88
pointer_width: 64,
9-
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(),
9+
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10+
.into(),
1011
arch: arch.target_arch(),
1112
options: TargetOptions {
1213
max_atomic_width: Some(128),

library/core/src/ffi/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl fmt::Debug for c_void {
238238
not(target_arch = "s390x"),
239239
not(target_arch = "x86_64")
240240
),
241-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
241+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
242242
target_family = "wasm",
243243
target_arch = "asmjs",
244244
target_os = "uefi",
@@ -267,7 +267,7 @@ pub struct VaListImpl<'f> {
267267
not(target_arch = "s390x"),
268268
not(target_arch = "x86_64")
269269
),
270-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
270+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
271271
target_family = "wasm",
272272
target_arch = "asmjs",
273273
target_os = "uefi",
@@ -292,7 +292,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
292292
/// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
293293
#[cfg(all(
294294
target_arch = "aarch64",
295-
not(any(target_os = "macos", target_os = "ios")),
295+
not(any(target_os = "macos", target_os = "ios", target_os = "tvos")),
296296
not(target_os = "uefi"),
297297
not(windows),
298298
))]
@@ -389,7 +389,10 @@ pub struct VaList<'a, 'f: 'a> {
389389
not(target_arch = "s390x"),
390390
not(target_arch = "x86_64")
391391
),
392-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
392+
all(
393+
target_arch = "aarch64",
394+
any(target_os = "macos", target_os = "ios", target_os = "tvos")
395+
),
393396
target_family = "wasm",
394397
target_arch = "asmjs",
395398
target_os = "uefi",
@@ -404,7 +407,10 @@ pub struct VaList<'a, 'f: 'a> {
404407
target_arch = "s390x",
405408
target_arch = "x86_64"
406409
),
407-
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
410+
any(
411+
not(target_arch = "aarch64"),
412+
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
413+
),
408414
not(target_family = "wasm"),
409415
not(target_arch = "asmjs"),
410416
not(target_os = "uefi"),
@@ -422,7 +428,7 @@ pub struct VaList<'a, 'f: 'a> {
422428
not(target_arch = "s390x"),
423429
not(target_arch = "x86_64")
424430
),
425-
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
431+
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
426432
target_family = "wasm",
427433
target_arch = "asmjs",
428434
target_os = "uefi",
@@ -449,7 +455,10 @@ impl<'f> VaListImpl<'f> {
449455
target_arch = "s390x",
450456
target_arch = "x86_64"
451457
),
452-
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
458+
any(
459+
not(target_arch = "aarch64"),
460+
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
461+
),
453462
not(target_family = "wasm"),
454463
not(target_arch = "asmjs"),
455464
not(target_os = "uefi"),

library/std/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn main() {
1818
|| target.contains("illumos")
1919
|| target.contains("apple-darwin")
2020
|| target.contains("apple-ios")
21+
|| target.contains("apple-tvos")
2122
|| target.contains("apple-watchos")
2223
|| target.contains("uwp")
2324
|| target.contains("windows")
@@ -48,7 +49,6 @@ fn main() {
4849
// - mipsel-sony-psp
4950
// - nvptx64-nvidia-cuda
5051
// - arch=avr
51-
// - tvos (aarch64-apple-tvos, x86_64-apple-tvos)
5252
// - uefi (x86_64-unknown-uefi, i686-unknown-uefi)
5353
// - JSON targets
5454
// - Any new targets that have not been explicitly added above.

library/std/src/fs/tests.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ fn test_file_times() {
16401640
use crate::os::ios::fs::FileTimesExt;
16411641
#[cfg(target_os = "macos")]
16421642
use crate::os::macos::fs::FileTimesExt;
1643+
#[cfg(target_os = "tvos")]
1644+
use crate::os::tvos::fs::FileTimesExt;
1645+
#[cfg(target_os = "tvos")]
1646+
use crate::os::tvos::fs::FileTimesExt;
16431647
#[cfg(target_os = "watchos")]
16441648
use crate::os::watchos::fs::FileTimesExt;
16451649
#[cfg(windows)]
@@ -1651,9 +1655,21 @@ fn test_file_times() {
16511655
let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345);
16521656
let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321);
16531657
times = times.set_accessed(accessed).set_modified(modified);
1654-
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
1658+
#[cfg(any(
1659+
windows,
1660+
target_os = "macos",
1661+
target_os = "ios",
1662+
target_os = "watchos",
1663+
target_os = "tvos",
1664+
))]
16551665
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
1656-
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
1666+
#[cfg(any(
1667+
windows,
1668+
target_os = "macos",
1669+
target_os = "ios",
1670+
target_os = "watchos",
1671+
target_os = "tvos",
1672+
))]
16571673
{
16581674
times = times.set_created(created);
16591675
}
@@ -1678,7 +1694,13 @@ fn test_file_times() {
16781694
let metadata = file.metadata().unwrap();
16791695
assert_eq!(metadata.accessed().unwrap(), accessed);
16801696
assert_eq!(metadata.modified().unwrap(), modified);
1681-
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
1697+
#[cfg(any(
1698+
windows,
1699+
target_os = "macos",
1700+
target_os = "ios",
1701+
target_os = "watchos",
1702+
target_os = "tvos",
1703+
))]
16821704
{
16831705
assert_eq!(metadata.created().unwrap(), created);
16841706
}

library/std/src/os/ios/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::sys_common::{AsInner, AsInnerMut, IntoInner};
66
use crate::time::SystemTime;
77

88
#[allow(deprecated)]
9-
use crate::os::ios::raw;
9+
use super::raw;
1010

1111
/// OS-specific extensions to [`fs::Metadata`].
1212
///

library/std/src/os/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ pub mod redox;
137137
pub mod solaris;
138138
#[cfg(target_os = "solid_asp3")]
139139
pub mod solid;
140+
#[cfg(target_os = "tvos")]
141+
#[path = "ios/mod.rs"]
142+
pub(crate) mod tvos;
140143
#[cfg(target_os = "vita")]
141144
pub mod vita;
142145
#[cfg(target_os = "vxworks")]

library/std/src/os/unix/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ mod platform {
7373
pub use crate::os::redox::*;
7474
#[cfg(target_os = "solaris")]
7575
pub use crate::os::solaris::*;
76+
#[cfg(target_os = "tvos")]
77+
pub use crate::os::tvos::*;
7678
#[cfg(target_os = "vita")]
7779
pub use crate::os::vita::*;
7880
#[cfg(target_os = "vxworks")]
@@ -96,6 +98,7 @@ pub mod thread;
9698
target_os = "dragonfly",
9799
target_os = "freebsd",
98100
target_os = "ios",
101+
target_os = "tvos",
99102
target_os = "watchos",
100103
target_os = "macos",
101104
target_os = "netbsd",

0 commit comments

Comments
 (0)