Skip to content

Commit ae53a9e

Browse files
authored
Rollup merge of rust-lang#63467 - terhechte:support-ios-catalyst-macabi-target-triple, r=estebank
Add Catalyst (iOS apps running on macOS) target This is a first attempt of adding support for the new [Apple Catalyst](https://developer.apple.com/ipad-apps-for-mac/) target (i.e. running iOS apps on macOS). Currently, `rustc` supports the iOS and iOS simulator targets for iOS: - iOS: ARM cpu, iOS SDK, linked agains the iOS ABI - Simulator: X86_64 cpu, iOS SDK, linked against the iOS ABI Apple Catalyst will add an additional target: - Macabi: X86_64 CPU, iOS SDK, linked again the macOS ABI. Note, it the actual SDK is the also the macOS 10.15 SDK, but the symbols are the iOS SDK symbols as they were added to macOS with 10.15. I've collected additional information via links in the open question sections below. This is way out of my comfort zone so please excuse whatever errors I may have made. # Open Questions: ## Clang Version It seems to me that `macabi` has not been merged into `clang` yet, I don't know whether that is a requirement rustc to compile, or if it is sufficient if the Clang that is used on a developers system is the correct one supporting macabi (that comes with current Xcode) ## Hardcoded iOS version `swift-llvm` actually used [x86_64-apple-ios13.0-macabi](apple/swift-llvm@3f1fd4f) as the target triple which hard-codes the current iOS version. A post on stackoverflow [points out that `MIN_IOS_VERSION` and `MIN_OSX_VERSION` should be used when compiling C code for clang (`-target x86_64-apple-ios${MIN_IOS_VERSION}-macabi`)](https://stackoverflow.com/questions/56487645/how-to-compile-a-3rd-party-library-to-be-used-with-uikit-for-mac-catalyst). However, I wasn't entirely sure how to do that in this PR. Pointers welcome. ## Data Layout I'm probably using the wrong data-layout. I don't know whether it should be the macOS version or the iOS version. This is probably easier to answer for somebody who understands these things much better than me. I just copied the iOS Simulator X86_64 version as it seems to be (based on what I understand) that Catalyst is just the simulator target build against a different SDK. # Current State 1. I got it to compile 2. I could successfully compile a `macabi` `libcore` via `cargo build --target x86_64-apple-ios-macabi` I'm not sure what needs to be done next. Supposedly I need to compile everything into a toolchain somehow that I can then test via `rustup` to make sure that a binary compiled against the toolchain also works with Catalyst. [I read this article, but I'm still lost](https://www.reddit.com/r/rust/comments/5ag60z/how_do_i_bootstrap_rust_to_crosscompile_for_a_new/d9gicr2/) and would love pointers what to do next here. # Additional Information - [Commit adding Catalyst support to the Swift Clang Fork](CocoaPods/CocoaPods#8877) - [Compiling C to Catalyst Discussion](CocoaPods/CocoaPods#8877) - [CocoaPods Discussion on Adding Catalyst support](CocoaPods/CocoaPods#8877)
2 parents 988cd5d + af1e668 commit ae53a9e

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/librustc_target/spec/apple_ios_base.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub enum Arch {
1313
Armv7s,
1414
Arm64,
1515
I386,
16-
X86_64
16+
X86_64,
17+
X86_64_macabi,
1718
}
1819

1920
impl Arch {
@@ -23,7 +24,8 @@ impl Arch {
2324
Armv7s => "armv7s",
2425
Arm64 => "arm64",
2526
I386 => "i386",
26-
X86_64 => "x86_64"
27+
X86_64 => "x86_64",
28+
X86_64_macabi => "x86_64"
2729
}
2830
}
2931
}
@@ -67,7 +69,8 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
6769
fn build_pre_link_args(arch: Arch) -> Result<LinkArgs, String> {
6870
let sdk_name = match arch {
6971
Armv7 | Armv7s | Arm64 => "iphoneos",
70-
I386 | X86_64 => "iphonesimulator"
72+
I386 | X86_64 => "iphonesimulator",
73+
X86_64_macabi => "macosx10.15",
7174
};
7275

7376
let arch_name = arch.to_string();
@@ -93,6 +96,7 @@ fn target_cpu(arch: Arch) -> String {
9396
Arm64 => "cyclone",
9497
I386 => "yonah",
9598
X86_64 => "core2",
99+
X86_64_macabi => "core2",
96100
}.to_string()
97101
}
98102

src/librustc_target/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ supported_targets! {
428428
("aarch64-apple-ios", aarch64_apple_ios),
429429
("armv7-apple-ios", armv7_apple_ios),
430430
("armv7s-apple-ios", armv7s_apple_ios),
431+
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
431432

432433
("armebv7r-none-eabi", armebv7r_none_eabi),
433434
("armebv7r-none-eabihf", armebv7r_none_eabihf),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
2+
use super::apple_ios_base::{opts, Arch};
3+
4+
pub fn target() -> TargetResult {
5+
let base = opts(Arch::X86_64_macabi)?;
6+
Ok(Target {
7+
llvm_target: "x86_64-apple-ios13.0-macabi".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: "ios".to_string(),
14+
target_env: String::new(),
15+
target_vendor: "apple".to_string(),
16+
linker_flavor: LinkerFlavor::Gcc,
17+
options: TargetOptions {
18+
max_atomic_width: Some(64),
19+
stack_probes: true,
20+
.. base
21+
}
22+
})
23+
}

0 commit comments

Comments
 (0)