Skip to content

Commit d882bb5

Browse files
committed
Add shims for modules that we can't implement on CloudABI.
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.
1 parent 2074526 commit d882bb5

File tree

13 files changed

+980
-9
lines changed

13 files changed

+980
-9
lines changed

src/libstd/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -473,21 +473,16 @@ pub mod f64;
473473
pub mod thread;
474474
pub mod ascii;
475475
pub mod collections;
476-
#[cfg(not(target_os = "cloudabi"))]
477476
pub mod env;
478477
pub mod error;
479478
pub mod ffi;
480-
#[cfg(not(target_os = "cloudabi"))]
481479
pub mod fs;
482480
pub mod io;
483-
#[cfg(not(target_os = "cloudabi"))]
484481
pub mod net;
485482
pub mod num;
486483
pub mod os;
487484
pub mod panic;
488-
#[cfg(not(target_os = "cloudabi"))]
489485
pub mod path;
490-
#[cfg(not(target_os = "cloudabi"))]
491486
pub mod process;
492487
pub mod sync;
493488
pub mod time;

src/libstd/sys/cloudabi/args.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
pub use sys::cloudabi::shims::args::*;
12+
1113
#[allow(dead_code)]
1214
pub fn init(_: isize, _: *const *const u8) {}
1315

src/libstd/sys/cloudabi/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub mod time;
3434

3535
mod abi;
3636

37+
mod shims;
38+
pub use self::shims::*;
39+
3740
#[allow(dead_code)]
3841
pub fn init() {}
3942

src/libstd/sys/cloudabi/os.rs

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use ffi::CStr;
1212
use libc::{self, c_int};
1313
use str;
1414

15+
pub use sys::cloudabi::shims::os::*;
16+
1517
pub fn errno() -> i32 {
1618
extern "C" {
1719
#[thread_local]
@@ -29,3 +31,7 @@ pub fn error_string(errno: i32) -> String {
2931
.unwrap()
3032
.to_owned()
3133
}
34+
35+
pub fn exit(code: i32) -> ! {
36+
unsafe { libc::exit(code as c_int) }
37+
}

src/libstd/sys/cloudabi/shims/args.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use ffi::OsString;
12+
13+
pub struct Args(());
14+
15+
impl Args {
16+
pub fn inner_debug(&self) -> &[OsString] {
17+
&[]
18+
}
19+
}
20+
21+
impl Iterator for Args {
22+
type Item = OsString;
23+
fn next(&mut self) -> Option<OsString> {
24+
None
25+
}
26+
fn size_hint(&self) -> (usize, Option<usize>) {
27+
(0, Some(0))
28+
}
29+
}
30+
31+
impl ExactSizeIterator for Args {
32+
fn len(&self) -> usize {
33+
0
34+
}
35+
}
36+
37+
impl DoubleEndedIterator for Args {
38+
fn next_back(&mut self) -> Option<OsString> {
39+
None
40+
}
41+
}
42+
43+
pub fn args() -> Args {
44+
Args(())
45+
}

src/libstd/sys/cloudabi/shims/env.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub mod os {
12+
pub const FAMILY: &'static str = "cloudabi";
13+
pub const OS: &'static str = "cloudabi";
14+
pub const DLL_PREFIX: &'static str = "lib";
15+
pub const DLL_SUFFIX: &'static str = ".so";
16+
pub const DLL_EXTENSION: &'static str = "so";
17+
pub const EXE_SUFFIX: &'static str = "";
18+
pub const EXE_EXTENSION: &'static str = "";
19+
}

0 commit comments

Comments
 (0)