-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 build support for Cargo's build-std feature. #74033
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8c6c1dd
Automatically calculate std::env::consts::ARCH.
ehuss 432b4c1
Use cfg_if in libtest.
ehuss 9e58908
Use cfg_if in libpanic_abort.
ehuss 6e9a1de
Introduce restricted-std feature.
ehuss cee9f05
Tweak formatting.
ehuss 0eb293d
Use an allow-list of platforms that support std.
ehuss 3d44d3c
Simplify os_str_bytes cfg expression.
ehuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,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 | ||
} | ||
} |
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,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 | ||
} | ||
} |
File renamed without changes.
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,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; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.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.
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 #.