Skip to content

Commit 8296e2c

Browse files
authored
Rollup merge of rust-lang#68191 - simlay:add-tvSO-target, r=nagisa
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.
2 parents c20d7ee + 2599771 commit 8296e2c

10 files changed

+90
-21
lines changed

src/librustc_target/spec/aarch64_apple_ios.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::Arm64)?;
5+
let base = opts(Arch::Arm64, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "arm64-apple-ios".to_string(),
88
target_endian: "little".to_string(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
2+
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
3+
4+
pub fn target() -> TargetResult {
5+
let base = opts(Arch::Arm64, AppleOS::tvOS)?;
6+
Ok(Target {
7+
llvm_target: "arm64-apple-tvos".to_string(),
8+
target_endian: "little".to_string(),
9+
target_pointer_width: "64".to_string(),
10+
target_c_int_width: "32".to_string(),
11+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
12+
arch: "aarch64".to_string(),
13+
target_os: "tvos".to_string(),
14+
target_env: String::new(),
15+
target_vendor: "apple".to_string(),
16+
linker_flavor: LinkerFlavor::Gcc,
17+
options: TargetOptions {
18+
features: "+neon,+fp-armv8,+cyclone".to_string(),
19+
eliminate_frame_pointer: false,
20+
max_atomic_width: Some(128),
21+
abi_blacklist: super::arm_base::abi_blacklist(),
22+
..base
23+
},
24+
})
25+
}

src/librustc_target/spec/apple_ios_base.rs src/librustc_target/spec/apple_sdk_base.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::Path;
55
use std::process::Command;
66

77
use Arch::*;
8-
98
#[allow(non_camel_case_types)]
109
#[derive(Copy, Clone)]
1110
pub enum Arch {
@@ -17,6 +16,13 @@ pub enum Arch {
1716
X86_64_macabi,
1817
}
1918

19+
#[allow(non_camel_case_types)]
20+
#[derive(Copy, Clone)]
21+
pub enum AppleOS {
22+
tvOS,
23+
iOS,
24+
}
25+
2026
impl Arch {
2127
pub fn to_string(self) -> &'static str {
2228
match self {
@@ -41,6 +47,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
4147
let p = Path::new(&sdkroot);
4248
match sdk_name {
4349
// Ignore `SDKROOT` if it's clearly set for the wrong platform.
50+
"appletvos"
51+
if sdkroot.contains("TVSimulator.platform")
52+
|| sdkroot.contains("MacOSX.platform") =>
53+
{
54+
()
55+
}
56+
"appletvsimulator"
57+
if sdkroot.contains("TVOS.platform") || sdkroot.contains("MacOSX.platform") =>
58+
{
59+
()
60+
}
4461
"iphoneos"
4562
if sdkroot.contains("iPhoneSimulator.platform")
4663
|| sdkroot.contains("MacOSX.platform") =>
@@ -82,11 +99,17 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
8299
}
83100
}
84101

85-
fn build_pre_link_args(arch: Arch) -> Result<LinkArgs, String> {
86-
let sdk_name = match arch {
87-
Armv7 | Armv7s | Arm64 => "iphoneos",
88-
I386 | X86_64 => "iphonesimulator",
89-
X86_64_macabi => "macosx10.15",
102+
fn build_pre_link_args(arch: Arch, os: AppleOS) -> Result<LinkArgs, String> {
103+
let sdk_name = match (arch, os) {
104+
(Arm64, AppleOS::tvOS) => "appletvos",
105+
(X86_64, AppleOS::tvOS) => "appletvsimulator",
106+
(Armv7, AppleOS::iOS) => "iphoneos",
107+
(Armv7s, AppleOS::iOS) => "iphoneos",
108+
(Arm64, AppleOS::iOS) => "iphoneos",
109+
(I386, AppleOS::iOS) => "iphonesimulator",
110+
(X86_64, AppleOS::iOS) => "iphonesimulator",
111+
(X86_64_macabi, AppleOS::iOS) => "macosx10.15",
112+
_ => unreachable!(),
90113
};
91114

92115
let arch_name = arch.to_string();
@@ -128,8 +151,8 @@ fn link_env_remove(arch: Arch) -> Vec<String> {
128151
}
129152
}
130153

131-
pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
132-
let pre_link_args = build_pre_link_args(arch)?;
154+
pub fn opts(arch: Arch, os: AppleOS) -> Result<TargetOptions, String> {
155+
let pre_link_args = build_pre_link_args(arch, os)?;
133156
Ok(TargetOptions {
134157
cpu: target_cpu(arch),
135158
dynamic_linking: false,

src/librustc_target/spec/armv7_apple_ios.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::Armv7)?;
5+
let base = opts(Arch::Armv7, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "armv7-apple-ios".to_string(),
88
target_endian: "little".to_string(),

src/librustc_target/spec/armv7s_apple_ios.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::Armv7s)?;
5+
let base = opts(Arch::Armv7s, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "armv7s-apple-ios".to_string(),
88
target_endian: "little".to_string(),

src/librustc_target/spec/i386_apple_ios.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::I386)?;
5+
let base = opts(Arch::I386, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "i386-apple-ios".to_string(),
88
target_endian: "little".to_string(),

src/librustc_target/spec/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_macros::HashStable_Generic;
4747
pub mod abi;
4848
mod android_base;
4949
mod apple_base;
50-
mod apple_ios_base;
50+
mod apple_sdk_base;
5151
mod arm_base;
5252
mod cloudabi_base;
5353
mod dragonfly_base;
@@ -434,6 +434,8 @@ supported_targets! {
434434
("armv7-apple-ios", armv7_apple_ios),
435435
("armv7s-apple-ios", armv7s_apple_ios),
436436
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
437+
("aarch64-apple-tvos", aarch64_apple_tvos),
438+
("x86_64-apple-tvos", x86_64_apple_tvos),
437439

438440
("armebv7r-none-eabi", armebv7r_none_eabi),
439441
("armebv7r-none-eabihf", armebv7r_none_eabihf),

src/librustc_target/spec/x86_64_apple_ios.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::X86_64)?;
5+
let base = opts(Arch::X86_64, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "x86_64-apple-ios".to_string(),
88
target_endian: "little".to_string(),

src/librustc_target/spec/x86_64_apple_ios_macabi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::apple_ios_base::{opts, Arch};
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
22
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
33

44
pub fn target() -> TargetResult {
5-
let base = opts(Arch::X86_64_macabi)?;
5+
let base = opts(Arch::X86_64_macabi, AppleOS::iOS)?;
66
Ok(Target {
77
llvm_target: "x86_64-apple-ios13.0-macabi".to_string(),
88
target_endian: "little".to_string(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::apple_sdk_base::{opts, AppleOS, Arch};
2+
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
3+
4+
pub fn target() -> TargetResult {
5+
let base = opts(Arch::X86_64, AppleOS::iOS)?;
6+
Ok(Target {
7+
llvm_target: "x86_64-apple-tvos".to_string(),
8+
target_endian: "little".to_string(),
9+
target_pointer_width: "64".to_string(),
10+
target_c_int_width: "32".to_string(),
11+
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(),
12+
arch: "x86_64".to_string(),
13+
target_os: "tvos".to_string(),
14+
target_env: String::new(),
15+
target_vendor: "apple".to_string(),
16+
linker_flavor: LinkerFlavor::Gcc,
17+
options: TargetOptions { max_atomic_width: Some(64), stack_probes: true, ..base },
18+
})
19+
}

0 commit comments

Comments
 (0)