Skip to content

Commit

Permalink
Merge branch 'master' into js-api
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary authored Jul 19, 2021
2 parents c6b5fe0 + 28079d8 commit 0537b63
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 63 deletions.
17 changes: 17 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 365
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 30
# Issues with these labels will never be considered stale
exemptLabels:
- "🐞 bug"
# Label to use when marking an issue as stale
staleLabel: "🏚 stale"
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
Feel free to reopen the issue if it has been closed by mistake.
72 changes: 48 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,25 @@ $(info --------------)
$(info )
$(info )

############
# Building #
############
#####
#
# Configure `sed -i` for a cross-platform usage.
#
#####

SEDI ?=

ifeq ($(IS_DARWIN), 1)
SEDI := "-i ''"
else ifeq ($(IS_LINUX), 1)
SEDI := "-i"
endif

#####
#
# Building.
#
#####

# Not really "all", just the default target that builds enough so make
# install will go through.
Expand Down Expand Up @@ -363,13 +379,11 @@ build-wasmer-headless-minimal:
RUSTFLAGS="${RUSTFLAGS}" xargo build --target $(HOST_TARGET) --release --manifest-path=lib/cli/Cargo.toml --no-default-features --features headless-minimal --bin wasmer-headless
ifeq ($(IS_DARWIN), 1)
strip -u target/$(HOST_TARGET)/release/wasmer-headless
else
ifeq ($(IS_WINDOWS), 1)
else ifeq ($(IS_WINDOWS), 1)
strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless.exe
else
strip --strip-unneeded target/$(HOST_TARGET)/release/wasmer-headless
endif
endif

WAPM_VERSION = v0.5.1
get-wapm:
Expand All @@ -395,9 +409,9 @@ build-docs-capi: capi-setup
# `wasmer-c-api` lib's name is `wasmer`. To avoid a conflict
# when generating the documentation, we rename it to its
# crate's name. Then we restore the lib's name.
sed -i '' -e 's/name = "wasmer" # ##lib.name##/name = "wasmer_c_api" # ##lib.name##/' lib/c-api/Cargo.toml
sed "$(SEDI)" -e 's/name = "wasmer" # ##lib.name##/name = "wasmer_c_api" # ##lib.name##/' lib/c-api/Cargo.toml
RUSTFLAGS="${RUSTFLAGS}" cargo doc --manifest-path lib/c-api/Cargo.toml --no-deps --features wat,universal,staticlib,dylib,cranelift,wasi
sed -i '' -e 's/name = "wasmer_c_api" # ##lib.name##/name = "wasmer" # ##lib.name##/' lib/c-api/Cargo.toml
sed "$(SEDI)" -e 's/name = "wasmer_c_api" # ##lib.name##/name = "wasmer" # ##lib.name##/' lib/c-api/Cargo.toml

build-capi: capi-setup
RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \
Expand Down Expand Up @@ -469,10 +483,11 @@ build-capi-headless-all: capi-setup
RUSTFLAGS="${RUSTFLAGS}" cargo build --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features universal,dylib,staticlib,wasi


###########
# Testing #
###########
#####
#
# Testing.
#
#####

test: test-compilers test-packages test-examples

Expand All @@ -488,9 +503,12 @@ test-packages:
test-js:
cd lib/js-api && wasm-pack test --node -- --features=wat

########################
# Testing (Compatible) #
########################

#####
#
# Testing compilers.
#
#####

test-compilers-compat: $(foreach compiler,$(compilers),test-$(compiler))

Expand Down Expand Up @@ -541,9 +559,11 @@ test-examples:
test-integration:
cargo test -p wasmer-integration-tests-cli

#############
# Packaging #
#############
#####
#
# Packaging.
#
#####

package-wapm:
mkdir -p "package/bin"
Expand Down Expand Up @@ -629,9 +649,11 @@ endif
tar -C package -zcvf wasmer.tar.gz bin lib include LICENSE ATTRIBUTIONS
mv wasmer.tar.gz dist/

########################
# (Distro-) Installing #
########################
#####
#
# Installating (for Distros).
#
#####

DESTDIR ?= /usr/local

Expand Down Expand Up @@ -672,9 +694,11 @@ install-pkgconfig:
install-wasmer-headless-minimal:
install -Dm755 target/release/wasmer-headless $(DESTDIR)/bin/wasmer-headless

