Skip to content

Commit f5e3492

Browse files
committed
Add arm64e-apple-ios target
1 parent 698fcc8 commit f5e3492

File tree

10 files changed

+112
-18
lines changed

10 files changed

+112
-18
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2659,9 +2659,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
26592659

26602660
[[package]]
26612661
name = "object"
2662-
version = "0.32.0"
2662+
version = "0.32.1"
26632663
source = "registry+https://github.com/rust-lang/crates.io-index"
2664-
checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe"
2664+
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
26652665
dependencies = [
26662666
"compiler_builtins",
26672667
"crc32fast",

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ libc = "0.2.50"
4646
# tidy-alphabetical-end
4747

4848
[dependencies.object]
49-
version = "0.32.0"
49+
version = "0.32.1"
5050
default-features = false
5151
features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write"]
5252

compiler/rustc_codegen_ssa/src/back/metadata.rs

+9
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
226226

227227
let mut file = write::Object::new(binary_format, architecture, endianness);
228228
if sess.target.is_like_osx {
229+
if macho_is_arm64e(&sess.target) {
230+
file.set_macho_cpu_subtype(object::macho::CPU_SUBTYPE_ARM64E);
231+
}
232+
229233
file.set_macho_build_version(macho_object_build_version_for_target(&sess.target))
230234
}
231235
if binary_format == BinaryFormat::Coff {
@@ -385,6 +389,11 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
385389
build_version
386390
}
387391

392+
/// Is Apple's CPU subtype `arm64e`s
393+
fn macho_is_arm64e(target: &Target) -> bool {
394+
return target.llvm_target.starts_with("arm64e");
395+
}
396+
388397
pub enum MetadataPosition {
389398
First,
390399
Last,

compiler/rustc_target/src/spec/base/apple/mod.rs

+29-15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ mod tests;
99

1010
use Arch::*;
1111
#[allow(non_camel_case_types)]
12-
#[derive(Copy, Clone)]
12+
#[derive(Copy, Clone, PartialEq)]
1313
pub enum Arch {
1414
Armv7k,
1515
Armv7s,
1616
Arm64,
17+
Arm64e,
1718
Arm64_32,
1819
I386,
1920
I686,
@@ -31,6 +32,7 @@ impl Arch {
3132
Armv7k => "armv7k",
3233
Armv7s => "armv7s",
3334
Arm64 | Arm64_macabi | Arm64_sim => "arm64",
35+
Arm64e => "arm64e",
3436
Arm64_32 => "arm64_32",
3537
I386 => "i386",
3638
I686 => "i686",
@@ -42,15 +44,15 @@ impl Arch {
4244
pub fn target_arch(self) -> Cow<'static, str> {
4345
Cow::Borrowed(match self {
4446
Armv7k | Armv7s => "arm",
45-
Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
47+
Arm64 | Arm64e | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
4648
I386 | I686 => "x86",
4749
X86_64 | X86_64_sim | X86_64_macabi | X86_64h => "x86_64",
4850
})
4951
}
5052

5153
fn target_abi(self) -> &'static str {
5254
match self {
53-
Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64h => "",
55+
Armv7k | Armv7s | Arm64 | Arm64e | Arm64_32 | I386 | I686 | X86_64 | X86_64h => "",
5456
X86_64_macabi | Arm64_macabi => "macabi",
5557
// x86_64-apple-ios is a simulator target, even though it isn't
5658
// declared that way in the target like the other ones...
@@ -63,6 +65,7 @@ impl Arch {
6365
Armv7k => "cortex-a8",
6466
Armv7s => "swift", // iOS 10 is only supported on iPhone 5 or higher.
6567
Arm64 => "apple-a7",
68+
Arm64e => "apple-a12",
6669
Arm64_32 => "apple-s4",
6770
// Only macOS 10.12+ is supported, which means
6871
// all x86_64/x86 CPUs must be running at least penryn
@@ -88,7 +91,7 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
8891
};
8992

9093
let platform_version: StaticCow<str> = match os {
91-
"ios" => ios_lld_platform_version(),
94+
"ios" => ios_lld_platform_version(arch),
9295
"tvos" => tvos_lld_platform_version(),
9396
"watchos" => watchos_lld_platform_version(),
9497
"macos" => macos_lld_platform_version(arch),
@@ -202,12 +205,22 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
202205
let (major, minor) = match &*target.os {
203206
"macos" => {
204207
// This does not need to be specific. It just needs to handle x86 vs M1.
205-
let arch = if target.arch == "x86" || target.arch == "x86_64" { X86_64 } else { Arm64 };
208+
let arch = match target.arch.as_ref() {
209+
"x86" | "x86_64" => X86_64,
210+
"arm64e" => Arm64e,
211+
_ => Arm64,
212+
};
206213
macos_deployment_target(arch)
207214
}
208215
"ios" => match &*target.abi {
209216
"macabi" => mac_catalyst_deployment_target(),
210-
_ => ios_deployment_target(),
217+
_ => {
218+
let arch = match target.arch.as_ref() {
219+
"arm64e" => Arm64e,
220+
_ => Arm64,
221+
};
222+
ios_deployment_target(arch)
223+
}
211224
},
212225
"watchos" => watchos_deployment_target(),
213226
"tvos" => tvos_deployment_target(),
@@ -228,7 +241,7 @@ fn from_set_deployment_target(var_name: &str) -> Option<(u32, u32)> {
228241
fn macos_default_deployment_target(arch: Arch) -> (u32, u32) {
229242
match arch {
230243
// Note: Arm64_sim is not included since macOS has no simulator.
231-
Arm64 | Arm64_macabi => (11, 0),
244+
Arm64 | Arm64e | Arm64_macabi => (11, 0),
232245
_ => (10, 12),
233246
}
234247
}
@@ -280,18 +293,19 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
280293
// Otherwise if cross-compiling for a different OS/SDK, remove any part
281294
// of the linking environment that's wrong and reversed.
282295
match arch {
283-
Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim | X86_64h
284-
| Arm64_sim => {
296+
Armv7k | Armv7s | Arm64 | Arm64e | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
297+
| X86_64h | Arm64_sim => {
285298
cvs!["MACOSX_DEPLOYMENT_TARGET"]
286299
}
287300
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
288301
}
289302
}
290303
}
291304

292-
fn ios_deployment_target() -> (u32, u32) {
305+
fn ios_deployment_target(arch: Arch) -> (u32, u32) {
293306
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
294-
from_set_deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((10, 0))
307+
let (major, minor) = if arch == Arm64e { (14, 0) } else { (10, 0) };
308+
from_set_deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((major, minor))
295309
}
296310

297311
fn mac_catalyst_deployment_target() -> (u32, u32) {
@@ -306,17 +320,17 @@ pub fn ios_llvm_target(arch: Arch) -> String {
306320
// set high enough. Luckily one LC_BUILD_VERSION is enough, for Xcode
307321
// to pick it up (since std and core are still built with the fallback
308322
// of version 7.0 and hence emit the old LC_IPHONE_MIN_VERSION).
309-
let (major, minor) = ios_deployment_target();
323+
let (major, minor) = ios_deployment_target(arch);
310324
format!("{}-apple-ios{}.{}.0", arch.target_name(), major, minor)
311325
}
312326

313-
fn ios_lld_platform_version() -> String {
314-
let (major, minor) = ios_deployment_target();
327+
fn ios_lld_platform_version(arch: Arch) -> String {
328+
let (major, minor) = ios_deployment_target(arch);
315329
format!("{major}.{minor}")
316330
}
317331

318332
pub fn ios_sim_llvm_target(arch: Arch) -> String {
319-
let (major, minor) = ios_deployment_target();
333+
let (major, minor) = ios_deployment_target(arch);
320334
format!("{}-apple-ios{}.{}.0-simulator", arch.target_name(), major, minor)
321335
}
322336

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ supported_targets! {
15661566
("i386-apple-ios", i386_apple_ios),
15671567
("x86_64-apple-ios", x86_64_apple_ios),
15681568
("aarch64-apple-ios", aarch64_apple_ios),
1569+
("arm64e-apple-ios", arm64e_apple_ios),
15691570
("armv7s-apple-ios", armv7s_apple_ios),
15701571
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
15711572
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::spec::base::apple::{ios_llvm_target, opts, Arch};
2+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let arch = Arch::Arm64e;
6+
let mut base = opts("ios", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
9+
Target {
10+
llvm_target: ios_llvm_target(arch).into(),
11+
pointer_width: 64,
12+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
13+
arch: arch.target_arch(),
14+
options: TargetOptions {
15+
features: "+neon,+fp-armv8,+apple-a12,+v8.3a,+paca,+pacg".into(),
16+
max_atomic_width: Some(128),
17+
forces_embed_bitcode: true,
18+
frame_pointer: FramePointer::NonLeaf,
19+
bitcode_llvm_cmdline: "-triple\0\
20+
arm64e-apple-ios14.1.0\0\
21+
-emit-obj\0\
22+
-disable-llvm-passes\0\
23+
-target-abi\0\
24+
darwinpcs\0\
25+
-Os\0"
26+
.into(),
27+
..base
28+
},
29+
}
30+
}

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Platform Support](platform-support.md)
1616
- [Target Tier Policy](target-tier-policy.md)
1717
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
18+
- [arm64e-apple-ios.md](platform-support/arm64e-apple-ios.md)
1819
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1920
- [\*-apple-tvos](platform-support/apple-tvos.md)
2021
- [\*-apple-watchos\*](platform-support/apple-watchos.md)

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ host tools.
216216

217217
target | std | host | notes
218218
-------|:---:|:----:|-------
219+
[`arm64e-apple-ios`](platform-support/arm64e-apple-ios.md) | ✓ | | ARM64e Apple iOS
219220
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
220221
[`aarch64-apple-tvos`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS
221222
[`aarch64-apple-tvos-sim`](platform-support/apple-tvos.md) | ? | | ARM64 tvOS Simulator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# `arm64e-apple-ios`
2+
3+
**Tier: 3**
4+
5+
ARM64e iOS (12.0+)
6+
7+
## Target maintainers
8+
9+
- Artyom Tetyukhin ([@arttet](https://github.com/https://github.com/arttet))
10+
11+
## Requirements
12+
13+
These targets only support cross-compilation.
14+
The targets do support `std`.
15+
16+
## Building the target
17+
18+
You can build Rust with support for the targets by adding it to the `target` list in `config.toml`:
19+
20+
```toml
21+
[build]
22+
target = [ "arm64e-apple-ios" ]
23+
```
24+
25+
## Building Rust programs
26+
27+
Rust does not yet ship pre-compiled artifacts for this target.
28+
To compile for this target, you will need to build Rust with the target enabled (see [Building the target](#building-the-target) above).
29+
30+
## Testing
31+
32+
The target does support running binaries on iOS platforms with `arm64e` architecture.
33+
34+
## Cross-compilation toolchains and C code
35+
36+
The targets do support `C` code.
37+
To build compatible `C` code, you have to use XCode with the same compiler and flags.

src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static HOSTS: &[&str] = &[
5151
static TARGETS: &[&str] = &[
5252
"aarch64-apple-darwin",
5353
"aarch64-apple-ios",
54+
"arm64e-apple-ios",
5455
"aarch64-apple-ios-sim",
5556
"aarch64-unknown-fuchsia",
5657
"aarch64-linux-android",

0 commit comments

Comments
 (0)