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

Add AppleTVOS support #704

Merged
merged 1 commit into from
Sep 23, 2023
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
34 changes: 30 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,10 @@ impl Build {
cmd.push_opt_unless_duplicate("-DANDROID".into());
}

if !target.contains("apple-ios") && !target.contains("apple-watchos") {
if !target.contains("apple-ios")
&& !target.contains("apple-watchos")
&& !target.contains("apple-tvos")
{
cmd.push_cc_arg("-ffunction-sections".into());
cmd.push_cc_arg("-fdata-sections".into());
}
Expand Down Expand Up @@ -1856,6 +1859,20 @@ impl Build {
.into(),
);
}
} else if target.contains("x86_64-apple-tvos") {
if let Some(arch) =
map_darwin_target_from_rust_to_compiler_architecture(target)
{
let deployment_target =
self.apple_deployment_version(AppleOs::TvOs, target, None);
cmd.args.push(
format!(
"--target={}-apple-tvos{}-simulator",
arch, deployment_target
)
.into(),
);
}
} else if target.starts_with("riscv64gc-") {
cmd.args.push(
format!("--target={}", target.replace("riscv64gc", "riscv64")).into(),
Expand Down Expand Up @@ -2382,6 +2399,8 @@ impl Build {
AppleOs::MacOs
} else if target.contains("-watchos") {
AppleOs::WatchOs
} else if target.contains("-tvos") {
AppleOs::TvOs
} else {
AppleOs::Ios
};
Expand All @@ -2402,7 +2421,7 @@ impl Build {
None => false,
};

let is_sim = match target.split('-').nth(3) {
let is_arm_sim = match target.split('-').nth(3) {
Some(v) => v == "sim",
None => false,
};
Expand Down Expand Up @@ -2430,14 +2449,14 @@ impl Build {
));
}
}
} else if is_sim {
} else if is_arm_sim {
match arch_str {
"arm64" | "aarch64" => ArchSpec::Simulator("arm64"),
"x86_64" | "x86_64h" => ArchSpec::Simulator("-m64"),
_ => {
return Err(Error::new(
ErrorKind::ArchitectureInvalid,
"Unknown architecture for iOS simulator target.",
"Unknown architecture for simulator target.",
));
}
}
Expand Down Expand Up @@ -2465,6 +2484,7 @@ impl Build {
AppleOs::MacOs => ("macosx", ""),
AppleOs::Ios => ("iphone", "ios-"),
AppleOs::WatchOs => ("watch", "watch"),
AppleOs::TvOs => ("appletv", "appletv"),
};

let sdk = match arch {
Expand Down Expand Up @@ -3468,6 +3488,10 @@ impl Build {
.ok()
.or_else(|| rustc_provided_target(rustc, target))
.unwrap_or_else(|| "5.0".into()),
AppleOs::TvOs => env::var("TVOS_DEPLOYMENT_TARGET")
.ok()
.or_else(|| rustc_provided_target(rustc, target))
.unwrap_or_else(|| "9.0".into()),
}
}

Expand Down Expand Up @@ -3863,13 +3887,15 @@ enum AppleOs {
MacOs,
Ios,
WatchOs,
TvOs,
}
impl std::fmt::Debug for AppleOs {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
AppleOs::MacOs => f.write_str("macOS"),
AppleOs::Ios => f.write_str("iOS"),
AppleOs::WatchOs => f.write_str("WatchOS"),
AppleOs::TvOs => f.write_str("AppleTVOS"),
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,33 @@ fn gnu_apple_darwin() {
.must_have(format!("-mmacosx-version-min={}", version));
}
}

#[cfg(target_os = "macos")]
#[test]
fn apple_tvos() {
for target in &["aarch64-apple-tvos"] {
let test = Test::gnu();
test.gcc()
.target(&target)
.host(&target)
.file("foo.c")
.compile("foo");

test.cmd(0).must_have("-mappletvos-version-min=9.0");
}
}

#[cfg(target_os = "macos")]
#[test]
fn apple_tvsimulator() {
for target in &["x86_64-apple-tvos"] {
let test = Test::gnu();
test.gcc()
.target(&target)
.host(&target)
.file("foo.c")
.compile("foo");

test.cmd(0).must_have("-mappletvsimulator-version-min=9.0");
}
}