Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/remote-code…
Browse files Browse the repository at this point in the history
…-load
  • Loading branch information
losfair committed May 15, 2019
2 parents 6df4e40 + 6b43a6a commit a1a58d4
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 68 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#442](https://github.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir
- [#440](https://github.com/wasmerio/wasmer/pull/440) Fix type mismatch between `wasmer_instance_call` and `wasmer_export_func_*_arity` functions in the runtime C API.
- [#269](https://github.com/wasmerio/wasmer/pull/269) Add better runtime docs
- [#432](https://github.com/wasmerio/wasmer/pull/432) Fix returned value of `wasmer_last_error_message` in the runtime C API
- [#429](https://github.com/wasmerio/wasmer/pull/429) Get wasi::path_filestat_get working for some programs; misc. minor WASI FS improvements
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -49,11 +49,13 @@ test:
# cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs)
cargo test --manifest-path lib/spectests/Cargo.toml --features clif
cargo test --manifest-path lib/spectests/Cargo.toml --features llvm
cargo test --manifest-path lib/runtime/Cargo.toml --features llvm
cargo build -p wasmer-runtime-c-api
cargo test -p wasmer-runtime-c-api -- --nocapture

test-singlepass:
cargo test --manifest-path lib/spectests/Cargo.toml --features singlepass
cargo test --manifest-path lib/runtime/Cargo.toml --features singlepass

test-emscripten-llvm:
cargo test --manifest-path lib/emscripten/Cargo.toml --features llvm -- --test-threads=1 $(runargs)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@

## Introduction

[Wasmer](https://wasmer.io/) is a standalone JIT WebAssembly runtime, aiming to be fully compatible with [WASI](https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/) and [Emscripten](https://emscripten.org/).
[Wasmer](https://wasmer.io/) is a standalone JIT WebAssembly runtime, aiming to be fully compatible with [WASI](https://github.com/WebAssembly/WASI) and [Emscripten](https://emscripten.org/).

Install Wasmer with:

Expand Down
4 changes: 2 additions & 2 deletions lib/runtime-c-api/src/export.rs
Expand Up @@ -222,7 +222,7 @@ pub unsafe extern "C" fn wasmer_export_func_params_arity(
pub unsafe extern "C" fn wasmer_export_func_params(
func: *const wasmer_export_func_t,
params: *mut wasmer_value_tag,
params_len: c_int,
params_len: uint32_t,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
Expand Down Expand Up @@ -252,7 +252,7 @@ pub unsafe extern "C" fn wasmer_export_func_params(
pub unsafe extern "C" fn wasmer_export_func_returns(
func: *const wasmer_export_func_t,
returns: *mut wasmer_value_tag,
returns_len: c_int,
returns_len: uint32_t,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime-c-api/src/instance.rs
Expand Up @@ -125,9 +125,9 @@ pub unsafe extern "C" fn wasmer_instance_call(
instance: *mut wasmer_instance_t,
name: *const c_char,
params: *const wasmer_value_t,
params_len: c_int,
params_len: uint32_t,
results: *mut wasmer_value_t,
results_len: c_int,
results_len: uint32_t,
) -> wasmer_result_t {
if instance.is_null() {
update_last_error(CApiError {
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/src/module.rs
Expand Up @@ -247,7 +247,7 @@ pub unsafe extern "C" fn wasmer_module_deserialize(
let serialized_module: &[u8] = &*(serialized_module as *const &[u8]);

match Artifact::deserialize(serialized_module) {
Ok(artifact) => match load_cache_with(artifact, default_compiler()) {
Ok(artifact) => match load_cache_with(artifact, &default_compiler()) {
Ok(deserialized_module) => {
*module = Box::into_raw(Box::new(deserialized_module)) as _;
wasmer_result_t::WASMER_OK
Expand Down
3 changes: 1 addition & 2 deletions lib/runtime-c-api/tests/test-exports.c
Expand Up @@ -60,7 +60,6 @@ int main()
assert(returns_sig[0] == WASM_I32);
free(returns_sig);


wasmer_value_t param_one;
param_one.tag = WASM_I32;
param_one.value.I32 = 7;
Expand All @@ -71,7 +70,7 @@ int main()
wasmer_value_t result_one;
wasmer_value_t results[] = {result_one};

wasmer_result_t call_result = wasmer_export_func_call(func, params, 2, results, 1);
wasmer_result_t call_result = wasmer_export_func_call(func, params, params_arity, results, returns_arity);
printf("Call result: %d\n", call_result);
printf("Result: %d\n", results[0].value.I32);
assert(results[0].value.I32 == 15);
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime-c-api/wasmer.h
Expand Up @@ -197,7 +197,7 @@ wasmer_result_t wasmer_export_func_call(const wasmer_export_func_t *func,
*/
wasmer_result_t wasmer_export_func_params(const wasmer_export_func_t *func,
wasmer_value_tag *params,
int params_len);
uint32_t params_len);

/**
* Sets the result parameter to the arity of the params of the wasmer_export_func_t
Expand All @@ -215,7 +215,7 @@ wasmer_result_t wasmer_export_func_params_arity(const wasmer_export_func_t *func
*/
wasmer_result_t wasmer_export_func_returns(const wasmer_export_func_t *func,
wasmer_value_tag *returns,
int returns_len);
uint32_t returns_len);

/**
* Sets the result parameter to the arity of the returns of the wasmer_export_func_t
Expand Down Expand Up @@ -390,9 +390,9 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun
wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance,
const char *name,
const wasmer_value_t *params,
int params_len,
uint32_t params_len,
wasmer_value_t *results,
int results_len);
uint32_t results_len);

/**
* Gets the `data` field within the context.
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime-c-api/wasmer.hh
Expand Up @@ -178,7 +178,7 @@ wasmer_result_t wasmer_export_func_call(const wasmer_export_func_t *func,
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_params(const wasmer_export_func_t *func,
wasmer_value_tag *params,
int params_len);
uint32_t params_len);

/// Sets the result parameter to the arity of the params of the wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
Expand All @@ -192,7 +192,7 @@ wasmer_result_t wasmer_export_func_params_arity(const wasmer_export_func_t *func
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_export_func_returns(const wasmer_export_func_t *func,
wasmer_value_tag *returns,
int returns_len);
uint32_t returns_len);

/// Sets the result parameter to the arity of the returns of the wasmer_export_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
Expand Down Expand Up @@ -313,9 +313,9 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun
wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance,
const char *name,
const wasmer_value_t *params,
int params_len,
uint32_t params_len,
wasmer_value_t *results,
int results_len);
uint32_t results_len);

/// Gets the `data` field within the context.
void *wasmer_instance_context_data_get(const wasmer_instance_context_t *ctx);
Expand Down
4 changes: 3 additions & 1 deletion lib/runtime/src/cache.rs
Expand Up @@ -94,7 +94,9 @@ impl Cache for FileSystemCache {
let mmap = unsafe { Mmap::map(&file)? };

let serialized_cache = Artifact::deserialize(&mmap[..])?;
unsafe { wasmer_runtime_core::load_cache_with(serialized_cache, super::default_compiler()) }
unsafe {
wasmer_runtime_core::load_cache_with(serialized_cache, &super::default_compiler())
}
}

fn store(&mut self, key: WasmHash, module: Module) -> Result<(), CacheError> {
Expand Down
14 changes: 4 additions & 10 deletions lib/runtime/src/lib.rs
Expand Up @@ -131,7 +131,7 @@ use wasmer_runtime_core::backend::{Compiler, CompilerConfig};
/// # Errors:
/// If the operation fails, the function returns `Err(error::CompileError::...)`.
pub fn compile(wasm: &[u8]) -> error::CompileResult<Module> {
wasmer_runtime_core::compile_with(&wasm[..], default_compiler())
wasmer_runtime_core::compile_with(&wasm[..], &default_compiler())
}

/// The same as `compile` but takes a `CompilerConfig` for the purpose of
Expand All @@ -140,7 +140,7 @@ pub fn compile_with_config(
wasm: &[u8],
compiler_config: CompilerConfig,
) -> error::CompileResult<Module> {
wasmer_runtime_core::compile_with_config(&wasm[..], default_compiler(), compiler_config)
wasmer_runtime_core::compile_with_config(&wasm[..], &default_compiler(), compiler_config)
}

/// The same as `compile_with_config` but takes a `Compiler` for the purpose of
Expand Down Expand Up @@ -177,9 +177,7 @@ pub fn instantiate(wasm: &[u8], import_object: &ImportObject) -> error::Result<I
}

/// Get a single instance of the default compiler to use.
pub fn default_compiler() -> &'static dyn Compiler {
use lazy_static::lazy_static;

pub fn default_compiler() -> impl Compiler {
#[cfg(feature = "llvm")]
use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler;

Expand All @@ -189,11 +187,7 @@ pub fn default_compiler() -> &'static dyn Compiler {
#[cfg(not(any(feature = "llvm", feature = "singlepass")))]
use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler;

lazy_static! {
static ref DEFAULT_COMPILER: DefaultCompiler = { DefaultCompiler::new() };
}

&*DEFAULT_COMPILER as &dyn Compiler
DefaultCompiler::new()
}

/// The current version of this crate
Expand Down
31 changes: 30 additions & 1 deletion lib/wasi/src/state.rs
Expand Up @@ -139,8 +139,10 @@ pub enum Kind {
handle: WasiFile,
},
Dir {
// TODO: wrap it like WasiFile
/// Parent directory
parent: Option<Inode>,
/// The path on the host system where the directory is located
// TODO: wrap it like WasiFile
path: PathBuf,
/// The entries of a directory are lazily filled.
entries: HashMap<String, Inode>,
Expand Down Expand Up @@ -196,6 +198,7 @@ impl WasiFs {
let cur_dir_metadata = cur_dir.metadata().expect("Could not find directory");
let kind = if cur_dir_metadata.is_dir() {
Kind::Dir {
parent: None,
path: cur_dir.clone(),
entries: Default::default(),
}
Expand Down Expand Up @@ -414,6 +417,32 @@ impl WasiFs {
);
Ok(idx)
}

pub fn get_base_path_for_directory(&self, directory: Inode) -> Option<String> {
let mut path_segments = vec![];
let mut cur_inode = directory;
loop {
path_segments.push(self.inodes[cur_inode].name.clone());

if let Kind::Dir { parent, .. } = &self.inodes[cur_inode].kind {
if let Some(p_inode) = parent {
cur_inode = *p_inode;
} else {
break;
}
} else {
return None;
}
}

path_segments.reverse();
Some(
path_segments
.iter()
.skip(1)
.fold(path_segments.first()?.clone(), |a, b| a + "/" + b),
)
}
}

#[derive(Debug)]
Expand Down

0 comments on commit a1a58d4

Please sign in to comment.