Skip to content

Commit

Permalink
Add shims for modules that we can't implement on CloudABI.
Browse files Browse the repository at this point in the history
As discussed in #47268, libstd isn't ready to have certain functionality
disabled yet. Follow wasm's approach of adding no-op modules for all of
the features that we can't implement.

I've placed all of those shims in a shims/ subdirectory, so we (the
CloudABI folks) can experiment with removing them more easily. It also
ensures that the code that does work doesn't get polluted with lots of
useless boilerplate code.
  • Loading branch information
EdSchouten committed Jan 11, 2018
1 parent 2074526 commit d882bb5
Show file tree
Hide file tree
Showing 13 changed files with 980 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/libstd/lib.rs
Expand Up @@ -473,21 +473,16 @@ pub mod f64;
pub mod thread;
pub mod ascii;
pub mod collections;
#[cfg(not(target_os = "cloudabi"))]
pub mod env;
pub mod error;
pub mod ffi;
#[cfg(not(target_os = "cloudabi"))]
pub mod fs;
pub mod io;
#[cfg(not(target_os = "cloudabi"))]
pub mod net;
pub mod num;
pub mod os;
pub mod panic;
#[cfg(not(target_os = "cloudabi"))]
pub mod path;
#[cfg(not(target_os = "cloudabi"))]
pub mod process;
pub mod sync;
pub mod time;
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/cloudabi/args.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub use sys::cloudabi::shims::args::*;

#[allow(dead_code)]
pub fn init(_: isize, _: *const *const u8) {}

Expand Down
3 changes: 3 additions & 0 deletions src/libstd/sys/cloudabi/mod.rs
Expand Up @@ -34,6 +34,9 @@ pub mod time;

mod abi;

mod shims;
pub use self::shims::*;

#[allow(dead_code)]
pub fn init() {}

Expand Down
6 changes: 6 additions & 0 deletions src/libstd/sys/cloudabi/os.rs
Expand Up @@ -12,6 +12,8 @@ use ffi::CStr;
use libc::{self, c_int};
use str;

pub use sys::cloudabi::shims::os::*;

pub fn errno() -> i32 {
extern "C" {
#[thread_local]
Expand All @@ -29,3 +31,7 @@ pub fn error_string(errno: i32) -> String {
.unwrap()
.to_owned()
}

pub fn exit(code: i32) -> ! {
unsafe { libc::exit(code as c_int) }
}
45 changes: 45 additions & 0 deletions src/libstd/sys/cloudabi/shims/args.rs
@@ -0,0 +1,45 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

use ffi::OsString;

pub struct 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
}
}

pub fn args() -> Args {
Args(())
}
19 changes: 19 additions & 0 deletions src/libstd/sys/cloudabi/shims/env.rs
@@ -0,0 +1,19 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

pub mod os {
pub const FAMILY: &'static str = "cloudabi";
pub const OS: &'static str = "cloudabi";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const DLL_EXTENSION: &'static str = "so";
pub const EXE_SUFFIX: &'static str = "";
pub const EXE_EXTENSION: &'static str = "";
}

0 comments on commit d882bb5

Please sign in to comment.