-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add build support for Cargo's build-std feature. #74033
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
Changes from all commits
8c6c1dd
432b4c1
9e58908
6e9a1de
cee9f05
0eb293d
3d44d3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::alloc::{GlobalAlloc, Layout, System}; | ||
|
||
#[stable(feature = "alloc_system_type", since = "1.28.0")] | ||
unsafe impl GlobalAlloc for System { | ||
#[inline] | ||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { | ||
0 as *mut u8 | ||
} | ||
|
||
#[inline] | ||
unsafe fn alloc_zeroed(&self, _layout: Layout) -> *mut u8 { | ||
0 as *mut u8 | ||
} | ||
|
||
#[inline] | ||
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} | ||
|
||
#[inline] | ||
unsafe fn realloc(&self, _ptr: *mut u8, _layout: Layout, _new_size: usize) -> *mut u8 { | ||
0 as *mut u8 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::ffi::OsString; | ||
|
||
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} | ||
pub unsafe fn cleanup() {} | ||
|
||
pub struct Args {} | ||
|
||
pub fn args() -> Args { | ||
Args {} | ||
} | ||
|
||
impl Args { | ||
pub fn inner_debug(&self) -> &[OsString] { | ||
&[] | ||
} | ||
} | ||
|
||
impl Iterator for Args { | ||
type Item = OsString; | ||
fn next(&mut self) -> Option<OsString> { | ||
None | ||
} | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
(0, Some(0)) | ||
} | ||
} | ||
|
||
impl ExactSizeIterator for Args { | ||
fn len(&self) -> usize { | ||
0 | ||
} | ||
} | ||
|
||
impl DoubleEndedIterator for Args { | ||
fn next_back(&mut self) -> Option<OsString> { | ||
None | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::io as std_io; | ||
|
||
pub mod memchr { | ||
pub use core::slice::memchr::{memchr, memrchr}; | ||
} | ||
|
||
pub use crate::sys_common::os_str_bytes as os_str; | ||
|
||
// This is not necessarily correct. May want to consider making it part of the | ||
// spec definition? | ||
use crate::os::raw::c_char; | ||
|
||
#[cfg(not(test))] | ||
pub fn init() {} | ||
|
||
pub fn unsupported<T>() -> std_io::Result<T> { | ||
Err(unsupported_err()) | ||
} | ||
|
||
pub fn unsupported_err() -> std_io::Error { | ||
std_io::Error::new(std_io::ErrorKind::Other, "operation not supported on this platform") | ||
} | ||
|
||
pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind { | ||
crate::io::ErrorKind::Other | ||
} | ||
|
||
pub fn abort_internal() -> ! { | ||
core::intrinsics::abort(); | ||
} | ||
|
||
pub fn hashmap_random_keys() -> (u64, u64) { | ||
(1, 2) | ||
} | ||
|
||
// This enum is used as the storage for a bunch of types which can't actually | ||
// exist. | ||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] | ||
pub enum Void {} | ||
|
||
pub unsafe fn strlen(mut s: *const c_char) -> usize { | ||
let mut n = 0; | ||
while *s != 0 { | ||
n += 1; | ||
s = s.offset(1); | ||
} | ||
return n; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod os { | ||
pub const FAMILY: &str = ""; | ||
pub const OS: &str = ""; | ||
pub const DLL_PREFIX: &str = ""; | ||
pub const DLL_SUFFIX: &str = ""; | ||
pub const DLL_EXTENSION: &str = ""; | ||
pub const EXE_SUFFIX: &str = ""; | ||
pub const EXE_EXTENSION: &str = ""; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pub mod alloc; | ||
pub mod args; | ||
pub mod cmath; | ||
pub mod condvar; | ||
pub mod env; | ||
pub mod fs; | ||
pub mod io; | ||
pub mod mutex; | ||
pub mod net; | ||
pub mod os; | ||
pub mod path; | ||
pub mod pipe; | ||
pub mod process; | ||
pub mod rwlock; | ||
pub mod stack_overflow; | ||
pub mod stdio; | ||
pub mod thread; | ||
#[cfg(target_thread_local)] | ||
pub mod thread_local_dtor; | ||
pub mod thread_local_key; | ||
pub mod time; | ||
|
||
mod common; | ||
pub use common::*; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use super::{unsupported, Void}; | ||
use crate::ffi::CStr; | ||
use crate::io; | ||
use crate::time::Duration; | ||
|
||
pub struct Thread(Void); | ||
|
||
pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; | ||
|
||
impl Thread { | ||
// unsafe: see thread::Builder::spawn_unchecked for safety requirements | ||
pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>) -> io::Result<Thread> { | ||
unsupported() | ||
} | ||
|
||
pub fn yield_now() { | ||
// do nothing | ||
} | ||
|
||
pub fn set_name(_name: &CStr) { | ||
// nope | ||
} | ||
|
||
pub fn sleep(_dur: Duration) { | ||
panic!("can't sleep"); | ||
} | ||
|
||
pub fn join(self) { | ||
match self.0 {} | ||
} | ||
} | ||
|
||
pub mod guard { | ||
pub type Guard = !; | ||
pub unsafe fn current() -> Option<Guard> { | ||
None | ||
} | ||
pub unsafe fn init() -> Option<Guard> { | ||
None | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,13 +51,9 @@ pub mod condvar; | |
pub mod fs; | ||
pub mod io; | ||
pub mod mutex; | ||
#[cfg(any(doc, // see `mod os`, docs are generated for multiple platforms | ||
unix, | ||
target_os = "redox", | ||
target_os = "cloudabi", | ||
target_os = "hermit", | ||
target_arch = "wasm32", | ||
all(target_vendor = "fortanix", target_env = "sgx")))] | ||
// `doc` is required because `sys/mod.rs` imports `unix/ext/mod.rs` on Windows | ||
// when generating documentation. | ||
#[cfg(any(doc, not(windows)))] | ||
pub mod os_str_bytes; | ||
pub mod poison; | ||
pub mod process; | ||
|
@@ -74,6 +70,7 @@ cfg_if::cfg_if! { | |
if #[cfg(any(target_os = "cloudabi", | ||
target_os = "l4re", | ||
target_os = "hermit", | ||
feature = "restricted-std", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sort of forget what's going on here, could you remind me what's up with this module? This may be a good candidate for movement to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I fully understand the question. There are some things defined in
If it is moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm ok so yeah if you're up for it I think the best way to deal with this is to use Otherwise the original intention of Nowadays I sort of feel like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind if I defer that to a separate PR? I'd actually like to do a pass of de-duplicating large sections of the sys module, and I think this would fit with that. In particular, there are large chunks of duplicate code in the cloudabi, hermit, sgx, and vxworks modules. It is not clear to me if there was a good reason for that, do you happen to know? Do you think there would be any objections to adding more (This is a practical thing, I was recently looking at making a small change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah that's ok, a separate PR should work fine 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you could, please cc me on the follow-up PR. |
||
all(target_arch = "wasm32", not(target_os = "emscripten")), | ||
all(target_vendor = "fortanix", target_env = "sgx")))] { | ||
pub use crate::sys::net; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ impl Mutex { | |
/// Also, until `init` is called, behavior is undefined if this | ||
/// mutex is ever used reentrantly, i.e., `raw_lock` or `try_lock` | ||
/// are called by the thread currently holding the lock. | ||
#[rustc_const_stable(feature = "const_sys_mutex_new", since = "1.0.0")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity where did this come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a bit convoluted (and I don't 100% understand the const stability infrastructure).
I believe when a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok no worries, I was a little curious but I'd believe that it falls out of something, and it's internal anyway so it doesn't matter too much. |
||
pub const fn new() -> Mutex { | ||
Mutex(imp::Mutex::new()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
//! Helper module which provides a function to test | ||
//! if stdout is a tty. | ||
#[cfg(any( | ||
target_os = "cloudabi", | ||
target_os = "hermit", | ||
all(target_arch = "wasm32", not(target_os = "emscripten")), | ||
all(target_vendor = "fortanix", target_env = "sgx") | ||
))] | ||
pub fn stdout_isatty() -> bool { | ||
// FIXME: Implement isatty on SGX | ||
false | ||
} | ||
#[cfg(unix)] | ||
pub fn stdout_isatty() -> bool { | ||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 } | ||
} | ||
#[cfg(windows)] | ||
pub fn stdout_isatty() -> bool { | ||
type DWORD = u32; | ||
type BOOL = i32; | ||
type HANDLE = *mut u8; | ||
type LPDWORD = *mut u32; | ||
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; | ||
extern "system" { | ||
fn GetStdHandle(which: DWORD) -> HANDLE; | ||
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL; | ||
} | ||
unsafe { | ||
let handle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
let mut out = 0; | ||
GetConsoleMode(handle, &mut out) != 0 | ||
cfg_if::cfg_if! { | ||
if #[cfg(unix)] { | ||
pub fn stdout_isatty() -> bool { | ||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 } | ||
} | ||
} else if #[cfg(windows)] { | ||
pub fn stdout_isatty() -> bool { | ||
type DWORD = u32; | ||
type BOOL = i32; | ||
type HANDLE = *mut u8; | ||
type LPDWORD = *mut u32; | ||
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD; | ||
extern "system" { | ||
fn GetStdHandle(which: DWORD) -> HANDLE; | ||
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL; | ||
} | ||
unsafe { | ||
let handle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
let mut out = 0; | ||
GetConsoleMode(handle, &mut out) != 0 | ||
} | ||
} | ||
} else { | ||
// FIXME: Implement isatty on SGX | ||
pub fn stdout_isatty() -> bool { | ||
false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#![feature(restricted_std)] | ||
pub use std::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_family = "unix"
FWIW I think is the same asunix
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is the same. I have been waffling on which style I like better, and I think I ended up being really inconsistent. I think part of the issue is that I've run into a number of users being confused what
cfg(unix)
means, which makes me feel it is better to be explicit. Butunix
andwindows
is conveniently short.One thing that surprises me is that it is possible to have
family="unix"
andos="none"
at the same time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh either way is fine by me, I figured
unix
is a bit more idiomatic though. Forunix, target_os = "none"
being true that seems like it's either a mistake or something that hasn't been reviewed since it was addedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x86_64-linux-kernel
is the only one. I'm not sure what values would make sense for that, since it is unusual.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the Linux kernel even have an UNIX API inside of itself? That doesn't sound right but maybe I just haven't seen it before.
(To be clear, I'm thinking that
family="unix"
is as valid for inside an OS kernel asos="thatosname"
- ifos="none"
is used then surely there should also not be a family? Maybe we should enforce that the family is derived from the OS name and therefore means "OS family")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #74247 for further discussion.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it was related or coincidental but I just saw #74257 being open.Oh, highly relevant, just likely accidentally pointing to the wrong #.