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

Port libstd to "no operating system" target #37133

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/libpanic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ test = false

[dependencies]
core = { path = "../libcore" }

[target.'cfg(all(unix,not(target_os="none")))'.dependencies]
libc = { path = "../rustc/libc_shim" }
8 changes: 4 additions & 4 deletions src/libpanic_abort/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

#![panic_runtime]
#![feature(panic_runtime)]
#![cfg_attr(unix, feature(libc))]
#![cfg_attr(windows, feature(core_intrinsics))]
#![cfg_attr(all(unix,not(target_os="none")), feature(libc))]
#![cfg_attr(any(windows,target_os="none"), feature(core_intrinsics))]

// Rust's "try" function, but if we're aborting on panics we just call the
// function as there's nothing else we need to do here.
Expand All @@ -55,13 +55,13 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
return abort();

#[cfg(unix)]
#[cfg(all(unix,not(target_os="none")))]
unsafe fn abort() -> ! {
extern crate libc;
libc::abort();
}

#[cfg(windows)]
#[cfg(any(windows,target_os="none"))]
unsafe fn abort() -> ! {
core::intrinsics::abort();
}
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ crate-type = ["dylib", "rlib"]

[dependencies]
alloc = { path = "../liballoc" }
alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true }
alloc_system = { path = "../liballoc_system" }
panic_unwind = { path = "../libpanic_unwind" }
panic_abort = { path = "../libpanic_abort" }
collections = { path = "../libcollections" }
core = { path = "../libcore" }
libc = { path = "../rustc/libc_shim" }
rand = { path = "../librand" }
compiler_builtins = { path = "../libcompiler_builtins" }
rustc_unicode = { path = "../librustc_unicode" }

[target.'cfg(not(target_os="none"))'.dependencies]
libc = { path = "../rustc/libc_shim" }
alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true }
alloc_system = { path = "../liballoc_system" }
panic_unwind = { path = "../libpanic_unwind" }
unwind = { path = "../libunwind" }

[build-dependencies]
Expand Down
12 changes: 9 additions & 3 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ extern crate collections as core_collections;
#[allow(deprecated)] extern crate rand as core_rand;
extern crate alloc;
extern crate rustc_unicode;
extern crate libc;
#[cfg(not(target_os="none"))] extern crate libc;
#[cfg(target_os="none")]
mod libc {
pub use os::none::libc::*;
}

// We always need an unwinder currently for backtraces
extern crate unwind;
#[cfg(not(target_os="none"))] extern crate unwind;

#[cfg(stage0)]
extern crate alloc_system;
Expand Down Expand Up @@ -457,8 +461,10 @@ mod memchr;
#[macro_use]
#[path = "sys/common/mod.rs"] mod sys_common;

#[cfg(unix)]
#[cfg(all(unix,not(target_os="none")))]
#[path = "sys/unix/mod.rs"] mod sys;
#[cfg(target_os="none")]
#[path = "sys/none/mod.rs"] mod sys;
#[cfg(windows)]
#[path = "sys/windows/mod.rs"] mod sys;

Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ pub use sys::ext as windows;
#[cfg(target_os = "openbsd")] pub mod openbsd;
#[cfg(target_os = "solaris")] pub mod solaris;
#[cfg(target_os = "emscripten")] pub mod emscripten;
#[cfg(target_os = "none")] pub mod none;

pub mod raw;
119 changes: 119 additions & 0 deletions src/libstd/os/none/libc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
pub use os::raw::*;

pub type size_t = usize;
pub type ssize_t = isize;

// Process/File definitions

pub type mode_t = u32;
pub type pid_t = u32;
pub type gid_t = u32;
pub type uid_t = u32;

pub const S_IFBLK: mode_t = 0;
pub const S_IFCHR: mode_t = 0;
pub const S_IFIFO: mode_t = 0;
pub const S_IFSOCK: mode_t = 0;

// Threading

#[derive(Copy,Clone)]
pub struct pthread_t(());
pub struct pthread_attr_t(());

// Time definitions

pub type time_t = i64;

