Skip to content

Add Apple WatchOS compile targets and stdlib support #94736

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

Closed
wants to merge 10 commits into from
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ version = "0.1.0"

[[package]]
name = "cc"
version = "1.0.69"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
dependencies = [
"jobserver",
]
Expand Down Expand Up @@ -1965,9 +1965,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.116"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,8 @@ unsafe fn embed_bitcode(
// reason (see issue #90326 for historical background).
let is_apple = cgcx.opts.target_triple.triple().contains("-ios")
|| cgcx.opts.target_triple.triple().contains("-darwin")
|| cgcx.opts.target_triple.triple().contains("-tvos");
|| cgcx.opts.target_triple.triple().contains("-tvos")
|| cgcx.opts.target_triple.triple().contains("-watchos");
if is_apple
|| cgcx.opts.target_triple.triple().starts_with("wasm")
|| cgcx.opts.target_triple.triple().starts_with("asmjs")
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
let os = &sess.target.os;
let llvm_target = &sess.target.llvm_target;
if sess.target.vendor != "apple"
|| !matches!(os.as_str(), "ios" | "tvos")
|| !matches!(os.as_str(), "ios" | "tvos" | "watchos")
|| flavor != LinkerFlavor::Gcc
{
return;
Expand All @@ -2472,6 +2472,10 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
("x86", "ios") => "iphonesimulator",
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx",
("x86_64", "ios") => "iphonesimulator",
("x86_64", "watchos") => "watchsimulator",
("arm64_32", "watchos") => "watchos",
("aarch64", "watchos") => "watchos",
("arm", "watchos") => "watchos",
_ => {
sess.err(&format!("unsupported arch `{}` for os `{}`", arch, os));
return;
Expand Down Expand Up @@ -2518,6 +2522,11 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
"macosx10.15"
if sdkroot.contains("iPhoneOS.platform")
|| sdkroot.contains("iPhoneSimulator.platform") => {}
"watchos"
if sdkroot.contains("WatchSimulator.platform")
|| sdkroot.contains("MacOSX.platform") => {}
"watchsimulator"
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
// Ignore `SDKROOT` if it's not a valid path.
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
_ => return Ok(sdkroot),
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,12 @@ pub fn ios_sim_llvm_target(arch: &str) -> String {
let (major, minor) = ios_deployment_target();
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
}

fn watchos_deployment_target() -> (u32, u32) {
deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
}

pub fn watchos_sim_llvm_target(arch: &str) -> String {
let (major, minor) = watchos_deployment_target();
format!("{}-apple-watchos{}.{}.0-simulator", arch, major, minor)
}
8 changes: 6 additions & 2 deletions compiler/rustc_target/src/spec/apple_sdk_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use Arch::*;
#[derive(Copy, Clone)]
pub enum Arch {
Armv7,
Armv7k,
Armv7s,
Arm64,
Arm64_32,
I386,
X86_64,
X86_64_macabi,
Expand All @@ -16,7 +18,7 @@ pub enum Arch {

fn target_abi(arch: Arch) -> String {
match arch {
Armv7 | Armv7s | Arm64 | I386 | X86_64 => "",
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 => "",
X86_64_macabi | Arm64_macabi => "macabi",
Arm64_sim => "sim",
}
Expand All @@ -26,8 +28,10 @@ fn target_abi(arch: Arch) -> String {
fn target_cpu(arch: Arch) -> String {
match arch {
Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
Armv7k => "cortex-a8",
Armv7s => "cortex-a9",
Arm64 => "apple-a7",
Arm64_32 => "apple-s4",
I386 => "yonah",
X86_64 => "core2",
X86_64_macabi => "core2",
Expand All @@ -39,7 +43,7 @@ fn target_cpu(arch: Arch) -> String {

fn link_env_remove(arch: Arch) -> Vec<String> {
match arch {
Armv7 | Armv7s | Arm64 | I386 | X86_64 | Arm64_sim => {
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | Arm64_sim => {
vec!["MACOSX_DEPLOYMENT_TARGET".to_string()]
}
X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()],
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_target/src/spec/arm64_32_apple_watchos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let base = opts("watchos", Arch::Arm64_32);
Target {
llvm_target: "arm64_32-apple-watchos".to_string(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".to_string(),
max_atomic_width: Some(64),
forces_embed_bitcode: true,
// These arguments are not actually invoked - they just have
// to look right to pass App Store validation.
bitcode_llvm_cmdline: "-triple\0\
arm64_32-apple-watchos5.0.0\0\
-emit-obj\0\
-disable-llvm-passes\0\
-target-abi\0\
darwinpcs\0\
-Os\0"
.to_string(),
..base
},
}
}
28 changes: 28 additions & 0 deletions compiler/rustc_target/src/spec/armv7k_apple_watchos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let base = opts("watchos", Arch::Armv7k);
Target {
llvm_target: "armv7k-apple-watchos".to_string(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128".to_string(),
arch: "arm".to_string(),
options: TargetOptions {
features: "+v7,+vfp4,+neon".to_string(),
max_atomic_width: Some(64),
forces_embed_bitcode: true,
// These arguments are not actually invoked - they just have
// to look right to pass App Store validation.
bitcode_llvm_cmdline: "-triple\0\
armv7k-apple-watchos3.0.0\0\
-emit-obj\0\
-disable-llvm-passes\0\
-target-abi\0\
darwinpcs\0\
-Os\0"
.to_string(),
..base
},
}
}
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,10 @@ supported_targets! {
("aarch64-apple-tvos", aarch64_apple_tvos),
("x86_64-apple-tvos", x86_64_apple_tvos),

("armv7k-apple-watchos", armv7k_apple_watchos),
("arm64_32-apple-watchos", arm64_32_apple_watchos),
("x86_64-apple-watchos-sim", x86_64_apple_watchos_sim),

("armebv7r-none-eabi", armebv7r_none_eabi),
("armebv7r-none-eabihf", armebv7r_none_eabihf),
("armv7r-none-eabi", armv7r_none_eabi),
Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};

pub fn target() -> Target {
let base = opts("watchos", Arch::X86_64);

let arch = "x86_64";
let llvm_target = super::apple_base::watchos_sim_llvm_target(arch);

Target {
llvm_target,
pointer_width: 64,
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.to_string(),
arch: "x86_64".to_string(),
options: TargetOptions {
max_atomic_width: Some(64),
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
stack_probes: StackProbeType::Call,
forces_embed_bitcode: true,
// Taken from a clang build on Xcode 11.4.1.
// These arguments are not actually invoked - they just have
// to look right to pass App Store validation.
bitcode_llvm_cmdline: "-triple\0\
x86_64-apple-watchos5.0-simulator\0\
-emit-obj\0\
-disable-llvm-passes\0\
-target-abi\0\
darwinpcs\0\
-Os\0"
.to_string(),
..base
},
}
}
4 changes: 2 additions & 2 deletions library/panic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ doc = false
alloc = { path = "../alloc" }
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
core = { path = "../core" }
libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0"
libc = { version = "*", default-features = false }
compiler_builtins = "*"
2 changes: 1 addition & 1 deletion library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

cfg_if::cfg_if! {
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "netbsd")))] {
if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "watchos"), not(target_os = "netbsd")))] {
// ARM EHABI personality routine.
// https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
//
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
|| target.contains("illumos")
|| target.contains("apple-darwin")
|| target.contains("apple-ios")
|| target.contains("apple-watchos")
|| target.contains("uwp")
|| target.contains("windows")
|| target.contains("fuchsia")
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ pub mod openbsd;
pub mod redox;
#[cfg(target_os = "solaris")]
pub mod solaris;

#[cfg(target_os = "solid_asp3")]
pub mod solid;
#[cfg(target_os = "vxworks")]
pub mod vxworks;
#[cfg(target_os = "watchos")]
pub mod watchos;

#[cfg(any(unix, target_os = "wasi", doc))]
mod fd;
3 changes: 3 additions & 0 deletions library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ mod platform {
pub use crate::os::solaris::*;
#[cfg(target_os = "vxworks")]
pub use crate::os::vxworks::*;
#[cfg(target_os = "watchos")]
pub use crate::os::watchos::*;
}

pub mod ffi;
Expand All @@ -88,6 +90,7 @@ pub mod thread;
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand All @@ -38,6 +39,7 @@ use crate::time::Duration;
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down Expand Up @@ -246,6 +248,7 @@ impl UnixStream {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "watchos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/unix/ucred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
))]
pub use self::impl_bsd::peer_cred;

#[cfg(any(target_os = "macos", target_os = "ios",))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos",))]
pub use self::impl_mac::peer_cred;

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -97,7 +97,7 @@ pub mod impl_bsd {
}
}

#[cfg(any(target_os = "macos", target_os = "ios",))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos",))]
pub mod impl_mac {
use super::UCred;
use crate::os::unix::io::AsRawFd;
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/unix/ucred/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use libc::{getegid, geteuid, getpid};
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "watchos",
target_os = "macos",
target_os = "openbsd"
))]
Expand All @@ -25,7 +26,7 @@ fn test_socket_pair() {
}

#[test]
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos",))]
#[cfg(any(target_os = "linux", target_os = "ios", target_os = "macos", target_os = "watchos",))]
fn test_socket_pair_pids(arg: Type) -> RetType {
// Create two connected sockets and get their peer credentials.
let (sock_a, sock_b) = UnixStream::pair().unwrap();
Expand Down
Loading