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

Added tvOS as targets #68191

Merged
merged 4 commits into from
Mar 12, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
})
}