diff --git a/src/librustc_target/spec/aarch64_apple_ios.rs b/src/librustc_target/spec/aarch64_apple_ios.rs index 6549be41ea944..e896b46da9a62 100644 --- a/src/librustc_target/spec/aarch64_apple_ios.rs +++ b/src/librustc_target/spec/aarch64_apple_ios.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::Arm64)?; + let base = opts(Arch::Arm64, AppleOS::iOS)?; Ok(Target { llvm_target: "arm64-apple-ios".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/aarch64_apple_tvos.rs b/src/librustc_target/spec/aarch64_apple_tvos.rs new file mode 100644 index 0000000000000..794bc7900e747 --- /dev/null +++ b/src/librustc_target/spec/aarch64_apple_tvos.rs @@ -0,0 +1,25 @@ +use super::apple_sdk_base::{opts, AppleOS, Arch}; +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; + +pub fn target() -> TargetResult { + let base = opts(Arch::Arm64, AppleOS::tvOS)?; + Ok(Target { + llvm_target: "arm64-apple-tvos".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + target_os: "tvos".to_string(), + target_env: String::new(), + target_vendor: "apple".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: TargetOptions { + features: "+neon,+fp-armv8,+cyclone".to_string(), + eliminate_frame_pointer: false, + max_atomic_width: Some(128), + abi_blacklist: super::arm_base::abi_blacklist(), + ..base + }, + }) +} diff --git a/src/librustc_target/spec/apple_ios_base.rs b/src/librustc_target/spec/apple_sdk_base.rs similarity index 77% rename from src/librustc_target/spec/apple_ios_base.rs rename to src/librustc_target/spec/apple_sdk_base.rs index 2673748321d79..513754352fbfb 100644 --- a/src/librustc_target/spec/apple_ios_base.rs +++ b/src/librustc_target/spec/apple_sdk_base.rs @@ -5,7 +5,6 @@ use std::path::Path; use std::process::Command; use Arch::*; - #[allow(non_camel_case_types)] #[derive(Copy, Clone)] pub enum Arch { @@ -17,6 +16,13 @@ pub enum Arch { X86_64_macabi, } +#[allow(non_camel_case_types)] +#[derive(Copy, Clone)] +pub enum AppleOS { + tvOS, + iOS, +} + impl Arch { pub fn to_string(self) -> &'static str { match self { @@ -41,6 +47,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result { let p = Path::new(&sdkroot); match sdk_name { // Ignore `SDKROOT` if it's clearly set for the wrong platform. + "appletvos" + if sdkroot.contains("TVSimulator.platform") + || sdkroot.contains("MacOSX.platform") => + { + () + } + "appletvsimulator" + if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") => + { + () + } "iphoneos" if sdkroot.contains("iPhoneSimulator.platform") || sdkroot.contains("MacOSX.platform") => @@ -82,11 +99,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result { } } -fn build_pre_link_args(arch: Arch) -> Result { - let sdk_name = match arch { - Armv7 | Armv7s | Arm64 => "iphoneos", - I386 | X86_64 => "iphonesimulator", - X86_64_macabi => "macosx10.15", +fn build_pre_link_args(arch: Arch, os: AppleOS) -> Result { + let sdk_name = match (arch, os) { + (Arm64, AppleOS::tvOS) => "appletvos", + (X86_64, AppleOS::tvOS) => "appletvsimulator", + (Armv7, AppleOS::iOS) => "iphoneos", + (Armv7s, AppleOS::iOS) => "iphoneos", + (Arm64, AppleOS::iOS) => "iphoneos", + (I386, AppleOS::iOS) => "iphonesimulator", + (X86_64, AppleOS::iOS) => "iphonesimulator", + (X86_64_macabi, AppleOS::iOS) => "macosx10.15", + _ => unreachable!(), }; let arch_name = arch.to_string(); @@ -128,8 +151,8 @@ fn link_env_remove(arch: Arch) -> Vec { } } -pub fn opts(arch: Arch) -> Result { - let pre_link_args = build_pre_link_args(arch)?; +pub fn opts(arch: Arch, os: AppleOS) -> Result { + let pre_link_args = build_pre_link_args(arch, os)?; Ok(TargetOptions { cpu: target_cpu(arch), dynamic_linking: false, diff --git a/src/librustc_target/spec/armv7_apple_ios.rs b/src/librustc_target/spec/armv7_apple_ios.rs index aa2d32e2d7935..c0c2ae909f8f0 100644 --- a/src/librustc_target/spec/armv7_apple_ios.rs +++ b/src/librustc_target/spec/armv7_apple_ios.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::Armv7)?; + let base = opts(Arch::Armv7, AppleOS::iOS)?; Ok(Target { llvm_target: "armv7-apple-ios".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/armv7s_apple_ios.rs b/src/librustc_target/spec/armv7s_apple_ios.rs index 6514643a64dae..6a5654f10d416 100644 --- a/src/librustc_target/spec/armv7s_apple_ios.rs +++ b/src/librustc_target/spec/armv7s_apple_ios.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::Armv7s)?; + let base = opts(Arch::Armv7s, AppleOS::iOS)?; Ok(Target { llvm_target: "armv7s-apple-ios".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/i386_apple_ios.rs b/src/librustc_target/spec/i386_apple_ios.rs index a6c1d24fa62a1..a121d49769d61 100644 --- a/src/librustc_target/spec/i386_apple_ios.rs +++ b/src/librustc_target/spec/i386_apple_ios.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::I386)?; + let base = opts(Arch::I386, AppleOS::iOS)?; Ok(Target { llvm_target: "i386-apple-ios".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 67f45d3d230ef..37eabb4f26d4b 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -47,7 +47,7 @@ use rustc_macros::HashStable_Generic; pub mod abi; mod android_base; mod apple_base; -mod apple_ios_base; +mod apple_sdk_base; mod arm_base; mod cloudabi_base; mod dragonfly_base; @@ -434,6 +434,8 @@ supported_targets! { ("armv7-apple-ios", armv7_apple_ios), ("armv7s-apple-ios", armv7s_apple_ios), ("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi), + ("aarch64-apple-tvos", aarch64_apple_tvos), + ("x86_64-apple-tvos", x86_64_apple_tvos), ("armebv7r-none-eabi", armebv7r_none_eabi), ("armebv7r-none-eabihf", armebv7r_none_eabihf), diff --git a/src/librustc_target/spec/x86_64_apple_ios.rs b/src/librustc_target/spec/x86_64_apple_ios.rs index ca02e2deabcf2..cfcf856836b14 100644 --- a/src/librustc_target/spec/x86_64_apple_ios.rs +++ b/src/librustc_target/spec/x86_64_apple_ios.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::X86_64)?; + let base = opts(Arch::X86_64, AppleOS::iOS)?; Ok(Target { llvm_target: "x86_64-apple-ios".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/x86_64_apple_ios_macabi.rs b/src/librustc_target/spec/x86_64_apple_ios_macabi.rs index 5f4f6ade682d8..c42d09117259d 100644 --- a/src/librustc_target/spec/x86_64_apple_ios_macabi.rs +++ b/src/librustc_target/spec/x86_64_apple_ios_macabi.rs @@ -1,8 +1,8 @@ -use super::apple_ios_base::{opts, Arch}; +use super::apple_sdk_base::{opts, AppleOS, Arch}; use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { - let base = opts(Arch::X86_64_macabi)?; + let base = opts(Arch::X86_64_macabi, AppleOS::iOS)?; Ok(Target { llvm_target: "x86_64-apple-ios13.0-macabi".to_string(), target_endian: "little".to_string(), diff --git a/src/librustc_target/spec/x86_64_apple_tvos.rs b/src/librustc_target/spec/x86_64_apple_tvos.rs new file mode 100644 index 0000000000000..a56062c0b2b5d --- /dev/null +++ b/src/librustc_target/spec/x86_64_apple_tvos.rs @@ -0,0 +1,19 @@ +use super::apple_sdk_base::{opts, AppleOS, Arch}; +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; + +pub fn target() -> TargetResult { + let base = opts(Arch::X86_64, AppleOS::iOS)?; + Ok(Target { + llvm_target: "x86_64-apple-tvos".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), + arch: "x86_64".to_string(), + target_os: "tvos".to_string(), + target_env: String::new(), + target_vendor: "apple".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: TargetOptions { max_atomic_width: Some(64), stack_probes: true, ..base }, + }) +}