forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#74033 - ehuss:std-compile-all-platforms, r=…
…Mark-Simulacrum Add build support for Cargo's build-std feature. This makes some changes to the standard library to make it easier to use with Cargo's build-std feature. The primary goal is to make it so that Cargo and its users do not need to know which crates to build and which features to use for every platform. Conditional cfgs are adjusted so that there is usually a fall-through for unsupported platforms. Additionally, there is a "restricted-std" feature to mark `std` as unstable when used with build-std on no_std platforms. There is no intent to stabilize this feature for the foreseeable future. This borrows some of the implementation for wasm which already does what this needs. More code sharing can be done with some other platforms (there is a lot of duplication with cloudabi, hermit, and sgx), but I figure that can be done in a future PR. There are some small changes to stable behavior in this PR: - `std::env::consts::ARCH` on asmjs now reports "wasm32", to match its actual architecture. - Some of the wasm error messages for unsupported features report a slightly different error message so that the code can be reused. There should otherwise not be any changes to how std is built for distribution via bootstrap. This does not yet support all platforms when used with build-std. - It doesn't work with 16-bit targets (hashbrown does not support that). - It does not work with JSON spec targets. - In particular, all target triple snooping will need to be replaced with appropriate target option checking. - Switching to gimli (rust-lang#73441) will make cross-building *much* easier. - There are still a ton of issues on the Cargo side to resolve. A big one is panic strategy support. Future PRs are intended to address some of these issues.
- Loading branch information
Showing
42 changed files
with
437 additions
and
345 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
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.