Skip to content

Commit a488cf8

Browse files
authored
Rollup merge of #136842 - randomPoison:trusty-libstd-v3, r=ChrisDenton
Add libstd support for Trusty targets This PR adds support for `alloc` and `std` for the Trusty targets based on the internal patches used in Android. The original patches can be seen [here](https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main/patches/development/rustc-0023-Add-Trusty-OS-support-to-Rust-std.patch) and [here](https://android.googlesource.com/toolchain/android_rust/+/refs/heads/main/patches/development/rustc-0054-Add-std-os-fd-support-for-Trusty.patch). Please let me know if there's any additional context I need to add.
2 parents b3ab695 + d3c55cd commit a488cf8

21 files changed

Lines changed: 181 additions & 15 deletions

File tree

‎library/std/build.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn main() {
4242
|| target_os == "fuchsia"
4343
|| (target_vendor == "fortanix" && target_env == "sgx")
4444
|| target_os == "hermit"
45+
|| target_os == "trusty"
4546
|| target_os == "l4re"
4647
|| target_os == "redox"
4748
|| target_os == "haiku"

‎library/std/src/fs.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
target_os = "emscripten",
1515
target_os = "wasi",
1616
target_env = "sgx",
17-
target_os = "xous"
17+
target_os = "xous",
18+
target_os = "trusty",
1819
))
1920
))]
2021
mod tests;

‎library/std/src/net/tcp.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
not(any(
66
target_os = "emscripten",
77
all(target_os = "wasi", target_env = "p1"),
8-
target_os = "xous"
8+
target_os = "xous",
9+
target_os = "trusty",
910
))
1011
))]
1112
mod tests;

‎library/std/src/net/udp.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
target_os = "emscripten",
55
all(target_os = "wasi", target_env = "p1"),
66
target_env = "sgx",
7-
target_os = "xous"
7+
target_os = "xous",
8+
target_os = "trusty",
89
))
910
))]
1011
mod tests;

‎library/std/src/os/fd/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod raw;
1313
mod owned;
1414

1515
// Implementations for `AsRawFd` etc. for network types.
16+
#[cfg(not(target_os = "trusty"))]
1617
mod net;
1718

1819
#[cfg(test)]

‎library/std/src/os/fd/owned.rs‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
#![deny(unsafe_op_in_unsafe_fn)]
55

66
usesuper::raw::{AsRawFd,FromRawFd,IntoRawFd,RawFd};
7+
#[cfg(not(target_os = "trusty"))]
8+
usecrate::fs;
79
usecrate::marker::PhantomData;
810
usecrate::mem::ManuallyDrop;
9-
#[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit")))]
11+
#[cfg(not(any(
12+
target_arch = "wasm32",
13+
target_env = "sgx",
14+
target_os = "hermit",
15+
target_os = "trusty"
16+
)))]
1017
usecrate::sys::cvt;
18+
#[cfg(not(target_os = "trusty"))]
1119
usecrate::sys_common::{AsInner,FromInner,IntoInner};
12-
usecrate::{fmt,fs,io};
20+
usecrate::{fmt, io};
1321

1422
typeValidRawFd = core::num::niche_types::NotAllOnes<RawFd>;
1523

