Skip to content

Commit

Permalink
Merge branch 'master' into asynchronous-io-with-fs-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
john-sharratt committed Jul 20, 2023
2 parents 8e07d72 + 4380bb3 commit 09ee543
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 184 deletions.
74 changes: 0 additions & 74 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ rust-version = "1.67"
version = "4.0.0"

[workspace.dependencies]
webc = { version = "5.0.4", default-features = false }
wapm-targz-to-pirita = "0.3.1"
webc = { version = "5.1.1", default-features = false, features = ["package"] }
wasmer-toml = "0.6.0"

[build-dependencies]
Expand Down Expand Up @@ -293,3 +292,4 @@ required-features = ["backend"]
name = "features"
path = "examples/features.rs"
required-features = ["cranelift"]

2 changes: 0 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ confidence-threshold = 0.8
exceptions = [
# Each entry is the crate and version constraint, and its specific allow
# list
{ name = "webc", allow = ["BUSL-1.1"] },
{ name = "wapm-targz-to-pirita", allow = ["BUSL-1.1"] },
]


Expand Down
31 changes: 30 additions & 1 deletion lib/c-api/src/wasm_c_api/unstable/module.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Unstable non-standard Wasmer-specific extensions to the Wasm C API.
use super::super::engine::wasm_engine_t;
use super::super::module::wasm_module_t;
use super::super::types::wasm_name_t;
use super::super::types::{wasm_byte_vec_t, wasm_name_t};
use std::ptr;
use std::str;
use wasmer_api::Module;

/// Unstable non-standard Wasmer-specific API to get the module's
/// name, otherwise `out->size` is set to `0` and `out->data` to
Expand Down Expand Up @@ -150,3 +152,30 @@ pub unsafe extern "C" fn wasmer_module_set_name(

module.inner.set_name(name)
}

/// A WebAssembly module contains stateless WebAssembly code that has
/// already been compiled and can be instantiated multiple times.
///
/// Creates a new WebAssembly Module using the provided engine,
/// respecting its configuration.
///
/// ## Security
///
/// Before the code is compiled, it will be validated using the engine
/// features.
///
/// # Example
///
/// See the module's documentation.
#[no_mangle]
pub unsafe extern "C" fn wasmer_module_new(
engine: Option<&mut wasm_engine_t>,
bytes: Option<&wasm_byte_vec_t>,
) -> Option<Box<wasm_module_t>> {
let engine: wasmer_api::Engine = engine?.inner.clone().into();
let bytes = bytes?;

let module = c_try!(Module::from_binary(&engine, bytes.as_slice()));

Some(Box::new(wasm_module_t { inner: module }))
}
2 changes: 0 additions & 2 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ virtual-net = { version = "0.3.0", path = "../virtual-net" }

# Wasmer-owned dependencies.
webc = { workspace = true }
wapm-targz-to-pirita = { workspace = true }
wasmer-deploy-cli = { version = "0.1.17", default-features = false }

# Third-party dependencies.

atty = "0.2"
is-terminal = "0.4.7"
colored = "2.0"
anyhow = "1.0"
Expand Down
52 changes: 5 additions & 47 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use once_cell::sync::Lazy;
use sha2::{Digest, Sha256};
use tempfile::NamedTempFile;
use url::Url;
use wapm_targz_to_pirita::{webc::v1::DirOrFile, FileMap, TransformManifestFunctions};
use wasmer::{
DeserializeError, Engine, Function, Imports, Instance, Module, Store, Type, TypedFunction,
Value,
Expand Down Expand Up @@ -556,15 +555,17 @@ enum ExecutableTarget {
impl ExecutableTarget {
/// Try to load a Wasmer package from a directory containing a `wasmer.toml`
/// file.
#[tracing::instrument(level = "debug", skip_all)]
fn from_dir(
dir: &Path,
runtime: &Arc<dyn Runtime + Send + Sync>,
pb: &ProgressBar,
) -> Result<Self, Error> {
pb.set_message(format!("Loading \"{}\" into memory", dir.display()));

let webc = construct_webc_in_memory(dir)?;
let container = Container::from_bytes(webc)?;
let manifest_path = dir.join("wasmer.toml");
let webc = webc::wasmer_package::Package::from_manifest(manifest_path)?;
let container = Container::from(webc);

pb.set_message("Resolving dependencies");
let inner_runtime = runtime.clone();
Expand All @@ -576,7 +577,7 @@ impl ExecutableTarget {
}

/// Try to load a file into something that can be used to run it.
#[tracing::instrument(skip_all)]
#[tracing::instrument(level = "debug", skip_all)]
fn from_file(
path: &Path,
runtime: &Arc<dyn Runtime + Send + Sync>,
Expand Down Expand Up @@ -622,49 +623,6 @@ impl ExecutableTarget {
}
}

#[tracing::instrument(level = "debug", skip_all)]
fn construct_webc_in_memory(dir: &Path) -> Result<Vec<u8>, Error> {
let mut files = BTreeMap::new();
load_files_from_disk(&mut files, dir, dir)?;

let wasmer_toml = DirOrFile::File("wasmer.toml".into());
if let Some(toml_data) = files.remove(&wasmer_toml) {
// HACK(Michael-F-Bryan): The version of wapm-targz-to-pirita we are
// using doesn't know we renamed "wapm.toml" to "wasmer.toml", so we
// manually patch things up if people have already migrated their
// projects.
files
.entry(DirOrFile::File("wapm.toml".into()))
.or_insert(toml_data);
}

let functions = TransformManifestFunctions::default();
let webc = wapm_targz_to_pirita::generate_webc_file(files, dir, &functions)?;

Ok(webc)
}

fn load_files_from_disk(files: &mut FileMap, dir: &Path, base: &Path) -> Result<(), Error> {
let entries = dir
.read_dir()
.with_context(|| format!("Unable to read the contents of \"{}\"", dir.display()))?;

for entry in entries {
let path = entry?.path();
let relative_path = path.strip_prefix(base)?.to_path_buf();

if path.is_dir() {
load_files_from_disk(files, &path, base)?;
files.insert(DirOrFile::Dir(relative_path), Vec::new());
} else if path.is_file() {
let data = std::fs::read(&path)
.with_context(|| format!("Unable to read \"{}\"", path.display()))?;
files.insert(DirOrFile::File(relative_path), data);
}
}
Ok(())
}

#[cfg(feature = "coredump")]
fn generate_coredump(err: &Error, source_name: String, coredump_path: &Path) -> Result<(), Error> {
let err: &wasmer::RuntimeError = match err.downcast_ref() {
Expand Down
Loading

0 comments on commit 09ee543

Please sign in to comment.