diff options
| author | bors <bors@rust-lang.org> | 2022-06-15 14:21:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-15 14:21:28 +0000 |
| commit | c3605f8c8020dbbe8f0d1961c7b33c4c4b78ad0d (patch) | |
| tree | 9c69ec553ce9679b117c2fdf6cbdbe66512b7fc8 /library/std/src/os/unix/process.rs | |
| parent | a4cec9742b7e05c33c84cd75002cd56762f7e33b (diff) | |
| parent | c814f842e46de25c95e08551a29f06ede1880a47 (diff) | |
| download | rust-c3605f8c8020dbbe8f0d1961c7b33c4c4b78ad0d.tar.gz rust-c3605f8c8020dbbe8f0d1961c7b33c4c4b78ad0d.zip | |
Auto merge of #95897 - AzureMarker:feature/horizon-std, r=nagisa
STD support for the Nintendo 3DS Rustc already supports compiling for the Nintendo 3DS using the `armv6k-nintendo-3ds` target (Tier 3). Until now though, only `core` and `alloc` were supported. This PR adds standard library support for the Nintendo 3DS. A notable exclusion is `std::thread` support, which will come in a follow-up PR as it requires more complicated changes. This has been a joint effort by `@Meziu,` `@ian-h-chamberlain,` myself, and prior work by `@rust3ds` members. ### Background The Nintendo 3DS (Horizon OS) is a mostly-UNIX looking system, with the caveat that it does not come with a full libc implementation out of the box. On the homebrew side (I'm not under NDA), the libc interface is partially implemented by the [devkitPro](https://devkitpro.org/wiki/devkitPro_pacman) toolchain and a user library like [`libctru`](https://github.com/devkitPro/libctru). This is important because there are [some possible legal barriers](https://github.com/rust-lang/rust/pull/88529#issuecomment-919938396) to linking directly to a library that uses the underlying platform APIs, since they might be considered a trade secret or under NDA. To get around this, the standard library impl for the 3DS does not directly depend on any platform-level APIs. Instead, it expects standard libc functions to be linked in. The implementation of these libc functions is left to the user. Some functions are provided by the devkitPro toolchain, but in our testing, we used the following to fill in the other functions: - [`libctru`] - provides more basic APIs, such as `nanosleep`. Linked in by way of [`ctru-sys`](https://github.com/Meziu/ctru-rs/tree/master/ctru-sys). - [`pthread-3ds`](https://github.com/Meziu/pthread-3ds) - provides pthread APIs for `std::thread`. Implemented using [`libctru`]. - [`linker-fix-3ds`](https://github.com/Meziu/rust-linker-fix-3ds) - fulfills some other missing libc APIs. Implemented using [`libctru`]. For more details, see the `src/doc/rustc/src/platform-support/armv6k-nintendo-3ds.md` file added in this PR. ### Notes We've already upstreamed changes to the [`libc`] crate to support this PR, as well as the upcoming threading PR. These changes have all been released as of 0.2.121, so we bump the crate version in this PR. Edit: After some rebases, the version bump has already been merged so it doesn't appear in this PR. A lot of the changes in this PR are straightforward, and follow in the footsteps of the ESP-IDF target: https://github.com/rust-lang/rust/pull/87666. The 3DS does not support user space process spawning, so these APIs are unimplemented (similar to ESP-IDF). [`libctru`]: https://github.com/devkitPro/libctru [`libc`]: https://github.com/rust-lang/libc
Diffstat (limited to 'library/std/src/os/unix/process.rs')
| -rw-r--r-- | library/std/src/os/unix/process.rs | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 3e989c85db9..5065530e8d4 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -12,6 +12,16 @@ use crate::sealed::Sealed; use crate::sys; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; +#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] +type UserId = u32; +#[cfg(not(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon")))] +type GroupId = u32; + +#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] +type UserId = u16; +#[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon"))] +type GroupId = u16; + /// Unix-specific extensions to the [`process::Command`] builder. /// /// This trait is sealed: it cannot be implemented outside the standard library. @@ -22,29 +32,17 @@ pub trait CommandExt: Sealed { /// `setuid` call in the child process. Failure in the `setuid` /// call will cause the spawn to fail. #[stable(feature = "rust1", since = "1.0.0")] - fn uid( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, - ) -> &mut process::Command; + fn uid(&mut self, id: UserId) -> &mut process::Command; /// Similar to `uid`, but sets the group ID of the child process. This has /// the same semantics as the `uid` field. #[stable(feature = "rust1", since = "1.0.0")] - fn gid( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, - ) -> &mut process::Command; + fn gid(&mut self, id: GroupId) -> &mut process::Command; /// Sets the supplementary group IDs for the calling process. Translates to /// a `setgroups` call in the child process. #[unstable(feature = "setgroups", issue = "90747")] - fn groups( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32], - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16], - ) -> &mut process::Command; + fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command; /// Schedules a closure to be run just before the `exec` function is /// invoked. @@ -158,29 +156,17 @@ pub trait CommandExt: Sealed { #[stable(feature = "rust1", since = "1.0.0")] impl CommandExt for process::Command { - fn uid( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, - ) -> &mut process::Command { + fn uid(&mut self, id: UserId) -> &mut process::Command { self.as_inner_mut().uid(id); self } - fn gid( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] id: u32, - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] id: u16, - ) -> &mut process::Command { + fn gid(&mut self, id: GroupId) -> &mut process::Command { self.as_inner_mut().gid(id); self } - fn groups( - &mut self, - #[cfg(not(any(target_os = "vxworks", target_os = "espidf")))] groups: &[u32], - #[cfg(any(target_os = "vxworks", target_os = "espidf"))] groups: &[u16], - ) -> &mut process::Command { + fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command { self.as_inner_mut().groups(groups); self } |
