Skip to content

Commit 08a7e59

Browse files
committed
[watch_os] add stdlib (match ios)
[watch_os] misc fixes [watch_os] fix target builds
1 parent c3457cf commit 08a7e59

File tree

26 files changed

+312
-28
lines changed

26 files changed

+312
-28
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ rustfmt-nightly = { path = "src/tools/rustfmt" }
125125
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
126126
# here
127127
rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
128+
cc = { git = "https://github.com/vladimir-ea/cc-rs", branch = "watch_os" }
129+
libc = { git = "https://github.com/vladimir-ea/libc", branch = "watch_os" }
128130

129131
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
130132
# here

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
24572457
let os = &sess.target.os;
24582458
let llvm_target = &sess.target.llvm_target;
24592459
if sess.target.vendor != "apple"
2460-
|| !matches!(os.as_str(), "ios" | "tvos")
2460+
|| !matches!(os.as_str(), "ios" | "tvos" | "watchos")
24612461
|| flavor != LinkerFlavor::Gcc
24622462
{
24632463
return;
@@ -2472,6 +2472,10 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
24722472
("x86", "ios") => "iphonesimulator",
24732473
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx",
24742474
("x86_64", "ios") => "iphonesimulator",
2475+
("x86_64", "watchos") => "watchsimulator",
2476+
("arm64_32", "watchos") => "watchos",
2477+
("aarch64", "watchos") => "watchos",
2478+
("armv7k", "watchos") => "watchos",
24752479
_ => {
24762480
sess.err(&format!("unsupported arch `{}` for os `{}`", arch, os));
24772481
return;
@@ -2518,13 +2522,18 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
25182522
"macosx10.15"
25192523
if sdkroot.contains("iPhoneOS.platform")
25202524
|| sdkroot.contains("iPhoneSimulator.platform") => {}
2525+
"watchos"
2526+
if sdkroot.contains("WatchSimulator.platform")
2527+
|| sdkroot.contains("MacOSX.platform") => {}
2528+
"watchsimulator"
2529+
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
25212530
// Ignore `SDKROOT` if it's not a valid path.
25222531
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
25232532
_ => return Ok(sdkroot),
25242533
}
25252534
}
25262535
let res =
2527-
Command::new("xcrun").arg("--show-sdk-path").arg("-sdk").arg(sdk_name).output().and_then(
2536+
Command::new("xcrunp").arg("--show-sdk-path").arg("-sdk").arg(sdk_name).output().and_then(
25282537
|output| {
25292538
if output.status.success() {
25302539
Ok(String::from_utf8(output.stdout).unwrap())

compiler/rustc_target/src/spec/armv7k_apple_watchos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn target() -> Target {
99
data_layout: "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128".to_string(),
1010
arch: "arm".to_string(),
1111
options: TargetOptions {
12-
features: "+v7".to_string(),
12+
features: "+v7,+vfp4,+neon".to_string(),
1313
max_atomic_width: Some(64),
1414
unsupported_abis: super::arm_base::unsupported_abis(),
1515
..base

library/panic_abort/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ doc = false
1515
alloc = { path = "../alloc" }
1616
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1717
core = { path = "../core" }
18-
libc = { version = "0.2", default-features = false }
19-
compiler_builtins = "0.1.0"
18+
libc = { version = "*", default-features = false }
19+
compiler_builtins = "*"

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub mod illumos;
129129
pub mod ios;
130130
#[cfg(target_os = "l4re")]
131131
pub mod l4re;
132+
#[cfg(target_os = "watchos")]
133+
pub mod watchos;
132134
#[cfg(target_os = "macos")]
133135
pub mod macos;
134136
#[cfg(target_os = "netbsd")]

library/std/src/os/unix/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ mod platform {
7171
pub use crate::os::solaris::*;
7272
#[cfg(target_os = "vxworks")]
7373
pub use crate::os::vxworks::*;
74+
#[cfg(target_os = "watchos")]
75+
pub use crate::os::watchos::*;
7476
}
7577

7678
pub mod ffi;
@@ -88,6 +90,7 @@ pub mod thread;
8890
target_os = "dragonfly",
8991
target_os = "freebsd",
9092
target_os = "ios",
93+
target_os = "watchos",
9194
target_os = "macos",
9295
target_os = "netbsd",
9396
target_os = "openbsd"

library/std/src/os/unix/net/stream.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
2020
target_os = "dragonfly",
2121
target_os = "freebsd",
2222
target_os = "ios",
23+
target_os = "watchos",
2324
target_os = "macos",
2425
target_os = "netbsd",
2526
target_os = "openbsd"
@@ -38,6 +39,7 @@ use crate::time::Duration;
3839
target_os = "dragonfly",
3940
target_os = "freebsd",
4041
target_os = "ios",
42+
target_os = "watchos",
4143
target_os = "macos",
4244
target_os = "netbsd",
4345
target_os = "openbsd"
@@ -246,6 +248,7 @@ impl UnixStream {
246248
target_os = "dragonfly",
247249
target_os = "freebsd",
248250
target_os = "ios",
251+
target_os = "watchos",
249252
target_os = "macos",
250253
target_os = "netbsd",
251254
target_os = "openbsd"

library/std/src/os/unix/ucred.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
3636
))]
3737
pub use self::impl_bsd::peer_cred;
3838

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

4242
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -97,7 +97,7 @@ pub mod impl_bsd {
9797
}
9898
}
9999

100-
#[cfg(any(target_os = "macos", target_os = "ios",))]
100+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos",))]
101101
pub mod impl_mac {
102102
use super::UCred;
103103
use crate::os::unix::io::AsRawFd;

library/std/src/os/unix/ucred/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use libc::{getegid, geteuid, getpid};
88
target_os = "dragonfly",
99
target_os = "freebsd",
1010
target_os = "ios",
11+
target_os = "watchos",
1112
target_os = "macos",
1213
target_os = "openbsd"
1314
))]
@@ -25,7 +26,7 @@ fn test_socket_pair() {
2526
}
2627

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

library/std/src/os/watchos/fs.rs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::Metadata;
4+
use crate::sys_common::AsInner;
5+
6+
#[allow(deprecated)]
7+
use crate::os::watchos::raw;
8+
9+
/// OS-specific extensions to [`fs::Metadata`].
10+
///
11+
/// [`fs::Metadata`]: crate::fs::Metadata
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
pub trait MetadataExt {
14+
/// Gain a reference to the underlying `stat` structure which contains
15+
/// the raw information returned by the OS.
16+
///
17+
/// The contents of the returned `stat` are **not** consistent across
18+
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
19+
/// cross-Unix abstractions contained within the raw stat.
20+
#[stable(feature = "metadata_ext", since = "1.1.0")]
21+
#[rustc_deprecated(
22+
since = "1.8.0",
23+
reason = "deprecated in favor of the accessor \
24+
methods of this trait"
25+
)]
26+
#[allow(deprecated)]
27+
fn as_raw_stat(&self) -> &raw::stat;
28+
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_dev(&self) -> u64;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_ino(&self) -> u64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_mode(&self) -> u32;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_nlink(&self) -> u64;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_uid(&self) -> u32;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_gid(&self) -> u32;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_rdev(&self) -> u64;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_size(&self) -> u64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_atime(&self) -> i64;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_atime_nsec(&self) -> i64;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_mtime(&self) -> i64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_mtime_nsec(&self) -> i64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_ctime(&self) -> i64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_ctime_nsec(&self) -> i64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_birthtime(&self) -> i64;
59+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
60+
fn st_birthtime_nsec(&self) -> i64;
61+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
62+
fn st_blksize(&self) -> u64;
63+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
64+
fn st_blocks(&self) -> u64;
65+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
66+
fn st_flags(&self) -> u32;
67+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
68+
fn st_gen(&self) -> u32;
69+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
70+
fn st_lspare(&self) -> u32;
71+
}
72+
73+
#[stable(feature = "metadata_ext", since = "1.1.0")]
74+
impl MetadataExt for Metadata {
75+
#[allow(deprecated)]
76+
fn as_raw_stat(&self) -> &raw::stat {
77+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
78+
}
79+
fn st_dev(&self) -> u64 {
80+
self.as_inner().as_inner().st_dev as u64
81+
}
82+
fn st_ino(&self) -> u64 {
83+
self.as_inner().as_inner().st_ino as u64
84+
}
85+
fn st_mode(&self) -> u32 {
86+
self.as_inner().as_inner().st_mode as u32
87+
}
88+
fn st_nlink(&self) -> u64 {
89+
self.as_inner().as_inner().st_nlink as u64
90+
}
91+
fn st_uid(&self) -> u32 {
92+
self.as_inner().as_inner().st_uid as u32
93+
}
94+
fn st_gid(&self) -> u32 {
95+
self.as_inner().as_inner().st_gid as u32
96+
}
97+
fn st_rdev(&self) -> u64 {
98+
self.as_inner().as_inner().st_rdev as u64
99+
}
100+
fn st_size(&self) -> u64 {
101+
self.as_inner().as_inner().st_size as u64
102+
}
103+
fn st_atime(&self) -> i64 {
104+
self.as_inner().as_inner().st_atime as i64
105+
}
106+
fn st_atime_nsec(&self) -> i64 {
107+
self.as_inner().as_inner().st_atime_nsec as i64
108+
}
109+
fn st_mtime(&self) -> i64 {
110+
self.as_inner().as_inner().st_mtime as i64
111+
}
112+
fn st_mtime_nsec(&self) -> i64 {
113+
self.as_inner().as_inner().st_mtime_nsec as i64
114+
}
115+
fn st_ctime(&self) -> i64 {
116+
self.as_inner().as_inner().st_ctime as i64
117+
}
118+
fn st_ctime_nsec(&self) -> i64 {
119+
self.as_inner().as_inner().st_ctime_nsec as i64
120+
}
121+
fn st_birthtime(&self) -> i64 {
122+
self.as_inner().as_inner().st_birthtime as i64
123+
}
124+
fn st_birthtime_nsec(&self) -> i64 {
125+
self.as_inner().as_inner().st_birthtime_nsec as i64
126+
}
127+
fn st_blksize(&self) -> u64 {
128+
self.as_inner().as_inner().st_blksize as u64
129+
}
130+
fn st_blocks(&self) -> u64 {
131+
self.as_inner().as_inner().st_blocks as u64
132+
}
133+
fn st_gen(&self) -> u32 {
134+
self.as_inner().as_inner().st_gen as u32
135+
}
136+
fn st_flags(&self) -> u32 {
137+
self.as_inner().as_inner().st_flags as u32
138+
}
139+
fn st_lspare(&self) -> u32 {
140+
self.as_inner().as_inner().st_lspare as u32
141+
}
142+
}

