Skip to content

Commit f272fc3

Browse files
committed
Auto merge of #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 #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

Diff for: compiler/rustc_target/src/spec/aarch64_apple_tvos.rs

+2-2
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(),

Diff for: compiler/rustc_target/src/spec/apple/tests.rs

+4-1
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
}

Diff for: compiler/rustc_target/src/spec/apple_base.rs

+17-1
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))

Diff for: compiler/rustc_target/src/spec/x86_64_apple_tvos.rs

+4-3
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),

Diff for: library/core/src/ffi/mod.rs

+16-7
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"),

Diff for: library/std/build.rs

+1-1
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.

Diff for: library/std/src/fs/tests.rs

+25-3
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
}

Diff for: library/std/src/os/ios/fs.rs

+1-1
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
///

Diff for: library/std/src/os/mod.rs

+3
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")]

Diff for: library/std/src/os/unix/mod.rs

+3
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",

Diff for: library/std/src/os/unix/net/stream.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
1111
target_os = "dragonfly",
1212
target_os = "freebsd",
1313
target_os = "ios",
14+
target_os = "tvos",
1415
target_os = "macos",
1516
target_os = "watchos",
1617
target_os = "netbsd",
@@ -30,6 +31,7 @@ use crate::time::Duration;
3031
target_os = "dragonfly",
3132
target_os = "freebsd",
3233
target_os = "ios",
34+
target_os = "tvos",
3335
target_os = "macos",
3436
target_os = "watchos",
3537
target_os = "netbsd",
@@ -238,6 +240,7 @@ impl UnixStream {
238240
target_os = "dragonfly",
239241
target_os = "freebsd",
240242
target_os = "ios",
243+
target_os = "tvos",
241244
target_os = "macos",
242245
target_os = "watchos",
243246
target_os = "netbsd",

Diff for: library/std/src/os/unix/ucred.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
3636
))]
3737
pub use self::impl_bsd::peer_cred;
3838

39-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
39+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
4040
pub use self::impl_mac::peer_cred;
4141

4242
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -98,7 +98,7 @@ pub mod impl_bsd {
9898
}
9999
}
100100

101-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
101+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
102102
pub mod impl_mac {
103103
use super::UCred;
104104
use crate::os::unix::io::AsRawFd;

Diff for: library/std/src/os/unix/ucred/tests.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use libc::{getegid, geteuid, getpid};
88
target_os = "dragonfly",
99
target_os = "freebsd",
1010
target_os = "ios",
11+
target_os = "tvos",
1112
target_os = "macos",
1213
target_os = "watchos",
1314
target_os = "openbsd"
@@ -26,7 +27,13 @@ fn test_socket_pair() {
2627
}
2728

2829
#[test]
29-
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos", target_os = "watchos"))]
30+
#[cfg(any(
31+
target_os = "linux",
32+
target_os = "ios",
33+
target_os = "macos",
34+
target_os = "watchos",
35+
target_os = "tvos",
36+
))]
3037
fn test_socket_pair_pids(arg: Type) -> RetType {
3138
// Create two connected sockets and get their peer credentials.
3239
let (sock_a, sock_b) = UnixStream::pair().unwrap();

Diff for: library/std/src/personality/gcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const UNWIND_DATA_REG: (i32, i32) = (4, 5); // a0, a1
8585
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
8686

8787
cfg_if::cfg_if! {
88-
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
88+
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "tvos"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
8989
// ARM EHABI personality routine.
9090
// https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
9191
//

Diff for: library/std/src/sys/unix/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod imp {
168168
}
169169
}
170170

171-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
171+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
172172
mod imp {
173173
use super::Args;
174174
use crate::ffi::CStr;
@@ -209,7 +209,7 @@ mod imp {
209209
// for i in (0..[args count])
210210
// res.push([args objectAtIndex:i])
211211
// res
212-
#[cfg(any(target_os = "ios", target_os = "watchos"))]
212+
#[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos"))]
213213
pub fn args() -> Args {
214214
use crate::ffi::OsString;
215215
use crate::mem;

Diff for: library/std/src/sys/unix/env.rs

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ pub mod os {
3131
pub const EXE_EXTENSION: &str = "";
3232
}
3333

34+
#[cfg(target_os = "tvos")]
35+
pub mod os {
36+
pub const FAMILY: &str = "unix";
37+
pub const OS: &str = "tvos";
38+
pub const DLL_PREFIX: &str = "lib";
39+
pub const DLL_SUFFIX: &str = ".dylib";
40+
pub const DLL_EXTENSION: &str = "dylib";
41+
pub const EXE_SUFFIX: &str = "";
42+
pub const EXE_EXTENSION: &str = "";
43+
}
44+
3445
#[cfg(target_os = "watchos")]
3546
pub mod os {
3647
pub const FAMILY: &str = "unix";

0 commit comments

Comments
 (0)