Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasmer run-unstable #3650

Merged
merged 39 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
749e70d
Started adding a WcgiRunner implementation to the wasmer-wasi crate
Feb 27, 2023
1d26db1
Remove the (now redundant) wcgi-runner crate
Feb 28, 2023
db2a661
Miscellaneous refactoring and tidy-ups
Feb 28, 2023
414146c
Fix the C API crate
Mar 1, 2023
b0e182a
We can run a WCGI server locally!
Mar 1, 2023
e1c098c
Started implementing version 2 of "wasmer run"
Mar 6, 2023
06a4dae
Revert some unnecessary Cargo.toml formatting
Mar 6, 2023
6b624af
Fixed some broken links that caused "cargo doc" to fail
Mar 8, 2023
ab2f65c
Added integration tests for run2
Mar 8, 2023
dd42d32
Wired up bare WEBC commands
Mar 8, 2023
c91ec45
Run WASI executables directly
Mar 8, 2023
f21b07e
Wasmer run for wasm32-unknown-unknown
Mar 8, 2023
0efd37f
Refactored the run2 tests so we recompile the wasmer CLI as necessary
Mar 8, 2023
ad59f5a
Implemented URL downloading & caching
Mar 8, 2023
fa53a0d
Propagate environment variables to the WASI runner
Mar 8, 2023
21d1fcf
Added a test for WCGI with mounted directories
Mar 8, 2023
77e2f39
Logs should go to stderr
Mar 8, 2023
86134da
Wired up module caching
Mar 8, 2023
4d53bc0
Implemented the logic for "wasmer run ./some/directory/"
Mar 8, 2023
b07dd1b
Fixed wasmer-cache unit tests and lints
Mar 9, 2023
7a55304
Re-worked the logic for directory mapping
Mar 9, 2023
ac7f8e5
Make lint
Mar 9, 2023
fa85347
Add more useful logs to the WCGI server
Mar 9, 2023
ee3d263
Added the webc fs to the WASI runner
Mar 9, 2023
6716e14
Added some more tests to pinpoint why the volume filesystem isn't loa…
Mar 9, 2023
2cd7263
Added tests for constructing the WASI runner's fs
Mar 10, 2023
27bf71e
Moved MappedDirectory into the wasmer_wasi::runners module
Mar 10, 2023
14f27b9
Trying to use UnionFS
Mar 13, 2023
2ba16b3
Updated to use the OverlayFileSystem
Mar 16, 2023
e2a933c
Reading from a WebCFile never advanced its cursor
Mar 16, 2023
702972f
Reuse unioned_filesystem() for WCGI
Mar 16, 2023
9171c59
Use external knowledge when preopening dirs instead of traversing the fs
Mar 16, 2023
ab12f14
Ripped out the union fs stuff
Mar 17, 2023
897bc6d
Ran rustfmt
Mar 20, 2023
e80f845
Rename "run2" to "run-unstable"
Mar 20, 2023
5bd69c6
Create the checkout dir if necessary
Mar 20, 2023
a4c9909
bumped dependencies to force a cache miss
Mar 20, 2023
7b49f56
The wat2wasm runner test needs an argument
Mar 21, 2023
3c7f73b
Disable `wasmer run-unstable` integration tests on musl Linux
Mar 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
841 changes: 611 additions & 230 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
//! compilation-time and runtime performance, useful for development,
//! * [`wasmer-compiler-llvm`] provides a deeply optimized executable
//! code with the fastest runtime speed, ideal for production.
//!
//!
//! * **Headless mode** — Once a WebAssembly module has been compiled, it
//! is possible to serialize it in a file for example, and later execute
//! it with Wasmer with headless mode turned on. Headless Wasmer has no
//! compiler, which makes it more portable and faster to load. It's
//! ideal for constrainted environments.
//!
//!
//! * **Cross-compilation** — Most compilers support cross-compilation. It
//! means it possible to pre-compile a WebAssembly module targetting a
//! different architecture or platform and serialize it, to then run it
Expand Down
Binary file added lib/c-api/examples/assets/staticserver.webc
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/cache/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait Cache {
/// The deserialization error for the implementation
type DeserializeError: Error + Send + Sync;

/// Loads a module using the provided [`Store`] and [`Hash`].
/// Loads a module using the provided [`wasmer::Store`] and [`crate::Hash`].
///
/// # Safety
/// This function is unsafe as the cache store could be tampered with.
Expand All @@ -23,6 +23,6 @@ pub trait Cache {
key: Hash,
) -> Result<Module, Self::DeserializeError>;

/// Store a [`Module`] into the cache with the given [`Hash`].
/// Store a [`Module`] into the cache with the given [`crate::Hash`].
fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError>;
}
5 changes: 3 additions & 2 deletions lib/cache/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use wasmer::{AsEngineRef, DeserializeError, Module, SerializeError};
/// Ok(())
/// }
/// ```
#[derive(Debug, Clone)]
pub struct FileSystemCache {
path: PathBuf,
ext: Option<String>,
Expand Down Expand Up @@ -97,7 +98,7 @@ impl Cache for FileSystemCache {
key: Hash,
) -> Result<Module, Self::DeserializeError> {
let filename = if let Some(ref ext) = self.ext {
format!("{}.{}", key.to_string(), ext)
format!("{}.{}", key, ext)
} else {
key.to_string()
};
Expand All @@ -113,7 +114,7 @@ impl Cache for FileSystemCache {

fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> {
let filename = if let Some(ref ext) = self.ext {
format!("{}.{}", key.to_string(), ext)
format!("{}.{}", key, ext)
} else {
key.to_string()
};
Expand Down
34 changes: 21 additions & 13 deletions lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use crate::DeserializeError;
use std::str::FromStr;
use std::string::ToString;
use std::{
fmt::{self, Display, Formatter},
str::FromStr,
};

/// A hash used as a key when loading and storing modules in a
/// [`Cache`].
/// [`crate::Cache`].
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
// Hash is made up of a 32 byte array
pub struct Hash([u8; 32]);

impl Hash {
/// Creates a new instance from 32 raw bytes.
/// Does not perform any hashing. In order to create a hash from data,
/// use `Hash::generate`.
/// use [`Hash::generate()`].
pub fn new(bytes: [u8; 32]) -> Self {
Self(bytes)
}
Expand All @@ -21,17 +24,19 @@ impl Hash {
let hash = blake3::hash(bytes);
Self::new(hash.into())
}

pub(crate) fn to_array(self) -> [u8; 32] {
self.0
}
}

impl ToString for Hash {
/// Create the hexadecimal representation of the
impl Display for Hash {
/// Print the hexadecimal representation of the
/// stored hash.
fn to_string(&self) -> String {
hex::encode(&self.to_array())
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut buffer = [0_u8; 64];

hex::encode_to_slice(&self.0, &mut buffer)
.expect("Can never fail with a hard-coded buffer length");
let s = std::str::from_utf8(&buffer).map_err(|_| fmt::Error)?;

f.write_str(s)
}
}

Expand Down Expand Up @@ -62,13 +67,16 @@ mod tests {
use super::*;

#[test]
fn hash_to_array_works() {
fn hash_is_displayed_as_hex() {
let original = [
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD,
0xEE, 0xFF, 0x12, 0x65,
];
let hash = Hash::new(original);
assert_eq!(hash.to_array(), original);
assert_eq!(
hash.to_string(),
"aabbccddeeff1265aabbccddeeff1265aabbccddeeff1265aabbccddeeff1265"
);
}
}
47 changes: 21 additions & 26 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ required-features = ["headless"]

[dependencies]
wasmer = { version = "=3.2.0-alpha.1", path = "../api", default-features = false }
wasmer-compiler = { version = "=3.2.0-alpha.1", path = "../compiler", features = ["compiler", ] }
wasmer-compiler = { version = "=3.2.0-alpha.1", path = "../compiler", features = ["compiler"] }
wasmer-compiler-cranelift = { version = "=3.2.0-alpha.1", path = "../compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "=3.2.0-alpha.1", path = "../compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "=3.2.0-alpha.1", path = "../compiler-llvm", optional = true }
wasmer-emscripten = { version = "=3.2.0-alpha.1", path = "../emscripten", optional = true }
wasmer-emscripten = { version = "=3.2.0-alpha.1", path = "../emscripten" }
wasmer-vm = { version = "=3.2.0-alpha.1", path = "../vm" }
wasmer-wasix = { version = "0.1.0", path = "../wasi", optional = true }
wasmer-wasix = { version = "0.1.0", path = "../wasi", features = ["logging", "webc_runner", "webc_runner_rt_wcgi", "webc_runner_rt_wasi", "webc_runner_rt_emscripten", "host-fs"] }
wasmer-wasix-experimental-io-devices = { version = "0.1.0", path = "../wasi-experimental-io-devices", optional = true, features = ["link_external_libs"] }
wasmer-wast = { version = "=3.2.0-alpha.1", path = "../../tests/lib/wast", optional = true }
wasmer-cache = { version = "=3.2.0-alpha.1", path = "../cache", optional = true }
wasmer-cache = { version = "=3.2.0-alpha.1", path = "../cache", features = ["blake3-pure"] }
wasmer-types = { version = "=3.2.0-alpha.1", path = "../types", features = ["enable-serde"] }
wasmer-registry = { version = "=4.0.0", path = "../registry" }
wasmer-object = { version = "=3.2.0-alpha.1", path = "../object", optional = true }
Expand Down Expand Up @@ -68,8 +68,10 @@ regex = "1.6.0"
toml = "0.5.9"
url = "2.3.1"
libc = { version = "^0.2", default-features = false }
nuke-dir = { version = "0.1.0", optional = true }
webc = { version = "5.0.0-rc.5", optional = true }
webc = { version = "5.0.0-rc.5" }
# HACK(Michael-F-Bryan): Remove this once a new version of wapm-targz-to-pirita
# is published that doesn't have a public dependency on webc
webc_v4 = { version = "4", package = "webc" }
isatty = "0.1.9"
dialoguer = "0.10.2"
tldextract = "0.6.0"
Expand All @@ -88,11 +90,13 @@ pathdiff = "0.2.1"
sha2 = "0.10.6"
object = "0.30.0"
wasm-coredump-builder = { version = "0.1.11" }
tracing = { version = "0.1", optional = true }
tracing-subscriber = { version = "0.3", features = [ "env-filter", "fmt" ], optional = true }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = [ "env-filter", "fmt" ] }
clap-verbosity-flag = "1"
wapm-targz-to-pirita = "0.1.7"

[build-dependencies]
chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] }
chrono = { version = "^0.4", default-features = false, features = ["std", "clock"] }

[target.'cfg(target_os = "linux")'.dependencies]
unix_mode = "0.1.3"
Expand All @@ -110,24 +114,10 @@ default = [
"wasmer-artifact-create",
"static-artifact-create",
"webc_runner",
"tracing",
]
cache = ["wasmer-cache"]
cache-blake3-pure = ["wasmer-cache/blake3-pure"]
wast = ["wasmer-wast"]
wasi = ["wasmer-wasix", "host-net"]
host-net = [ "virtual-net/host-net" ]
emscripten = ["wasmer-emscripten"]
wat = ["wasmer/wat"]
webc_runner = [
"wasi",
"wasmer-wasix/webc_runner",
"wasmer-wasix/webc_runner_rt_wasi",
"wasmer-wasix/webc_runner_rt_wcgi",
"wasmer-wasix/webc_runner_rt_emscripten",
"nuke-dir",
"webc"
]
compiler = [
"wasmer-compiler/translator",
"wasmer-compiler/compiler",
Expand Down Expand Up @@ -155,7 +145,6 @@ static-artifact-load = ["compiler",
"wasmer/static-artifact-load",
"wasmer-compiler/static-artifact-load",
]

experimental-io-devices = [
"wasmer-wasix-experimental-io-devices",
"wasi"
Expand All @@ -172,11 +161,9 @@ llvm = [
"wasmer-compiler-llvm",
"compiler",
]
debug = ["tracing", "wasmer-wasix/logging"]
disable-all-logging = ["wasmer-wasix/disable-all-logging", "log/release_max_level_off"]
headless = []
headless-minimal = ["headless", "disable-all-logging", "wasi"]
tracing = [ "dep:tracing", "tracing-subscriber" ]

# Optional
enable-serde = [
Expand All @@ -186,6 +173,14 @@ enable-serde = [
"wasmer-wasix/enable-serde",
]

# Deprecated. These feature flags no longer protect anything.
cache = []
cache-blake3-pure = []
debug = []
wasi = []
emscripten = []
webc_runner = []

[target.'cfg(target_os = "windows")'.dependencies]
colored = "2.0.0"

Expand Down
13 changes: 10 additions & 3 deletions lib/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::commands::CreateExe;
#[cfg(feature = "wast")]
use crate::commands::Wast;
use crate::commands::{
Add, Cache, Config, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate, Whoami,
Add, Cache, Config, Init, Inspect, List, Login, Publish, Run, RunUnstable, SelfUpdate,
Validate, Whoami,
};
#[cfg(feature = "static-artifact-create")]
use crate::commands::{CreateObj, GenCHeader};
Expand Down Expand Up @@ -160,6 +161,9 @@ enum WasmerCLIOptions {

/// Add a WAPM package's bindings to your application.
Add(Add),

/// (unstable) Run a WebAssembly file or WEBC container.
RunUnstable(RunUnstable),
}

impl WasmerCLIOptions {
Expand Down Expand Up @@ -189,6 +193,7 @@ impl WasmerCLIOptions {
Self::Binfmt(binfmt) => binfmt.execute(),
Self::Whoami(whoami) => whoami.execute(),
Self::Add(install) => install.execute(),
Self::RunUnstable(run2) => run2.execute(),
}
}
}
Expand Down Expand Up @@ -241,8 +246,10 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> {
} else {
match command.unwrap_or(&"".to_string()).as_ref() {
"add" | "cache" | "compile" | "config" | "create-obj" | "create-exe" | "help"
| "gen-c-header" | "inspect" | "init" | "run" | "self-update" | "validate" | "wast"
| "binfmt" | "list" | "login" | "publish" => WasmerCLIOptions::parse(),
| "gen-c-header" | "inspect" | "init" | "run" | "run-unstable" | "self-update"
| "validate" | "wast" | "binfmt" | "list" | "login" | "publish" => {
WasmerCLIOptions::parse()
}
_ => {
WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| {
match e.kind() {
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod list;
mod login;
mod publish;
mod run;
mod run_unstable;
mod self_update;
mod validate;
#[cfg(feature = "wast")]
Expand All @@ -34,7 +35,7 @@ pub use create_exe::*;
pub use wast::*;
pub use {
add::*, cache::*, config::*, init::*, inspect::*, list::*, login::*, publish::*, run::*,
self_update::*, validate::*, whoami::*,
run_unstable::RunUnstable, self_update::*, validate::*, whoami::*,
};
#[cfg(feature = "static-artifact-create")]
pub use {create_obj::*, gen_c_header::*};
7 changes: 2 additions & 5 deletions lib/cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ fn lookup_bindings_for_package(

match all_bindings.iter().find(|b| b.language == *language) {
Some(b) => {
#[cfg(feature = "debug")]
{
let Bindings { url, generator, .. } = b;
log::debug!("Found {pkg} bindings generated by {generator} at {url}");
}
let Bindings { url, generator, .. } = b;
log::debug!("Found {pkg} bindings generated by {generator} at {url}");

Ok(b.clone())
}
Expand Down
2 changes: 0 additions & 2 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,6 @@ mod http_fetch {
.context("Could not lookup wasmer repository on Github.")?;

if response.status_code() != StatusCode::new(200) {
#[cfg(feature = "debug")]
log::warn!(
"Warning: Github API replied with non-200 status code: {}. Response: {}",
response.status_code(),
Expand Down Expand Up @@ -2134,7 +2133,6 @@ mod http_fetch {
let download_path = download_tempdir.path().join(&filename);

let mut file = std::fs::File::create(&download_path)?;
#[cfg(feature = "debug")]
log::debug!(
"Downloading {} to {}",
browser_download_url,
Expand Down
Loading