library/std/src/os/watchos/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! watchOS-specific definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
5+
pub mod fs;
6+
pub mod raw;

library/std/src/os/watchos/raw.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//! watchOS-specific raw type definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![rustc_deprecated(
5+
since = "1.8.0",
6+
reason = "these type aliases are no longer supported by \
7+
the standard library, the `libc` crate on \
8+
crates.io should be used instead for the correct \
9+
definitions"
10+
)]
11+
#![allow(deprecated)]
12+
13+
use crate::os::raw::c_long;
14+
15+
#[stable(feature = "raw_ext", since = "1.1.0")]
16+
pub type blkcnt_t = u64;
17+
#[stable(feature = "raw_ext", since = "1.1.0")]
18+
pub type blksize_t = u64;
19+
#[stable(feature = "raw_ext", since = "1.1.0")]
20+
pub type dev_t = u64;
21+
#[stable(feature = "raw_ext", since = "1.1.0")]
22+
pub type ino_t = u64;
23+
#[stable(feature = "raw_ext", since = "1.1.0")]
24+
pub type mode_t = u32;
25+
#[stable(feature = "raw_ext", since = "1.1.0")]
26+
pub type nlink_t = u64;
27+
#[stable(feature = "raw_ext", since = "1.1.0")]
28+
pub type off_t = u64;
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
30+
pub type time_t = i64;
31+
32+
#[stable(feature = "pthread_t", since = "1.8.0")]
33+
pub type pthread_t = usize;
34+
35+
#[repr(C)]
36+
#[derive(Clone)]
37+
#[stable(feature = "raw_ext", since = "1.1.0")]
38+
pub struct stat {
39+
#[stable(feature = "raw_ext", since = "1.1.0")]
40+
pub st_dev: i32,
41+
#[stable(feature = "raw_ext", since = "1.1.0")]
42+
pub st_mode: u16,
43+
#[stable(feature = "raw_ext", since = "1.1.0")]
44+
pub st_nlink: u16,
45+
#[stable(feature = "raw_ext", since = "1.1.0")]
46+
pub st_ino: u64,
47+
#[stable(feature = "raw_ext", since = "1.1.0")]
48+
pub st_uid: u32,
49+
#[stable(feature = "raw_ext", since = "1.1.0")]
50+
pub st_gid: u32,
51+
#[stable(feature = "raw_ext", since = "1.1.0")]
52+
pub st_rdev: i32,
53+
#[stable(feature = "raw_ext", since = "1.1.0")]
54+
pub st_atime: c_long,
55+
#[stable(feature = "raw_ext", since = "1.1.0")]
56+
pub st_atime_nsec: c_long,
57+
#[stable(feature = "raw_ext", since = "1.1.0")]
58+
pub st_mtime: c_long,
59+
#[stable(feature = "raw_ext", since = "1.1.0")]
60+
pub st_mtime_nsec: c_long,
61+
#[stable(feature = "raw_ext", since = "1.1.0")]
62+
pub st_ctime: c_long,
63+
#[stable(feature = "raw_ext", since = "1.1.0")]
64+
pub st_ctime_nsec: c_long,
65+
#[stable(feature = "raw_ext", since = "1.1.0")]
66+
pub st_birthtime: c_long,
67+
#[stable(feature = "raw_ext", since = "1.1.0")]
68+
pub st_birthtime_nsec: c_long,
69+
#[stable(feature = "raw_ext", since = "1.1.0")]
70+
pub st_size: i64,
71+
#[stable(feature = "raw_ext", since = "1.1.0")]
72+
pub st_blocks: i64,
73+
#[stable(feature = "raw_ext", since = "1.1.0")]
74+
pub st_blksize: i32,
75+
#[stable(feature = "raw_ext", since = "1.1.0")]
76+
pub st_flags: u32,
77+
#[stable(feature = "raw_ext", since = "1.1.0")]
78+
pub st_gen: u32,
79+
#[stable(feature = "raw_ext", since = "1.1.0")]
80+
pub st_lspare: i32,
81+
#[stable(feature = "raw_ext", since = "1.1.0")]
82+
pub st_qspare: [i64; 2],
83+
}

0 commit comments

Comments
 (0)