Skip to content

Commit 1687ea6

Browse files
author
Mark McCaskey
committed
Add lots of rustdocs and clean up one line of code
1 parent 287b425 commit 1687ea6

File tree

9 files changed

+52
-7
lines changed

9 files changed

+52
-7
lines changed

lib/runtime-c-api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Wasmer Runtime C API
2626

2727
Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully
28-
compatible with Emscripten, Rust and Go. [Learn
28+
compatible with WASI, Emscripten, Rust and Go. [Learn
2929
more](https://github.com/wasmerio/wasmer).
3030

3131
This crate exposes a C and a C++ API for the Wasmer runtime.

lib/runtime-core/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
# Wasmer Runtime Core
2626

2727
Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully
28-
compatible with Emscripten, Rust and Go. [Learn
28+
compatible with WASI, Emscripten, Rust and Go. [Learn
2929
more](https://github.com/wasmerio/wasmer).
3030

31-
This crate represents the core of the runtime.
31+
This crate represents the core of the runtime. Consider
32+
[`wasmer-runtime`] for higher level APIs.

lib/runtime-core/src/backend.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod sys {
2222
}
2323
pub use crate::sig_registry::SigRegistry;
2424

25+
/// Enum used to select which compiler should be used to generate code
2526
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
2627
pub enum Backend {
2728
Cranelift,
@@ -30,6 +31,7 @@ pub enum Backend {
3031
}
3132

3233
impl Backend {
34+
/// Get a list of the currently enabled (via feature flag) backends
3335
pub fn variants() -> &'static [&'static str] {
3436
&[
3537
#[cfg(feature = "backend-cranelift")]
@@ -41,7 +43,7 @@ impl Backend {
4143
]
4244
}
4345

44-
/// stable string representation of the backend
46+
/// Stable string representation of the backend
4547
/// can be used as part of a cache key, for example
4648
pub fn to_string(&self) -> &'static str {
4749
match self {
@@ -111,6 +113,7 @@ impl Default for MemoryBoundCheckMode {
111113
}
112114
}
113115

116+
/// Controls which experimental features will be enabled
114117
#[derive(Debug, Default)]
115118
pub struct Features {
116119
pub simd: bool,

lib/runtime-core/src/backing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ fn import_functions(
618618
}
619619
}
620620

621-
if link_errors.len() > 0 {
621+
if !link_errors.is_empty() {
622622
Err(link_errors)
623623
} else {
624624
Ok(functions.into_boxed_map())

lib/runtime/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ fn main() -> error::Result<()> {
9595
## Additional Notes
9696

9797
The `wasmer-runtime` crate is build to support multiple compiler
98-
backends. Currently, we support the [Cranelift] compiler with the
99-
[`wasmer-clif-backend`] crate by default.
98+
backends. We support have a [Cranelift] backend in the
99+
[`wasmer-clif-backend`] crate, a [LLVM] backend in the
100+
[`wasmer-llvm-backend`] crate, and the [Singlepass] backend in the
101+
[`wasmer-singlepass-backend`] crate. Currently, the Cranelift backend
102+
is the default.
100103

101104
You can specify the compiler you wish to use with the [`compile_with`] function.
102105

103106
[Cranelift]: https://github.com/CraneStation/cranelift
107+
[LLVM]: https://llvm.org
108+
[Singlepass]: https://github.com/wasmerio/wasmer/tree/master/lib/singlepass-backend
104109
[`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
105110
[`compile_with`]: https://docs.rs/wasmer-runtime/*/wasmer_runtime/fn.compile_with.html

lib/runtime/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ pub fn instantiate(wasm: &[u8], import_object: &ImportObject) -> error::Result<I
189189
}
190190

191191
/// Get a single instance of the default compiler to use.
192+
///
193+
/// The ouptput of this function can be controlled by the mutually
194+
/// exclusive `default-backend-llvm`, `default-backend-singlepass`,
195+
/// and `default-backend-cranelift` feature flags.
192196
pub fn default_compiler() -> impl Compiler {
193197
#[cfg(any(
194198
all(
@@ -219,6 +223,11 @@ pub fn default_compiler() -> impl Compiler {
219223
DefaultCompiler::new()
220224
}
221225

226+
/// Get the `Compiler` as a trait object for the given `Backend`.
227+
/// Returns `Option` because support for the `Compiler` may not be enabled by
228+
/// feature flags.
229+
///
230+
/// To get a list of the enabled backends as strings, call `Backend::variants()`
222231
pub fn compiler_for_backend(backend: Backend) -> Option<Box<dyn Compiler>> {
223232
match backend {
224233
#[cfg(feature = "cranelift")]

lib/wasi/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
1111
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]
1212

13+
//! Wasmer's WASI implementation
14+
//!
15+
//! Use `generate_import_object` to create an `ImportObject`. This `ImportObject`
16+
//! can be combined with a module to create an `Instance` which can execute WASI
17+
//! Wasm functions.
18+
//!
19+
//! See `state` for the experimental WASI FS API. Also see the
20+
//! [WASI plugin example](https://github.com/wasmerio/wasmer/blob/master/examples/plugin.rs)
21+
//! for an example of how to extend WASI using the WASI FS API.
22+
1323
#[cfg(target = "windows")]
1424
extern crate winapi;
1525

@@ -37,6 +47,7 @@ pub struct ExitCode {
3747
pub code: syscalls::types::__wasi_exitcode_t,
3848
}
3949

50+
/// Create a WasiImport object with `WasiState`
4051
pub fn generate_import_object(
4152
args: Vec<Vec<u8>>,
4253
envs: Vec<Vec<u8>>,

lib/wasi/src/state/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
//! WARNING: the API exposed here is unstable and very experimental. Certain things are not ready
22
//! yet and may be broken in patch releases. If you're using this and have any specific needs,
33
//! please let us know here https://github.com/wasmerio/wasmer/issues/583 or by filing an issue.
4+
//!
5+
//! Wasmer always has a virtual root directory located at `/` at which all pre-opened directories can
6+
//! be found. It's possible to traverse between preopened directories this way as well (for example
7+
//! `preopen-dir1/../preopen-dir2`).
8+
//!
9+
//! A preopened directory is a directory or directory + name combination passed into the
10+
//! `generate_import_object` function. These are directories that the caller has given
11+
//! the WASI module permission to access.
12+
//!
13+
//! You can implement `WasiFile` for your own types to get custom behavior and extend WASI, see the
14+
//! [WASI plugin example](https://github.com/wasmerio/wasmer/blob/master/examples/plugin.rs).
415
516
mod types;
617

@@ -44,6 +55,7 @@ pub struct InodeVal {
4455
pub kind: Kind,
4556
}
4657

58+
/// The core file-object data type
4759
#[derive(Debug, Serialize, Deserialize)]
4860
pub enum Kind {
4961
File {
@@ -998,6 +1010,7 @@ impl WasiFs {
9981010
}
9991011
}
10001012

1013+
/// Top level data type containing all the state that WASI can interact with
10011014
#[derive(Debug, Serialize, Deserialize)]
10021015
pub struct WasiState {
10031016
pub fs: WasiFs,

lib/wasi/src/state/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ fn host_file_bytes_available(_raw_fd: i32) -> Result<usize, WasiFsError> {
626626
unimplemented!("host_file_bytes_available not yet implemented for non-Unix-like targets. This probably means the program tried to use wasi::poll_oneoff")
627627
}
628628

629+
/// A wrapper type around Stdout
629630
#[derive(Debug, Serialize, Deserialize)]
630631
pub struct Stdout;
631632
impl Read for Stdout {
@@ -717,6 +718,7 @@ impl WasiFile for Stdout {
717718
}
718719
}
719720

721+
/// A wrapper type around Stderr
720722
#[derive(Debug, Serialize, Deserialize)]
721723
pub struct Stderr;
722724
impl Read for Stderr {
@@ -808,6 +810,7 @@ impl WasiFile for Stderr {
808810
}
809811
}
810812

813+
/// A wrapper type around Stdin
811814
#[derive(Debug, Serialize, Deserialize)]
812815
pub struct Stdin;
813816
impl Read for Stdin {

0 commit comments

Comments
 (0)