#[derive(Copy,Clone)]
pub struct timespec {
pub tv_sec: time_t,
pub tv_nsec: c_long,
}

pub const CLOCK_MONOTONIC: c_int = 0;
pub const CLOCK_REALTIME: c_int = 0;

// Networking definitions

pub type sa_family_t = u16;
pub type in_port_t = u16;

#[derive(Copy,Clone)]
pub struct in_addr {
pub s_addr: u32,
}

#[derive(Copy,Clone)]
pub struct sockaddr_in {
pub sin_family: sa_family_t,
pub sin_port: in_port_t,
pub sin_addr: in_addr,
pub sin_zero: [u8; 8],
}

#[derive(Copy,Clone)]
pub struct ip_mreq {
pub imr_multiaddr: in_addr,
pub imr_interface: in_addr,
}

#[derive(Copy,Clone)]
pub struct in6_addr {
pub s6_addr: [u8; 16],
}

#[derive(Copy,Clone)]
pub struct sockaddr_in6 {
pub sin6_family: sa_family_t,
pub sin6_port: in_port_t,
pub sin6_flowinfo: u32,
pub sin6_addr: in6_addr,
pub sin6_scope_id: u32,
}

#[derive(Copy,Clone)]
pub struct ipv6_mreq {
pub ipv6mr_multiaddr: in6_addr,
pub ipv6mr_interface: c_uint,
}

pub const AF_INET6: c_int = 0;
pub const AF_INET: c_int = 0;
pub const AF_UNIX: c_int = 0;
pub const IPPROTO_IPV6: c_int = 0;
pub const IPPROTO_IP: c_int = 0;
pub const IPV6_ADD_MEMBERSHIP: c_int = 0;
pub const IPV6_DROP_MEMBERSHIP: c_int = 0;
pub const IPV6_MULTICAST_LOOP: c_int = 0;
pub const IPV6_V6ONLY: c_int = 0;
pub const IP_ADD_MEMBERSHIP: c_int = 0;
pub const IP_DROP_MEMBERSHIP: c_int = 0;
pub const IP_MULTICAST_LOOP: c_int = 0;
pub const IP_MULTICAST_TTL: c_int = 0;
pub const IP_TTL: c_int = 0;
pub const SOCK_DGRAM: c_int = 0;
pub const SOCK_STREAM: c_int = 0;
pub const SOL_SOCKET: c_int = 0;
pub const SO_BROADCAST: c_int = 0;
pub const SO_RCVTIMEO: c_int = 0;
pub const SO_REUSEADDR: c_int = 0;
pub const SO_SNDTIMEO: c_int = 0;

pub struct sockaddr(());
#[derive(Clone)]
pub struct sockaddr_un(());
pub type socklen_t = u32;
pub struct sockaddr_storage(());

// C functions

pub unsafe fn strlen(s: *const c_char) -> size_t {
let mut i=0isize;
loop {
if *s.offset(i)==0 {
return i as usize
}
i+=1;
}
}
4 changes: 4 additions & 0 deletions src/libstd/os/none/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![stable(feature = "raw_ext", since = "1.1.0")]

#[unstable(reason = "not public", issue = "0", feature = "libc_shim")] pub mod libc;
pub mod raw;
16 changes: 16 additions & 0 deletions src/libstd/os/none/raw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![stable(feature = "raw_ext", since = "1.1.0")]
#![rustc_deprecated(since = "1.8.0",
reason = "these type aliases are no longer supported by \
the standard library, the `libc` crate on \
crates.io should be used instead for the correct \
definitions")]

#[stable(feature = "raw_ext", since = "1.1.0")] pub struct blkcnt_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct blksize_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct dev_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct ino_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct mode_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct nlink_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct off_t;
#[stable(feature = "pthread_t", since = "1.8.0")]pub use super::libc::pthread_t;
#[stable(feature = "raw_ext", since = "1.1.0")] pub struct time_t;
2 changes: 2 additions & 0 deletions src/libstd/sys/common/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![cfg(not(target_os = "none"))]

use io;
use io::ErrorKind;
use io::Read;
Expand Down
Loading