ya_runtime_wasi/lib.rs
1//! This crate allows you to embed [Yagna] WASI runtime inside your application.
2//!
3//! [Yagna]: https://github.com/golemfactory/yagna
4//!
5//! ## Quick start
6//!
7//! The usage is pretty straightforward. In your `Cargo.toml`, put `ya-runtime-wasi`
8//! as your dependency
9//!
10//! ```toml
11//! # Cargo.toml
12//! [dependencies]
13//! ya-runtime-wasi = "0.2"
14//! ```
15//!
16//! You can now embed the runtime in your app like so
17//!
18//! ```rust,no_run
19//! use std::path::Path;
20//! use ya_runtime_wasi::*;
21//!
22//! // In this example, we assume that `package.zip` contains a WASI binary
23//! // called `hello.wasm` which also our entrypoint into the package, and
24//! // maps input/output to `/workdir`
25//! let workspace = Path::new("workspace");
26//! let entrypoint = "hello";
27//! let package = Path::new("package.zip");
28//!
29//! // Deploy package
30//! deploy(&workspace, &package).unwrap();
31//!
32//! // Start the runtime
33//! start(&workspace).unwrap();
34//!
35//! // Execute the binary
36//! run(
37//! &workspace,
38//! &entrypoint,
39//! vec![
40//! "/workdir/input".into(),
41//! "/workdir/output".into(),
42//! ],
43//! ).unwrap();
44//! ```
45//!
46//! ## Obtaining handle to the deployed image
47//!
48//! A handle to the deployed image, i.e., the path to the image as well as a list of mapped
49//! container volumes, can be obtained using [`DeployFile::load`] function invoked
50//! after [`ya_runtime_wasi::deploy`] and [`ya_runtime_wasi::start`] were run.
51//!
52//! [`DeployFile::load`]: struct.DeployFile.html#method.load
53//! [`ya_runtime_wasi::deploy`]: fn.deploy.html
54//! [`ya_runtime_wasi::start`]: fn.start.html
55//!
56//! ## Examples
57//!
58//! A good example of using `ya-runtime-wasi` embedding API can be found in the [`gfaas`]
59//! crate.
60//!
61//! [`gfaas`]: https://github.com/golemfactory/gfaas
62
63#![deny(missing_docs)]
64
65mod deploy;
66mod entrypoint;
67mod manifest;
68mod wasmtime_unit;
69
70pub use deploy::{deploy, ContainerVolume, DeployFile};
71pub use entrypoint::{run, start};