forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#95897 - AzureMarker:feature/horizon-std, r=na…
…gisa 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](rust-lang#88529 (comment)) 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: rust-lang#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
- Loading branch information
Showing
27 changed files
with
437 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#![stable(feature = "metadata_ext", since = "1.1.0")] | ||
|
||
use crate::fs::Metadata; | ||
use crate::sys_common::AsInner; | ||
|
||
/// OS-specific extensions to [`fs::Metadata`]. | ||
/// | ||
/// [`fs::Metadata`]: crate::fs::Metadata | ||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
pub trait MetadataExt { | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_dev(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_ino(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_mode(&self) -> u32; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_nlink(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_uid(&self) -> u32; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_gid(&self) -> u32; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_rdev(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_size(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_atime(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_atime_nsec(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_mtime(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_mtime_nsec(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_ctime(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_ctime_nsec(&self) -> i64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_blksize(&self) -> u64; | ||
#[stable(feature = "metadata_ext2", since = "1.8.0")] | ||
fn st_blocks(&self) -> u64; | ||
} | ||
|
||
#[stable(feature = "metadata_ext", since = "1.1.0")] | ||
impl MetadataExt for Metadata { | ||
fn st_dev(&self) -> u64 { | ||
self.as_inner().as_inner().st_dev as u64 | ||
} | ||
fn st_ino(&self) -> u64 { | ||
self.as_inner().as_inner().st_ino as u64 | ||
} | ||
fn st_mode(&self) -> u32 { | ||
self.as_inner().as_inner().st_mode as u32 | ||
} | ||
fn st_nlink(&self) -> u64 { | ||
self.as_inner().as_inner().st_nlink as u64 | ||
} | ||
fn st_uid(&self) -> u32 { | ||
self.as_inner().as_inner().st_uid as u32 | ||
} | ||
fn st_gid(&self) -> u32 { | ||
self.as_inner().as_inner().st_gid as u32 | ||
} | ||
fn st_rdev(&self) -> u64 { | ||
self.as_inner().as_inner().st_rdev as u64 | ||
} | ||
fn st_size(&self) -> u64 { | ||
self.as_inner().as_inner().st_size as u64 | ||
} | ||
fn st_atime(&self) -> i64 { | ||
self.as_inner().as_inner().st_atim.tv_sec | ||
} | ||
fn st_atime_nsec(&self) -> i64 { | ||
self.as_inner().as_inner().st_atim.tv_nsec as i64 | ||
} | ||
fn st_mtime(&self) -> i64 { | ||
self.as_inner().as_inner().st_mtim.tv_sec | ||
} | ||
fn st_mtime_nsec(&self) -> i64 { | ||
self.as_inner().as_inner().st_mtim.tv_nsec as i64 | ||
} | ||
fn st_ctime(&self) -> i64 { | ||
self.as_inner().as_inner().st_ctim.tv_sec | ||
} | ||
fn st_ctime_nsec(&self) -> i64 { | ||
self.as_inner().as_inner().st_ctim.tv_nsec as i64 | ||
} | ||
fn st_blksize(&self) -> u64 { | ||
self.as_inner().as_inner().st_blksize as u64 | ||
} | ||
fn st_blocks(&self) -> u64 { | ||
self.as_inner().as_inner().st_blocks as u64 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! Definitions for Horizon OS | ||
#![stable(feature = "raw_ext", since = "1.1.0")] | ||
|
||
pub mod fs; | ||
pub(crate) mod raw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//! Horizon OS raw type definitions | ||
#![stable(feature = "raw_ext", since = "1.1.0")] | ||
#![deprecated( | ||
since = "1.8.0", | ||
note = "these type aliases are no longer supported by \ | ||
the standard library, the `libc` crate on \ | ||
crates.io should be used instead for the correct \ | ||
definitions" | ||
)] | ||
#![allow(deprecated)] | ||
|
||
use crate::os::raw::c_long; | ||
use crate::os::unix::raw::{gid_t, uid_t}; | ||
|
||
#[stable(feature = "pthread_t", since = "1.8.0")] | ||
pub type pthread_t = libc::pthread_t; | ||
|
||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type blkcnt_t = libc::blkcnt_t; | ||
|
||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type blksize_t = libc::blksize_t; | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type dev_t = libc::dev_t; | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type ino_t = libc::ino_t; | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type mode_t = libc::mode_t; | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type nlink_t = libc::nlink_t; | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type off_t = libc::off_t; | ||
|
||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub type time_t = libc::time_t; | ||
|
||
#[repr(C)] | ||
#[derive(Clone)] | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub struct stat { | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_dev: dev_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_ino: ino_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_mode: mode_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_nlink: nlink_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_uid: uid_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_gid: gid_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_rdev: dev_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_size: off_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_atime: time_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_mtime: time_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_ctime: time_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_blksize: blksize_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_blocks: blkcnt_t, | ||
#[stable(feature = "raw_ext", since = "1.1.0")] | ||
pub st_spare4: [c_long; 2usize], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.