Compare commits
6 Commits
arg-parsin
...
main
Author | SHA1 | Date | |
---|---|---|---|
aab129c969 | |||
2a6da1a7f3 | |||
3cb89896eb | |||
42bb7655ba | |||
ca16d4aa80 | |||
5b35be7425 |
40
Cargo.lock
generated
40
Cargo.lock
generated
@ -20,7 +20,7 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"shlex",
|
"shlex",
|
||||||
"syn 1.0.109",
|
"syn",
|
||||||
"which",
|
"which",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -86,6 +86,12 @@ version = "0.2.140"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc_alloc"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a090348b66d90d8507e30f0d2bd88e5a5c454bd1733fc6d617cbc3471bf69ea"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.7.4"
|
version = "0.7.4"
|
||||||
@ -186,13 +192,11 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spd"
|
name = "spd"
|
||||||
version = "0.0.1"
|
version = "0.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"libc",
|
"libc",
|
||||||
"quote",
|
"libc_alloc",
|
||||||
"syn 2.0.8",
|
|
||||||
"tabwriter",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -206,38 +210,12 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tabwriter"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "36205cfc997faadcc4b0b87aaef3fbedafe20d38d4959a7ca6ff803564051111"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-width",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.8"
|
version = "1.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-width"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "which"
|
name = "which"
|
||||||
version = "4.4.0"
|
version = "4.4.0"
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "spd"
|
name = "spd"
|
||||||
version = "0.0.1"
|
version = "0.0.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "LGPL-3.0-or-later"
|
license = "LGPL-3.0-or-later"
|
||||||
authors = [
|
authors = [
|
||||||
"Emma Tebibyte <emma@tebibyte.media>",
|
"Emma Tebibyte <emma@tebibyte.media>",
|
||||||
"Douman <douman@gmx.se>",
|
"Douman <douman@gmx.se>",
|
||||||
|
"Matt Mastracci <matthew@mastracci.com>",
|
||||||
]
|
]
|
||||||
description ="Minimal standard library replacement containing essential functionality."
|
description ="Minimal standard library replacement containing essential functionality."
|
||||||
repository = "https://git.tebibyte.media/emma/spd"
|
repository = "https://git.tebibyte.media/emma/spd"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.140"
|
libc = "0.2.140"
|
||||||
quote = "1.0.26"
|
libc_alloc = "1.0.4"
|
||||||
syn = { version = "2.0.8", features = [ "extra-traits" ] }
|
|
||||||
tabwriter = "1.2.1"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "0.64.0"
|
bindgen = "0.64.0"
|
||||||
|
@ -68,7 +68,7 @@ impl Args {
|
|||||||
///On error returns pair: `(string index, Utf8Error)`
|
///On error returns pair: `(string index, Utf8Error)`
|
||||||
///
|
///
|
||||||
///The function is safe as long as you pass C style main function arguments.
|
///The function is safe as long as you pass C style main function arguments.
|
||||||
pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result<Self, (usize, core::str::Utf8Error)> {
|
pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result<Self, (usize, crate::str::Utf8Error)> {
|
||||||
assert!(argc > 0);
|
assert!(argc > 0);
|
||||||
assert!(!argv.is_null());
|
assert!(!argv.is_null());
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ impl Args {
|
|||||||
///Returns slice of raw C strings
|
///Returns slice of raw C strings
|
||||||
pub fn as_slice(&self) -> &[*const u8] {
|
pub fn as_slice(&self) -> &[*const u8] {
|
||||||
unsafe {
|
unsafe {
|
||||||
core::slice::from_raw_parts(self.argv, self.argc)
|
crate::slice::from_raw_parts(self.argv, self.argc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
use args::*;
|
pub use args::*;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[cold]
|
#[cold]
|
||||||
@ -79,10 +79,10 @@ unsafe fn invalid_cli_args_error() -> libc::c_int {
|
|||||||
///Converts C string to Rust's, verifying it is UTF-8
|
///Converts C string to Rust's, verifying it is UTF-8
|
||||||
///
|
///
|
||||||
///It is UB to pass non-C string as it requires \0
|
///It is UB to pass non-C string as it requires \0
|
||||||
pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::Utf8Error> {
|
pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, crate::str::Utf8Error> {
|
||||||
let len = libc::strlen(ptr as *const i8);
|
let len = libc::strlen(ptr as *const i8);
|
||||||
let parts = core::slice::from_raw_parts(ptr, len);
|
let parts = crate::slice::from_raw_parts(ptr, len);
|
||||||
core::str::from_utf8(parts)
|
crate::str::from_utf8(parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Converts C string to Rust's one assuming it is UTF-8
|
///Converts C string to Rust's one assuming it is UTF-8
|
||||||
@ -90,8 +90,8 @@ pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::U
|
|||||||
///It is UB to pass non-C string as it requires \0
|
///It is UB to pass non-C string as it requires \0
|
||||||
pub unsafe fn c_str_to_rust_unchecked(ptr: *const u8) -> &'static str {
|
pub unsafe fn c_str_to_rust_unchecked(ptr: *const u8) -> &'static str {
|
||||||
let len = libc::strlen(ptr as *const i8);
|
let len = libc::strlen(ptr as *const i8);
|
||||||
let parts = core::slice::from_raw_parts(ptr, len);
|
let parts = crate::slice::from_raw_parts(ptr, len);
|
||||||
core::str::from_utf8_unchecked(parts)
|
crate::str::from_utf8_unchecked(parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
|
25
src/lib.rs
25
src/lib.rs
@ -46,11 +46,23 @@
|
|||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
extern crate core;
|
||||||
|
|
||||||
pub mod entry;
|
pub mod entry;
|
||||||
// pub mod env;
|
|
||||||
mod macros;
|
mod macros;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
|
|
||||||
|
pub use alloc::{
|
||||||
|
borrow::*,
|
||||||
|
boxed::*,
|
||||||
|
collections::*,
|
||||||
|
rc::*,
|
||||||
|
string::*,
|
||||||
|
vec::*,
|
||||||
|
};
|
||||||
|
pub use core::*;
|
||||||
|
|
||||||
pub use macros::*;
|
pub use macros::*;
|
||||||
|
|
||||||
pub use libc_dbg as dbg;
|
pub use libc_dbg as dbg;
|
||||||
@ -61,4 +73,15 @@ pub use libc_print as print;
|
|||||||
pub use libc_println as println;
|
pub use libc_println as println;
|
||||||
pub use libc_writeln as writeln;
|
pub use libc_writeln as writeln;
|
||||||
|
|
||||||
|
pub use libc_alloc::LibcAlloc;
|
||||||
|
|
||||||
pub const SOURCE: &str = "https://git.tebibyte.media/emma/spd.git";
|
pub const SOURCE: &str = "https://git.tebibyte.media/emma/spd.git";
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
pub static ALLOCATOR: LibcAlloc = LibcAlloc;
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
pub fn panic(info: &panic::PanicInfo) -> ! {
|
||||||
|
eprintln!("{:?}", info);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
@ -85,13 +85,10 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![warn(unsafe_op_in_unsafe_fn)]
|
#![warn(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
use core::{convert::TryFrom, file, line, stringify};
|
|
||||||
|
|
||||||
/// This forces a "C" library linkage
|
/// This forces a "C" library linkage
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
#[link(name = "c")]
|
#[link(name = "c")]
|
||||||
@ -111,9 +108,9 @@ pub const __LIBC_STDERR: i32 = 2;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct __LibCWriter(i32);
|
pub struct __LibCWriter(i32);
|
||||||
|
|
||||||
impl core::fmt::Write for __LibCWriter {
|
impl crate::fmt::Write for __LibCWriter {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
fn write_str(&mut self, s: &str) -> crate::fmt::Result {
|
||||||
__libc_println(self.0, s)
|
__libc_println(self.0, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,24 +122,24 @@ impl __LibCWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn write_fmt(&mut self, args: core::fmt::Arguments) -> core::fmt::Result {
|
pub fn write_fmt(&mut self, args: crate::fmt::Arguments) -> crate::fmt::Result {
|
||||||
core::fmt::Write::write_fmt(self, args)
|
crate::fmt::Write::write_fmt(self, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
pub fn write_str(&mut self, s: &str) -> crate::fmt::Result {
|
||||||
__libc_println(self.0, s)
|
__libc_println(self.0, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn write_nl(&mut self) -> core::fmt::Result {
|
pub fn write_nl(&mut self) -> crate::fmt::Result {
|
||||||
__libc_println(self.0, __LIBC_NEWLINE)
|
__libc_println(self.0, __LIBC_NEWLINE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn __libc_println(handle: i32, msg: &str) -> core::fmt::Result {
|
pub fn __libc_println(handle: i32, msg: &str) -> crate::fmt::Result {
|
||||||
let msg = msg.as_bytes();
|
let msg = msg.as_bytes();
|
||||||
|
|
||||||
let mut written = 0;
|
let mut written = 0;
|
||||||
@ -162,7 +159,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option<usize> {
|
|||||||
usize::try_from(unsafe {
|
usize::try_from(unsafe {
|
||||||
libc::write(
|
libc::write(
|
||||||
handle,
|
handle,
|
||||||
bytes.as_ptr().cast::<core::ffi::c_void>(),
|
bytes.as_ptr().cast::<crate::ffi::c_void>(),
|
||||||
bytes.len(),
|
bytes.len(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -174,7 +171,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option<usize> {
|
|||||||
usize::try_from(unsafe {
|
usize::try_from(unsafe {
|
||||||
libc::write(
|
libc::write(
|
||||||
handle,
|
handle,
|
||||||
bytes.as_ptr().cast::<core::ffi::c_void>(),
|
bytes.as_ptr().cast::<crate::ffi::c_void>(),
|
||||||
libc::c_uint::try_from(bytes.len()).unwrap_or(libc::c_uint::MAX),
|
libc::c_uint::try_from(bytes.len()).unwrap_or(libc::c_uint::MAX),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
|
||||||
extern crate core;
|
|
||||||
|
|
||||||
pub fn exit(code: u32) -> ! {
|
pub fn exit(code: u32) -> ! {
|
||||||
unsafe { libc::exit(code as i32 as libc::c_int); }
|
unsafe { libc::exit(code as i32 as libc::c_int); }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user