Skip to content
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

Add aarch64-unknown-switch-libnx target #74567

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e90d05f
Fix NixOS
leo60228 Mar 31, 2020
e07c671
Add aarch64-unknown-horizon-libnx target
leo60228 Mar 31, 2020
de95cc9
Fix crc feature
leo60228 Mar 31, 2020
9ebbfa4
horizon is (currently) no_std
leo60228 Mar 31, 2020
59daa56
Port libstd to horizon/libnx
leo60228 Apr 12, 2020
fbb156a
Don't use sysconf on horizon
leo60228 Apr 12, 2020
d9c1a13
Emulate pread/pwrite on newlib
leo60228 Apr 16, 2020
eef24b9
Fake readlink/symlink on Horizon
leo60228 Apr 16, 2020
c962990
Emulate realpath on Horizon
leo60228 Apr 16, 2020
fd20025
Emulate getppid on Horizon
leo60228 Apr 16, 2020
1ec9801
libunwind on Horizon
leo60228 Apr 17, 2020
39ee014
Implement current_exe
leo60228 Apr 18, 2020
7596eba
panic_unwind
leo60228 Apr 18, 2020
f98dd7d
Cleanup cfgs, rename to aarch64-unknown-switch-devkita64
leo60228 Jul 18, 2020
426735b
Switch to new unsupported_abis name
leo60228 Jul 18, 2020
480cb7f
Add disabled CI Docker image
leo60228 Jul 18, 2020
58a0750
Fix build
leo60228 Jul 18, 2020
eb2c219
Add Switch linker configuration
leo60228 Jul 18, 2020
bc9d603
Initialize romfs on startup
leo60228 Jul 19, 2020
39bfc20
Support LLVM TLS on Switch
leo60228 Jul 20, 2020
fc0bb2f
Handle Switch linker args properly (BROKEN)
leo60228 Jul 20, 2020
49b553c
Revert "Handle Switch linker args properly (BROKEN)"
leo60228 Jul 20, 2020
056c5e1
fmt
leo60228 Jul 20, 2020
6ea2b77
Move romfs initialization to sys::unix::init
leo60228 Jul 20, 2020
f14034e
Whitelist libc fork for tidy (TEMPORARY)
leo60228 Jul 20, 2020
1298bdf
Don't unnecessarily add library paths
leo60228 Jul 20, 2020
8d1bff2
Add short blurb about building in Docker
leo60228 Jul 20, 2020
b6d2585
Update libc
leo60228 Jul 20, 2020
e600298
Update tidy whitelist
leo60228 Jul 20, 2020
6b99f73
Revert "Support LLVM TLS on Switch"
leo60228 Jul 20, 2020
8ed3f5f
Revert "Emulate pread/pwrite on newlib"
leo60228 Jul 20, 2020
f0cdfa6
Make FileExt unimplemented!() on DevkitA64
leo60228 Jul 20, 2020
e409a27
Correct devkitA64 capitalization
leo60228 Jul 20, 2020
6bf6325
Rename to aarch64-unknown-switch-libnx
leo60228 Jul 21, 2020
0d36e7d
Use OsString::push instead of OsStr::to_str + format!
leo60228 Jul 21, 2020
4ba0fe7
Update libc
leo60228 Aug 11, 2020
9e4f631
Update libc
leo60228 Aug 11, 2020
ef03c4c
Update tidy
leo60228 Aug 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
[[package]]
name = "libc"
version = "0.2.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10"
source = "git+https://github.com/leo60228/libc.git?branch=bindgen-horizon#9f1d51f1276ac6967065b0fd7c3d814ec86dd391"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
# source code for this crate.
backtrace = { path = "library/backtrace" }

libc = { git = 'https://github.com/leo60228/libc.git', branch = 'bindgen-horizon' }

[patch."https://github.com/rust-lang/rust-clippy"]
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn main() {
|| target.contains("vxworks")
|| target.contains("wasm32")
|| target.contains("asmjs")
|| target.contains("libnx")
{
// These platforms don't have any special requirements.
} else {
Expand Down
312 changes: 312 additions & 0 deletions library/std/src/os/libnx/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sys_common::AsInner;

#[allow(deprecated)]
use crate::os::libnx::raw;

/// OS-specific extensions to [`fs::Metadata`].
///
/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
/// The contents of the returned [`stat`] are **not** consistent across
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
/// cross-Unix abstractions contained within the raw stat.
///
/// [`stat`]: ../../../../std/os/linux/raw/struct.stat.html
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// let stat = meta.as_raw_stat();
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext", since = "1.1.0")]
#[rustc_deprecated(since = "1.8.0", reason = "other methods of this trait are now preferred")]
#[allow(deprecated)]
fn as_raw_stat(&self) -> &raw::stat;

/// Returns the device ID on which this file resides.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_dev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
/// Returns the inode number.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ino());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ino(&self) -> u64;
/// Returns the file type and mode.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mode());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mode(&self) -> u32;
/// Returns the number of hard links to file.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_nlink());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_nlink(&self) -> u64;
/// Returns the user ID of the file owner.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_uid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_uid(&self) -> u32;
/// Returns the group ID of the file owner.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_gid());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_gid(&self) -> u32;
/// Returns the device ID that this file represents. Only relevant for special file.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_rdev());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_rdev(&self) -> u64;
/// Returns the size of the file (if it is a regular file or a symbolic link) in bytes.
///
/// The size of a symbolic link is the length of the pathname it contains,
/// without a terminating null byte.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_size());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_size(&self) -> u64;
/// Returns the last access time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_atime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_atime(&self) -> i64;
/// Returns the last modification time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_mtime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_mtime(&self) -> i64;
/// Returns the last status change time of the file, in seconds since Unix Epoch.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_ctime());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_ctime(&self) -> i64;
/// Returns the "preferred" blocksize for efficient filesystem I/O.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blksize());
/// Ok(())
/// }
/// ```
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_blksize(&self) -> u64;
/// Returns the number of blocks allocated to the file, 512-byte units.
///
/// # Examples
///
/// ```no_run
/// use std::fs;
/// use std::io;
/// use std::os::linux::fs::MetadataExt;
///
/// fn main() -> io::Result<()> {
/// let meta = fs::metadata("some_file")?;
/// println!("{}", meta.st_blocks());
/// Ok(())
/// }
/// ```
#[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 {
#[allow(deprecated)]
fn as_raw_stat(&self) -> &raw::stat {
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
}
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_atime as i64
}
fn st_mtime(&self) -> i64 {
self.as_inner().as_inner().st_mtime as i64
}
fn st_ctime(&self) -> i64 {
self.as_inner().as_inner().st_ctime 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
}
}
19 changes: 19 additions & 0 deletions library/std/src/os/libnx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! libnx-specific definitions

#![stable(feature = "raw_ext", since = "1.1.0")]

pub mod fs;
pub mod raw;

extern "C" {
fn romfsMountSelf(name: *const u8) -> u32;
}

/// This is necessary for getting debug info (needed by backtraces).
pub(crate) fn initialize_romfs() {
unsafe {
// This will return an error if there isn't a romfs, which can be safely ignored.
// SAFETY: We're passing a valid C string to romfsMountSelf.
let _ = romfsMountSelf(b"romfs\0" as *const _);
}
}
Loading