#################
# Miscellaneous #
#################
#####
#
# Miscellaneous.
#
#####

# Updates the spectests from the repo
update-testsuite:
Expand Down
2 changes: 1 addition & 1 deletion lib/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wasmer"
version = "2.0.0"
description = "High-performant WebAssembly runtime"
description = "High-performance WebAssembly runtime"
categories = ["wasm"]
keywords = ["wasm", "webassembly", "runtime", "vm"]
authors = ["Wasmer Engineering Team <[email protected]>"]
Expand Down
3 changes: 3 additions & 0 deletions lib/c-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Looking for changes to the Wasmer CLI and the Rust API? See our [Primary Changel
### Added
- [#2449](https://github.com/wasmerio/wasmer/pull/2449) Configure `soname`, `install_name`, `out-implib`, etc.

### Changed
- [#2478](https://github.com/wasmerio/wasmer/pull/2478) Rename `traps` input to `wasm_instance_new()` to `trap`.

### Fixed
- [#2444](https://github.com/wasmerio/wasmer/pull/2444) Trap's messages are always null terminated.

Expand Down
6 changes: 3 additions & 3 deletions lib/c-api/examples/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int main(int argc, const char* argv[]) {

printf("Instantiating module...\n");
wasm_extern_vec_t imports = WASM_EMPTY_VEC;
wasm_trap_t* traps = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports,&traps);
wasm_trap_t* trap = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports,&trap);

if (!instance) {
printf("> Error instantiating module!\n");
Expand All @@ -67,7 +67,7 @@ int main(int argc, const char* argv[]) {
wasm_val_vec_t arguments_as_array = WASM_ARRAY_VEC(arguments);
wasm_val_vec_t results_as_array = WASM_ARRAY_VEC(results);

wasm_trap_t* trap = wasm_func_call(swap, &arguments_as_array, &results_as_array);
trap = wasm_func_call(swap, &arguments_as_array, &results_as_array);

if (trap != NULL) {
printf("> Failed to call `swap`.\n");
Expand Down
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ mod tests {
assert(module);

wasm_extern_vec_t imports = WASM_EMPTY_VEC;
wasm_trap_t* traps = NULL;
wasm_trap_t* trap = NULL;

wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
assert(instance);

wasm_extern_vec_t exports;
Expand Down
18 changes: 9 additions & 9 deletions lib/c-api/src/wasm_c_api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct wasm_instance_t {
/// 2. Runtime errors that happen when running the module `start`
/// function.
///
/// Failures are stored in the `traps` argument; the program doesn't
/// The failure is stored in the `trap` argument; the program doesn't
/// panic.
///
/// # Notes
Expand All @@ -41,7 +41,7 @@ pub unsafe extern "C" fn wasm_instance_new(
_store: Option<&wasm_store_t>,
module: Option<&wasm_module_t>,
imports: Option<&wasm_extern_vec_t>,
traps: *mut *mut wasm_trap_t,
trap: *mut *mut wasm_trap_t,
) -> Option<Box<wasm_instance_t>> {
let module = module?;
let imports = imports?;
Expand All @@ -67,8 +67,8 @@ pub unsafe extern "C" fn wasm_instance_new(
}

Err(InstantiationError::Start(runtime_error)) => {
let trap: Box<wasm_trap_t> = Box::new(runtime_error.into());
*traps = Box::into_raw(trap);
let this_trap: Box<wasm_trap_t> = Box::new(runtime_error.into());
*trap = Box::into_raw(this_trap);

return None;
}
Expand Down Expand Up @@ -124,9 +124,9 @@ pub unsafe extern "C" fn wasm_instance_delete(_instance: Option<Box<wasm_instanc
///
/// // Instantiate the module.
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_trap_t* trap = NULL;
///
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Read the exports.
Expand Down Expand Up @@ -252,8 +252,8 @@ mod tests {
wasm_extern_vec_t imports = WASM_ARRAY_VEC(externs);

// Instantiate the module.
wasm_trap_t* traps = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
wasm_trap_t* trap = NULL;
wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);

assert(instance);

Expand All @@ -273,7 +273,7 @@ mod tests {
wasm_val_vec_t arguments_as_array = WASM_ARRAY_VEC(arguments);
wasm_val_vec_t results_as_array = WASM_ARRAY_VEC(results);

wasm_trap_t* trap = wasm_func_call(run_function, &arguments_as_array, &results_as_array);
trap = wasm_func_call(run_function, &arguments_as_array, &results_as_array);

assert(trap == NULL);
assert(results[0].of.i32 == 2);
Expand Down
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ pub mod externals;
///
/// // Instantiate the module.
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_trap_t* trap = NULL;
///
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Now do something with the instance, like calling the
Expand Down
14 changes: 7 additions & 7 deletions lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
//!
//! // Instantiate the module.
//! wasm_extern_vec_t imports = WASM_EMPTY_VEC;
//! wasm_trap_t* traps = NULL;
//! wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
//! wasm_trap_t* trap = NULL;
//! wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
//! assert(instance);
//!
//! // Here we go. At this step, we will get the `add_two` exported function, and
Expand All @@ -88,7 +88,7 @@
//!
//! // Let's call `add_two` for the first time!
//! {
//! wasm_trap_t* trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! assert(trap == NULL);
//! assert(results[0].of.i32 == 42);
//!
Expand All @@ -99,7 +99,7 @@
//!
//! // Let's call `add_two` for the second time!
//! {
//! wasm_trap_t* trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! assert(trap == NULL);
//! assert(results[0].of.i32 == 42);
//!
Expand All @@ -110,7 +110,7 @@
//!
//! // Let's call `add_two` for the third time!
//! {
//! wasm_trap_t* trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! trap = wasm_func_call(add_two, &arguments_as_array, &results_as_array);
//! // Oh, it failed!
//! assert(trap != NULL);
//!
Expand Down Expand Up @@ -269,8 +269,8 @@ pub extern "C" fn wasmer_metering_points_are_exhausted(instance: &wasm_instance_
/// assert(module);
///
/// wasm_extern_vec_t imports = WASM_EMPTY_VEC;
/// wasm_trap_t* traps = NULL;
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &traps);
/// wasm_trap_t* trap = NULL;
/// wasm_instance_t* instance = wasm_instance_new(store, module, &imports, &trap);
/// assert(instance);
///
/// // Read the number of points.
Expand Down
20 changes: 6 additions & 14 deletions lib/c-api/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@ $(info * LDFLAGS: $(LDFLAGS))
$(info * LDLIBS: $(LDLIBS))

CAPI_BASE_TESTS = \
wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \
wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \
wasm-c-api/example/start wasm-c-api/example/trap wasm-c-api/example/multi
wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \
wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \
wasm-c-api/example/start wasm-c-api/example/trap wasm-c-api/example/multi

CAPI_BASE_TESTS_NOT_WORKING = \
wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/threads \
wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/threads \
wasm-c-api/example/table

ALL = $(CAPI_BASE_TESTS) $(CAPI_WASMER_TESTS)

test-%: %.o
ALL = $(CAPI_BASE_TESTS)

.PHONY: all
all: $(ALL)

.PHONY: test-capi-wasmer
.SILENT: test-capi-wasmer
test-capi-wasmer: $(CAPI_WASMER_TESTS)
set -o errexit; \
$(foreach example,$?,echo Running \"$(example)\" example; cd $(shell dirname $(realpath $(example))) && ./$(shell basename $(example)); echo;)

.PHONY: test-capi-base
.SILENT: test-capi-base
test-capi-base: $(CAPI_BASE_TESTS)
Expand All @@ -48,7 +40,7 @@ test-capi-base: $(CAPI_BASE_TESTS)

.PHONY: test-capi-base
.SILENT: test-capi-base
test-capi: test-capi-base test-capi-wasmer
test-capi: test-capi-base

test: test-capi

Expand Down
5 changes: 4 additions & 1 deletion lib/cli/src/commands/validate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::store::StoreOptions;
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*;
Expand All @@ -24,6 +24,9 @@ impl Validate {
fn inner_execute(&self) -> Result<()> {
let (store, _engine_type, _compiler_type) = self.store.get_store()?;
let module_contents = std::fs::read(&self.path)?;
if !is_wasm(&module_contents) {
bail!("`wasmer validate` only validates WebAssembly files");
}
Module::validate(&store, &module_contents)?;
eprintln!("Validation passed for `{}`.", self.path.display());
Ok(())
Expand Down

0 comments on commit 0537b63

Please sign in to comment.