@@ -87,7 +95,7 @@ impl OwnedFd {
8795
implBorrowedFd<'_>{
8896
/// Creates a new `OwnedFd` instance that shares the same underlying file
8997
/// description as the existing `BorrowedFd` instance.
90-
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit")))]
98+
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit", target_os = "trusty")))]
9199
#[stable(feature = "io_safety", since = "1.63.0")]
92100
pubfntry_clone_to_owned(&self) -> crate::io::Result<OwnedFd>{
93101
// We want to atomically duplicate this file descriptor and set the
@@ -110,7 +118,7 @@ impl BorrowedFd<'_> {
110118

111119
/// Creates a new `OwnedFd` instance that shares the same underlying file
112120
/// description as the existing `BorrowedFd` instance.
113-
#[cfg(any(target_arch = "wasm32", target_os = "hermit"))]
121+
#[cfg(any(target_arch = "wasm32", target_os = "hermit", target_os = "trusty"))]
114122
#[stable(feature = "io_safety", since = "1.63.0")]
115123
pubfntry_clone_to_owned(&self) -> crate::io::Result<OwnedFd>{
116124
Err(crate::io::Error::UNSUPPORTED_PLATFORM)
@@ -280,6 +288,7 @@ impl AsFd for OwnedFd {
280288
}
281289

282290
#[stable(feature = "io_safety", since = "1.63.0")]
291+
#[cfg(not(target_os = "trusty"))]
283292
implAsFdfor fs::File{
284293
#[inline]
285294
fnas_fd(&self) -> BorrowedFd<'_>{
@@ -288,6 +297,7 @@ impl AsFd for fs::File {
288297
}
289298

290299
#[stable(feature = "io_safety", since = "1.63.0")]
300+
#[cfg(not(target_os = "trusty"))]
291301
implFrom<fs::File>forOwnedFd{
292302
/// Takes ownership of a [`File`](fs::File)'s underlying file descriptor.
293303
#[inline]
@@ -297,6 +307,7 @@ impl From<fs::File> for OwnedFd {
297307
}
298308

299309
#[stable(feature = "io_safety", since = "1.63.0")]
310+
#[cfg(not(target_os = "trusty"))]
300311
implFrom<OwnedFd>for fs::File{
301312
/// Returns a [`File`](fs::File) that takes ownership of the given
302313
/// file descriptor.
@@ -307,6 +318,7 @@ impl From<OwnedFd> for fs::File {
307318
}
308319

309320
#[stable(feature = "io_safety", since = "1.63.0")]
321+
#[cfg(not(target_os = "trusty"))]
310322
implAsFdforcrate::net::TcpStream{
311323
#[inline]
312324
fnas_fd(&self) -> BorrowedFd<'_>{
@@ -315,6 +327,7 @@ impl AsFd for crate::net::TcpStream {
315327
}
316328

317329
#[stable(feature = "io_safety", since = "1.63.0")]
330+
#[cfg(not(target_os = "trusty"))]
318331
implFrom<crate::net::TcpStream>forOwnedFd{
319332
/// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor.
320333
#[inline]
@@ -324,6 +337,7 @@ impl From<crate::net::TcpStream> for OwnedFd {
324337
}
325338

326339
#[stable(feature = "io_safety", since = "1.63.0")]
340+
#[cfg(not(target_os = "trusty"))]
327341
implFrom<OwnedFd>forcrate::net::TcpStream{
328342
#[inline]
329343
fnfrom(owned_fd:OwnedFd) -> Self{
@@ -334,6 +348,7 @@ impl From<OwnedFd> for crate::net::TcpStream {
334348
}
335349

336350
#[stable(feature = "io_safety", since = "1.63.0")]
351+
#[cfg(not(target_os = "trusty"))]
337352
implAsFdforcrate::net::TcpListener{
338353
#[inline]
339354
fnas_fd(&self) -> BorrowedFd<'_>{
@@ -342,6 +357,7 @@ impl AsFd for crate::net::TcpListener {
342357
}
343358

344359
#[stable(feature = "io_safety", since = "1.63.0")]
360+
#[cfg(not(target_os = "trusty"))]
345361
implFrom<crate::net::TcpListener>forOwnedFd{
346362
/// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor.
347363
#[inline]
@@ -351,6 +367,7 @@ impl From<crate::net::TcpListener> for OwnedFd {
351367
}
352368

353369
#[stable(feature = "io_safety", since = "1.63.0")]
370+
#[cfg(not(target_os = "trusty"))]
354371
implFrom<OwnedFd>forcrate::net::TcpListener{
355372
#[inline]
356373
fnfrom(owned_fd:OwnedFd) -> Self{
@@ -361,6 +378,7 @@ impl From<OwnedFd> for crate::net::TcpListener {
361378
}
362379

363380
#[stable(feature = "io_safety", since = "1.63.0")]
381+
#[cfg(not(target_os = "trusty"))]
364382
implAsFdforcrate::net::UdpSocket{
365383
#[inline]
366384
fnas_fd(&self) -> BorrowedFd<'_>{
@@ -369,6 +387,7 @@ impl AsFd for crate::net::UdpSocket {
369387
}
370388

371389
#[stable(feature = "io_safety", since = "1.63.0")]
390+
#[cfg(not(target_os = "trusty"))]
372391
implFrom<crate::net::UdpSocket>forOwnedFd{
373392
/// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor.
374393
#[inline]
@@ -378,6 +397,7 @@ impl From<crate::net::UdpSocket> for OwnedFd {
378397
}
379398

380399
#[stable(feature = "io_safety", since = "1.63.0")]
400+
#[cfg(not(target_os = "trusty"))]
381401
implFrom<OwnedFd>forcrate::net::UdpSocket{
382402
#[inline]
383403
fnfrom(owned_fd:OwnedFd) -> Self{

‎library/std/src/os/fd/raw.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#[cfg(target_os = "hermit")]
66
use hermit_abi as libc;
77

8+
#[cfg(not(target_os = "trusty"))]
9+
usecrate::fs;
10+
usecrate::io;
811
#[cfg(target_os = "hermit")]
912
usecrate::os::hermit::io::OwnedFd;
1013
#[cfg(not(target_os = "hermit"))]
@@ -15,8 +18,8 @@ use crate::os::unix::io::AsFd;
1518
usecrate::os::unix::io::OwnedFd;
1619
#[cfg(target_os = "wasi")]
1720
usecrate::os::wasi::io::OwnedFd;
21+
#[cfg(not(target_os = "trusty"))]
1822
usecrate::sys_common::{AsInner,IntoInner};
19-
usecrate::{fs, io};
2023

2124
/// Raw file descriptors.
2225
#[stable(feature = "rust1", since = "1.0.0")]
@@ -161,20 +164,23 @@ impl FromRawFd for RawFd {
161164
}
162165

163166
#[stable(feature = "rust1", since = "1.0.0")]
167+
#[cfg(not(target_os = "trusty"))]
164168
implAsRawFdfor fs::File{
165169
#[inline]
166170
fnas_raw_fd(&self) -> RawFd{
167171
self.as_inner().as_raw_fd()
168172
}
169173
}
170174
#[stable(feature = "from_raw_os", since = "1.1.0")]
175+
#[cfg(not(target_os = "trusty"))]
171176
implFromRawFdfor fs::File{
172177
#[inline]
173178
unsafefnfrom_raw_fd(fd:RawFd) -> fs::File{
174179
unsafe{ fs::File::from(OwnedFd::from_raw_fd(fd))}
175180
}
176181
}
177182
#[stable(feature = "into_raw_os", since = "1.4.0")]
183+
#[cfg(not(target_os = "trusty"))]
178184
implIntoRawFdfor fs::File{
179185
#[inline]
180186
fninto_raw_fd(self) -> RawFd{
@@ -183,6 +189,7 @@ impl IntoRawFd for fs::File {
183189
}
184190

185191
#[stable(feature = "asraw_stdio", since = "1.21.0")]
192+
#[cfg(not(target_os = "trusty"))]
186193
implAsRawFdfor io::Stdin{
187194
#[inline]
188195
fnas_raw_fd(&self) -> RawFd{
@@ -207,6 +214,7 @@ impl AsRawFd for io::Stderr {
207214
}
208215

209216
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
217+
#[cfg(not(target_os = "trusty"))]
210218
impl<'a>AsRawFdfor io::StdinLock<'a>{
211219
#[inline]
212220
fnas_raw_fd(&self) -> RawFd{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub mod rtems;
169169
pubmod solaris;
170170
#[cfg(target_os = "solid_asp3")]
171171
pubmod solid;
172+
#[cfg(target_os = "trusty")]
173+
pubmod trusty;
172174
#[cfg(target_os = "uefi")]
173175
pubmod uefi;
174176
#[cfg(target_os = "vita")]
@@ -178,7 +180,7 @@ pub mod vxworks;
178180
#[cfg(target_os = "xous")]
179181
pubmod xous;
180182

181-
#[cfg(any(unix, target_os = "hermit", target_os = "wasi", doc))]
183+
#[cfg(any(unix, target_os = "hermit", target_os = "trusty", target_os = "wasi", doc))]
182184
pubmod fd;
183185

184186
#[cfg(any(target_os = "linux", target_os = "android", doc))]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![stable(feature = "os_fd", since = "1.66.0")]
2+
3+
#[stable(feature = "os_fd", since = "1.66.0")]
4+
pubusecrate::os::fd::*;

‎library/std/src/os/trusty/mod.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![stable(feature = "rust1", since = "1.0.0")]
2+
3+
pubmod io;

0 commit comments

Comments
 (0)