Skip to content

Commit b5bd6a9

Browse files
committed
Add AppleTVOS support
1 parent 53fb72c commit b5bd6a9

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

src/lib.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,10 @@ impl Build {
15291529
cmd.push_opt_unless_duplicate("-DANDROID".into());
15301530
}
15311531

1532-
if !target.contains("apple-ios") && !target.contains("apple-watchos") {
1532+
if !target.contains("apple-ios")
1533+
&& !target.contains("apple-watchos")
1534+
&& !target.contains("apple-tvos")
1535+
{
15331536
cmd.push_cc_arg("-ffunction-sections".into());
15341537
cmd.push_cc_arg("-fdata-sections".into());
15351538
}
@@ -1611,6 +1614,20 @@ impl Build {
16111614
.into(),
16121615
);
16131616
}
1617+
} else if target.contains("x86_64-apple-tvos") {
1618+
if let Some(arch) =
1619+
map_darwin_target_from_rust_to_compiler_architecture(target)
1620+
{
1621+
let deployment_target =
1622+
env::var("TVOS_DEPLOYMENT_TARGET").unwrap_or_else(|_| "9.0".into());
1623+
cmd.args.push(
1624+
format!(
1625+
"--target={}-apple-tvos{}-simulator",
1626+
arch, deployment_target
1627+
)
1628+
.into(),
1629+
);
1630+
}
16141631
} else if target.starts_with("riscv64gc-") {
16151632
cmd.args.push(
16161633
format!("--target={}", target.replace("riscv64gc", "riscv64")).into(),
@@ -1870,8 +1887,11 @@ impl Build {
18701887
}
18711888
}
18721889

1873-
if target.contains("apple-ios") || target.contains("apple-watchos") {
1874-
self.ios_watchos_flags(cmd)?;
1890+
if target.contains("apple-ios")
1891+
|| target.contains("apple-watchos")
1892+
|| target.contains("apple-tvos")
1893+
{
1894+
self.apple_flags(cmd)?;
18751895
}
18761896

18771897
if self.static_flag.unwrap_or(false) {
@@ -2064,7 +2084,7 @@ impl Build {
20642084
Ok(())
20652085
}
20662086

2067-
fn ios_watchos_flags(&self, cmd: &mut Tool) -> Result<(), Error> {
2087+
fn apple_flags(&self, cmd: &mut Tool) -> Result<(), Error> {
20682088
enum ArchSpec {
20692089
Device(&'static str),
20702090
Simulator(&'static str),
@@ -2074,19 +2094,23 @@ impl Build {
20742094
enum Os {
20752095
Ios,
20762096
WatchOs,
2097+
TvOs,
20772098
}
20782099
impl Display for Os {
20792100
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
20802101
match self {
20812102
Os::Ios => f.write_str("iOS"),
20822103
Os::WatchOs => f.write_str("WatchOS"),
2104+
Os::TvOs => f.write_str("tvOS"),
20832105
}
20842106
}
20852107
}
20862108

20872109
let target = self.get_target()?;
20882110
let os = if target.contains("-watchos") {
20892111
Os::WatchOs
2112+
} else if target.contains("-tvos") {
2113+
Os::TvOs
20902114
} else {
20912115
Os::Ios
20922116
};
@@ -2103,7 +2127,7 @@ impl Build {
21032127
None => false,
21042128
};
21052129

2106-
let is_sim = match target.split('-').nth(3) {
2130+
let is_arm_sim = match target.split('-').nth(3) {
21072131
Some(v) => v == "sim",
21082132
None => false,
21092133
};
@@ -2120,14 +2144,14 @@ impl Build {
21202144
));
21212145
}
21222146
}
2123-
} else if is_sim {
2147+
} else if is_arm_sim {
21242148
match arch {
21252149
"arm64" | "aarch64" => ArchSpec::Simulator("-arch arm64"),
21262150
"x86_64" => ArchSpec::Simulator("-m64"),
21272151
_ => {
21282152
return Err(Error::new(
21292153
ErrorKind::ArchitectureInvalid,
2130-
"Unknown architecture for iOS simulator target.",
2154+
"Unknown architecture for simulator target.",
21312155
));
21322156
}
21332157
}
@@ -2161,6 +2185,11 @@ impl Build {
21612185
"watch",
21622186
std::env::var("WATCHOS_DEPLOYMENT_TARGET").unwrap_or_else(|_| "2.0".into()),
21632187
),
2188+
Os::TvOs => (
2189+
"appletv",
2190+
"appletv",
2191+
std::env::var("TVOS_DEPLOYMENT_TARGET").unwrap_or_else(|_| "9.0".into()),
2192+
),
21642193
};
21652194

21662195
let sdk = match arch {

tests/test.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,33 @@ fn msvc_no_dash_dash() {
427427

428428
test.cmd(0).must_not_have("--");
429429
}
430+
431+
#[cfg(target_os = "macos")]
432+
#[test]
433+
fn apple_tvos() {
434+
for target in &["aarch64-apple-tvos"] {
435+
let test = Test::gnu();
436+
test.gcc()
437+
.target(&target)
438+
.host(&target)
439+
.file("foo.c")
440+
.compile("foo");
441+
442+
test.cmd(0).must_have("-mappletvos-version-min=9.0");
443+
}
444+
}
445+
446+
#[cfg(target_os = "macos")]
447+
#[test]
448+
fn apple_tvsimulator() {
449+
for target in &["x86_64-apple-tvos"] {
450+
let test = Test::gnu();
451+
test.gcc()
452+
.target(&target)
453+
.host(&target)
454+
.file("foo.c")
455+
.compile("foo");
456+
457+
test.cmd(0).must_have("-mappletvsimulator-version-min=9.0");
458+
}
459+
}

0 commit comments

Comments
 (0)