Skip to content

Commit

Permalink
Auto merge of rust-lang#68191 - simlay:add-tvSO-target, r=nagisa
Browse files Browse the repository at this point in the history
Added tvOS as targets

This is a first attempt of adding support tvOS as described in rust-lang#48862. It's got a lot of overlap with [src/librustc_target/spec/apple_ios_base.rs](https://github.com/rust-lang/rust/blob/31dd4f4acbcbdb02b0745d2136399ed664a28050/src/librustc_target/spec/apple_ios_base.rs).

I thought about refactoring `apple_ios_base.rs` to include this as well but that would require each of the ios and tvos targets to be of the something like the form `let base = opts(AppleOS::TV, Arch::Arm64)?;` I also did the same thing for watchOS because from what I can tell, all three targets (iOS, tvOS, and watchOS) have the same logic but have different parameters being sent to `xcrun`. Thoughts?

As far as the `data_layout` and other parameters to `Target`, I did as much research as I could but it really seems that processor in the [iPhone 11 is the same as the apple TV](https://en.wikipedia.org/wiki/Apple-designed_processors) so I didn't change any of those parameters.

I did get this to build and tested that it's actually running the the below logic (because the parameter to `xcrun` is `appletvos` not `tvos`).

I didn't manage to get it to actually compile a file with `fn main(){}` because I don't have the stdlib for `aarch64-apple-tvos` compiled it seems. Is there documentation for this?

Similar to the ending of rust-lang#63467, I'm not sure what to do next.
  • Loading branch information
bors committed Mar 12, 2020
2 parents c20d7ee + 2599771 commit e5e8ba4
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/librustc_target/spec/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
25 changes: 25 additions & 0 deletions src/librustc_target/spec/aarch64_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -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
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -41,6 +47,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
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") =>
Expand Down Expand Up @@ -82,11 +99,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
}
}

fn build_pre_link_args(arch: Arch) -> Result<LinkArgs, String> {
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<LinkArgs, String> {
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();
Expand Down Expand Up @@ -128,8 +151,8 @@ fn link_env_remove(arch: Arch) -> Vec<String> {
}
}

pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
let pre_link_args = build_pre_link_args(arch)?;
pub fn opts(arch: Arch, os: AppleOS) -> Result<TargetOptions, String> {
let pre_link_args = build_pre_link_args(arch, os)?;
Ok(TargetOptions {
cpu: target_cpu(arch),
dynamic_linking: false,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/armv7_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/armv7s_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/i386_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/x86_64_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/x86_64_apple_ios_macabi.rs
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_target/spec/x86_64_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -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 },
})
}

0 comments on commit e5e8ba4

Please sign in to comment.