-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Support Apple tvOS in libstd #103503
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
Support Apple tvOS in libstd #103503
Changes from all commits
bdc3db9
f978d7e
3785a17
abb1911
df96402
b18ff59
6e62961
a3f5566
b80e0b7
49da0ac
37854aa
a7ecc71
5ef4d1f
af0662f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,7 +240,12 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]> | |
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which | ||
// may occur when we're linking a custom build script while targeting iOS for example. | ||
if let Ok(sdkroot) = env::var("SDKROOT") { | ||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") | ||
if sdkroot.contains("iPhoneOS.platform") | ||
|| sdkroot.contains("iPhoneSimulator.platform") | ||
|| sdkroot.contains("AppleTVOS.platform") | ||
|| sdkroot.contains("AppleTVSimulator.platform") | ||
|| sdkroot.contains("WatchOS.platform") | ||
|| sdkroot.contains("WatchSimulator.platform") | ||
{ | ||
env_remove.push("SDKROOT".into()) | ||
} | ||
|
@@ -249,6 +254,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]> | |
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", | ||
// although this is apparently ignored when using the linker at "/usr/bin/ld". | ||
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into()); | ||
env_remove.push("TVOS_DEPLOYMENT_TARGET".into()); | ||
Comment on lines
256
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, preexisting so it doesn't have to be addressed here, but should we be doing this for "WATCHOS_DEPLOYMENT_TARGET"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll catch this after this PR merges. I think this mainly matters in cases involving build scripts that want to use SDK tools, but I could be mistaken. |
||
env_remove.into() | ||
} else { | ||
// Otherwise if cross-compiling for a different OS/SDK, remove any part | ||
|
@@ -299,6 +305,16 @@ fn tvos_lld_platform_version() -> String { | |
format!("{major}.{minor}") | ||
} | ||
|
||
pub fn tvos_llvm_target(arch: Arch) -> String { | ||
let (major, minor) = tvos_deployment_target(); | ||
format!("{}-apple-tvos{}.{}.0", arch.target_name(), major, minor) | ||
} | ||
|
||
pub fn tvos_sim_llvm_target(arch: Arch) -> String { | ||
let (major, minor) = tvos_deployment_target(); | ||
format!("{}-apple-tvos{}.{}.0-simulator", arch.target_name(), major, minor) | ||
} | ||
|
||
fn watchos_deployment_target() -> (u32, u32) { | ||
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`. | ||
from_set_deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
use super::apple_base::{opts, Arch}; | ||
use super::apple_base::{opts, tvos_sim_llvm_target, Arch}; | ||
use crate::spec::{StackProbeType, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
let arch = Arch::X86_64_sim; | ||
Target { | ||
llvm_target: "x86_64-apple-tvos".into(), | ||
llvm_target: tvos_sim_llvm_target(arch).into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(), | ||
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems all of our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure. In general this comes from LLVM/Clang via the magic of TableGen (I think), so I'm hesitant on trying to unify it given there's no reason for us to assume that these must be the same in the future. I'll ask around though. I don't think we should try to unify these in this PR anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving it for another PR sounds fine, I just had to ask. |
||
.into(), | ||
arch: arch.target_arch(), | ||
options: TargetOptions { | ||
max_atomic_width: Some(128), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# `*-apple-tvos` | ||
- aarch64-apple-tvos | ||
- x86_64-apple-tvos | ||
|
||
**Tier: 3** | ||
|
||
Apple tvOS targets: | ||
- Apple tvOS on aarch64 | ||
- Apple tvOS Simulator on x86_64 | ||
|
||
## Target maintainers | ||
|
||
* [@thomcc](https://github.com/thomcc) | ||
|
||
## Requirements | ||
|
||
These targets are cross-compiled. You will need appropriate versions of Xcode | ||
and the SDKs for tvOS (`AppleTVOS.sdk`) and/or the tvOS Simulator | ||
(`AppleTVSimulator.sdk`) to build a toolchain and target these platforms. | ||
|
||
The targets support most (see below) of the standard library including the | ||
allocator to the best of my knowledge, however they are very new, not yet | ||
well-tested, and it is possible that there are various bugs. | ||
|
||
In theory we support back to tvOS version 7.0, although the actual minimum | ||
version you can target may be newer than this, for example due to the versions | ||
of Xcode and your SDKs. | ||
|
||
As with the other Apple targets, `rustc` respects the common environment | ||
variables used by Xcode to configure this, in this case | ||
`TVOS_DEPLOYMENT_TARGET`. | ||
|
||
#### Incompletely supported library functionality | ||
|
||
As mentioned, "most" of the standard library is supported, which means that some portions | ||
are known to be unsupported. The following APIs are currently known to have | ||
missing or incomplete support: | ||
|
||
- `std::process::Command`'s API will return an error if it is configured in a | ||
manner which cannot be performed using `posix_spawn` -- this is because the | ||
more flexible `fork`/`exec`-based approach is prohibited on these platforms in | ||
favor of `posix_spawn{,p}` (which still probably will get you rejected from | ||
app stores, so is likely sideloading-only). A concrete set of cases where this | ||
will occur is difficult to enumerate (and would quickly become stale), but in | ||
some cases it may be worked around by tweaking the manner in which `Command` | ||
is invoked. | ||
|
||
## Building the target | ||
|
||
The targets can be built by enabling them for a `rustc` build in `config.toml`, by adding, for example: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
target = ["aarch64-apple-tvos", "x86_64-apple-tvos"] | ||
``` | ||
|
||
It's possible that cargo under `-Zbuild-std` may also be used to target them. | ||
|
||
## Building Rust programs | ||
|
||
*Note: Building for this target requires the corresponding TVOS SDK, as provided by Xcode.* | ||
thomcc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Rust programs can be built for these targets | ||
|
||
```text | ||
$ rustc --target aarch64-apple-tvos your-code.rs | ||
... | ||
$ rustc --target x86_64-apple-tvos your-code.rs | ||
``` | ||
|
||
## Testing | ||
|
||
There is no support for running the Rust or standard library testsuite on tvOS | ||
or the simulators at the moment. Testing has mostly been done manually with | ||
builds of static libraries called from Xcode or a simulator. | ||
|
||
It hopefully will be possible to improve this in the future. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
This target can be cross-compiled from x86_64 or aarch64 macOS hosts. | ||
|
||
Other hosts are not supported for cross-compilation, but might work when also | ||
providing the required Xcode SDK. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tvOS (simulator) SDK, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When cross-compiling you are plausibly providing some sort of franken-SDK built from a hybrid of (usually patched versions of) tools from https://github.com/apple-oss-distributions, often-manually-tweaked tbd files, and so on. The details are complex and not worth getting into here, but yeah basically if you're cross-compiling from some non-macOS host, you probably need something other than just the stock SDKs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question but now it's about "WatchOS.platform".