Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Apple tvOS in libstd #103503

Merged
merged 14 commits into from Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/aarch64_apple_tvos.rs
@@ -1,10 +1,10 @@
use super::apple_base::{opts, Arch};
use super::apple_base::{opts, tvos_llvm_target, Arch};
use crate::spec::{FramePointer, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64;
Target {
llvm_target: "arm64-apple-tvos".into(),
llvm_target: tvos_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: arch.target_arch(),
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_target/src/spec/apple/tests.rs
Expand Up @@ -30,6 +30,9 @@ fn macos_link_environment_unmodified() {
for target in all_macos_targets {
// macOS targets should only remove information for cross-compiling, but never
// for the host.
assert_eq!(target.link_env_remove, crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET"]);
assert_eq!(
target.link_env_remove,
crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET", "TVOS_DEPLOYMENT_TARGET"],
);
}
}
18 changes: 17 additions & 1 deletion compiler/rustc_target/src/spec/apple_base.rs
Expand Up @@ -240,7 +240,12 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
// may occur when we're linking a custom build script while targeting iOS for example.
if let Ok(sdkroot) = env::var("SDKROOT") {
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform")
if sdkroot.contains("iPhoneOS.platform")
|| sdkroot.contains("iPhoneSimulator.platform")
|| sdkroot.contains("AppleTVOS.platform")
|| sdkroot.contains("AppleTVSimulator.platform")
Comment on lines +243 to +246
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question but now it's about "WatchOS.platform".

|| sdkroot.contains("WatchOS.platform")
|| sdkroot.contains("WatchSimulator.platform")
{
env_remove.push("SDKROOT".into())
}
Expand All @@ -249,6 +254,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
// although this is apparently ignored when using the linker at "/usr/bin/ld".
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
Comment on lines 256 to +257
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, preexisting so it doesn't have to be addressed here, but should we be doing this for "WATCHOS_DEPLOYMENT_TARGET"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll catch this after this PR merges. I think this mainly matters in cases involving build scripts that want to use SDK tools, but I could be mistaken.

env_remove.into()
} else {
// Otherwise if cross-compiling for a different OS/SDK, remove any part
Expand Down Expand Up @@ -299,6 +305,16 @@ fn tvos_lld_platform_version() -> String {
format!("{major}.{minor}")
}

pub fn tvos_llvm_target(arch: Arch) -> String {
let (major, minor) = tvos_deployment_target();
format!("{}-apple-tvos{}.{}.0", arch.target_name(), major, minor)
}

pub fn tvos_sim_llvm_target(arch: Arch) -> String {
let (major, minor) = tvos_deployment_target();
format!("{}-apple-tvos{}.{}.0-simulator", arch.target_name(), major, minor)
}

fn watchos_deployment_target() -> (u32, u32) {
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
from_set_deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_target/src/spec/x86_64_apple_tvos.rs
@@ -1,12 +1,13 @@
use super::apple_base::{opts, Arch};
use super::apple_base::{opts, tvos_sim_llvm_target, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::X86_64_sim;
Target {
llvm_target: "x86_64-apple-tvos".into(),
llvm_target: tvos_sim_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(),
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems all of our x86_64-apple-*-* have the same ABI string, should we try to be more proactive about bitrot by functionalizing or defaulting this? Or do we expect them to differ in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. In general this comes from LLVM/Clang via the magic of TableGen (I think), so I'm hesitant on trying to unify it given there's no reason for us to assume that these must be the same in the future.

I'll ask around though. I don't think we should try to unify these in this PR anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it for another PR sounds fine, I just had to ask.

arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(128),
Expand Down
23 changes: 16 additions & 7 deletions library/core/src/ffi/mod.rs
Expand Up @@ -238,7 +238,7 @@ impl fmt::Debug for c_void {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
target_family = "wasm",
target_arch = "asmjs",
target_os = "uefi",
Expand Down Expand Up @@ -267,7 +267,7 @@ pub struct VaListImpl<'f> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
target_family = "wasm",
target_arch = "asmjs",
target_os = "uefi",
Expand All @@ -292,7 +292,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
/// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
#[cfg(all(
target_arch = "aarch64",
not(any(target_os = "macos", target_os = "ios")),
not(any(target_os = "macos", target_os = "ios", target_os = "tvos")),
not(target_os = "uefi"),
not(windows),
))]
Expand Down Expand Up @@ -389,7 +389,10 @@ pub struct VaList<'a, 'f: 'a> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
all(
target_arch = "aarch64",
any(target_os = "macos", target_os = "ios", target_os = "tvos")
),
target_family = "wasm",
target_arch = "asmjs",
target_os = "uefi",
Expand All @@ -404,7 +407,10 @@ pub struct VaList<'a, 'f: 'a> {
target_arch = "s390x",
target_arch = "x86_64"
),
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
any(
not(target_arch = "aarch64"),
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
),
not(target_family = "wasm"),
not(target_arch = "asmjs"),
not(target_os = "uefi"),
Expand All @@ -422,7 +428,7 @@ pub struct VaList<'a, 'f: 'a> {
not(target_arch = "s390x"),
not(target_arch = "x86_64")
),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos")),
target_family = "wasm",
target_arch = "asmjs",
target_os = "uefi",
Expand All @@ -449,7 +455,10 @@ impl<'f> VaListImpl<'f> {
target_arch = "s390x",
target_arch = "x86_64"
),
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
any(
not(target_arch = "aarch64"),
not(any(target_os = "macos", target_os = "ios", target_os = "tvos"))
),
not(target_family = "wasm"),
not(target_arch = "asmjs"),
not(target_os = "uefi"),
Expand Down
2 changes: 1 addition & 1 deletion library/std/build.rs
Expand Up @@ -18,6 +18,7 @@ fn main() {
|| target.contains("illumos")
|| target.contains("apple-darwin")
|| target.contains("apple-ios")
|| target.contains("apple-tvos")
|| target.contains("apple-watchos")
|| target.contains("uwp")
|| target.contains("windows")
Expand Down Expand Up @@ -48,7 +49,6 @@ fn main() {
// - mipsel-sony-psp
// - nvptx64-nvidia-cuda
// - arch=avr
// - tvos (aarch64-apple-tvos, x86_64-apple-tvos)
// - uefi (x86_64-unknown-uefi, i686-unknown-uefi)
// - JSON targets
// - Any new targets that have not been explicitly added above.
Expand Down
28 changes: 25 additions & 3 deletions library/std/src/fs/tests.rs
Expand Up @@ -1640,6 +1640,10 @@ fn test_file_times() {
use crate::os::ios::fs::FileTimesExt;
#[cfg(target_os = "macos")]
use crate::os::macos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "watchos")]
use crate::os::watchos::fs::FileTimesExt;
#[cfg(windows)]
Expand All @@ -1651,9 +1655,21 @@ fn test_file_times() {
let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345);
let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321);
times = times.set_accessed(accessed).set_modified(modified);
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
))]
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
))]
{
times = times.set_created(created);
}
Expand All @@ -1678,7 +1694,13 @@ fn test_file_times() {
let metadata = file.metadata().unwrap();
assert_eq!(metadata.accessed().unwrap(), accessed);
assert_eq!(metadata.modified().unwrap(), modified);
#[cfg(any(windows, target_os = "macos", target_os = "ios", target_os = "watchos"))]
#[cfg(any(
windows,
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
))]
{
assert_eq!(metadata.created().unwrap(), created);
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/ios/fs.rs
Expand Up @@ -6,7 +6,7 @@ use crate::sys_common::{AsInner, AsInnerMut, IntoInner};
use crate::time::SystemTime;

#[allow(deprecated)]
use crate::os::ios::raw;
use super::raw;

/// OS-specific extensions to [`fs::Metadata`].
///
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/mod.rs
Expand Up @@ -137,6 +137,9 @@ pub mod redox;
pub mod solaris;
#[cfg(target_os = "solid_asp3")]
pub mod solid;
#[cfg(target_os = "tvos")]
#[path = "ios/mod.rs"]
pub(crate) mod tvos;
#[cfg(target_os = "vita")]
pub mod vita;
#[cfg(target_os = "vxworks")]
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/unix/mod.rs
Expand Up @@ -73,6 +73,8 @@ mod platform {
pub use crate::os::redox::*;
#[cfg(target_os = "solaris")]
pub use crate::os::solaris::*;
#[cfg(target_os = "tvos")]
pub use crate::os::tvos::*;
#[cfg(target_os = "vita")]
pub use crate::os::vita::*;
#[cfg(target_os = "vxworks")]
Expand All @@ -96,6 +98,7 @@ pub mod thread;
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/unix/net/stream.rs
Expand Up @@ -11,6 +11,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "netbsd",
Expand All @@ -30,6 +31,7 @@ use crate::time::Duration;
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "netbsd",
Expand Down Expand Up @@ -238,6 +240,7 @@ impl UnixStream {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "netbsd",
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/ucred.rs
Expand Up @@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
))]
pub use self::impl_bsd::peer_cred;

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

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -98,7 +98,7 @@ pub mod impl_bsd {
}
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
pub mod impl_mac {
use super::UCred;
use crate::os::unix::io::AsRawFd;
Expand Down
9 changes: 8 additions & 1 deletion library/std/src/os/unix/ucred/tests.rs
Expand Up @@ -8,6 +8,7 @@ use libc::{getegid, geteuid, getpid};
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "openbsd"
Expand All @@ -26,7 +27,13 @@ fn test_socket_pair() {
}

#[test]
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos", target_os = "watchos"))]
#[cfg(any(
target_os = "linux",
target_os = "ios",
target_os = "macos",
target_os = "watchos",
target_os = "tvos",
))]
fn test_socket_pair_pids(arg: Type) -> RetType {
// Create two connected sockets and get their peer credentials.
let (sock_a, sock_b) = UnixStream::pair().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/personality/gcc.rs
Expand Up @@ -85,7 +85,7 @@ const UNWIND_DATA_REG: (i32, i32) = (4, 5); // a0, a1
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

cfg_if::cfg_if! {
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "tvos"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
// ARM EHABI personality routine.
// https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
//
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/args.rs
Expand Up @@ -168,7 +168,7 @@ mod imp {
}
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
mod imp {
use super::Args;
use crate::ffi::CStr;
Expand Down Expand Up @@ -209,7 +209,7 @@ mod imp {
// for i in (0..[args count])
// res.push([args objectAtIndex:i])
// res
#[cfg(any(target_os = "ios", target_os = "watchos"))]
#[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos"))]
pub fn args() -> Args {
use crate::ffi::OsString;
use crate::mem;
Expand Down
11 changes: 11 additions & 0 deletions library/std/src/sys/unix/env.rs
Expand Up @@ -31,6 +31,17 @@ pub mod os {
pub const EXE_EXTENSION: &str = "";
}

#[cfg(target_os = "tvos")]
pub mod os {
pub const FAMILY: &str = "unix";
pub const OS: &str = "tvos";
pub const DLL_PREFIX: &str = "lib";
pub const DLL_SUFFIX: &str = ".dylib";
pub const DLL_EXTENSION: &str = "dylib";
pub const EXE_SUFFIX: &str = "";
pub const EXE_EXTENSION: &str = "";
}

#[cfg(target_os = "watchos")]
pub mod os {
pub const FAMILY: &str = "unix";
Expand Down