Skip to content

Commit 67ae86b

Browse files
bors[bot]Mark McCaskey
and
Mark McCaskey
authored
Merge #841
841: Add lots of rustdocs and clean up one line of code r=MarkMcCaskey a=MarkMcCaskey - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <mark@wasmer.io>
2 parents 7313714 + dad43dd commit 67ae86b

File tree

10 files changed

+65
-9
lines changed

10 files changed

+65
-9
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Blocks of changes will separated by version increments.
66

77
## **[Unreleased]**
88

9+
- [#841](https://github.com/wasmerio/wasmer/pull/841) Slightly improve rustdoc documentation and small updates to outdated info in readme files
10+
- [#835](https://github.com/wasmerio/wasmer/pull/836) Update Cranelift fork version to `0.44.0`
911
- [#836](https://github.com/wasmerio/wasmer/pull/836) Update Cranelift fork version to `0.44.0`
1012
- [#839](https://github.com/wasmerio/wasmer/pull/839) Change supported version to stable Rust 1.37+
1113
- [#834](https://github.com/wasmerio/wasmer/pull/834) Fix panic when unwraping `wasmer` arguments

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

+5-2
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,8 +43,8 @@ impl Backend {
4143
]
4244
}
4345

44-
/// stable string representation of the backend
45-
/// can be used as part of a cache key, for example
46+
/// Stable string representation of the backend.
47+
/// It can be used as part of a cache key, for example.
4648
pub fn to_string(&self) -> &'static str {
4749
match self {
4850
Backend::Cranelift => "cranelift",
@@ -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

+10-1
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 output 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 requested `Compiler` may
228+
/// not be enabled by 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")]
@@ -241,5 +250,5 @@ pub fn compiler_for_backend(backend: Backend) -> Option<Box<dyn Compiler>> {
241250
}
242251
}
243252

244-
/// The current version of this crate
253+
/// The current version of this crate.
245254
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

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+
/// Creates 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

+19
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,8 @@ pub struct InodeVal {
4455
pub kind: Kind,
4556
}
4657

58+
/// The core of the filesystem abstraction. Includes directories,
59+
/// files, and symlinks.
4760
#[derive(Debug, Serialize, Deserialize)]
4861
pub enum Kind {
4962
File {
@@ -998,6 +1011,12 @@ impl WasiFs {
9981011
}
9991012
}
10001013

1014+
/// Top level data type containing all* the state with which WASI can
1015+
/// interact.
1016+
///
1017+
/// * The contents of files are not stored and may be modified by
1018+
/// other, concurrently running programs. Data such as the contents
1019+
/// of directories are lazily loaded.
10011020
#[derive(Debug, Serialize, Deserialize)]
10021021
pub struct WasiState {
10031022
pub fs: WasiFs,

lib/wasi/src/state/types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ 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 that implements `WasiFile` and
630+
/// `Serialize` + `Deserialize`.
629631
#[derive(Debug, Serialize, Deserialize)]
630632
pub struct Stdout;
631633
impl Read for Stdout {
@@ -717,6 +719,8 @@ impl WasiFile for Stdout {
717719
}
718720
}
719721

722+
/// A wrapper type around Stderr that implements `WasiFile` and
723+
/// `Serialize` + `Deserialize`.
720724
#[derive(Debug, Serialize, Deserialize)]
721725
pub struct Stderr;
722726
impl Read for Stderr {
@@ -808,6 +812,8 @@ impl WasiFile for Stderr {
808812
}
809813
}
810814

815+
/// A wrapper type around Stdin that implements `WasiFile` and
816+
/// `Serialize` + `Deserialize`.
811817
#[derive(Debug, Serialize, Deserialize)]
812818
pub struct Stdin;
813819
impl Read for Stdin {

0 commit comments

Comments
 (0)