diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..1c2f0d31e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# How to Contribute to Wasmer + +Thank you for your interest in contributing to Wasmer. This document outlines some recommendations on how to contribute. + +## Issues & Feature Requests +Please use the issue template and provide a failing example if possible to help us recreate the issue. + +## Pull Requests +For large changes, please try reaching the Wasmer using Github Issues or Spectrum Chat to ensure we can accept the change once it is ready. + +We recommend trying the following commands before sending a pull request to ensure code quality: +- `cargo fmt --all` Ensures all code is correctly formatted. +- Run `cargo test` in the crates that you are modifying. +- Run `cargo build --all` (nightly) or `cargo build --all --exclude wasmer-singlepass-backend` + +A comprehensive CI test suite will be run by a Wasmer team member after the PR has been created. + +### Common Build Issues + +**LLVM Dependency** + +The LLVM backend requires LLVM to be installed to compile. + +So, you may run into the following error: +``` +Didn't find usable system-wide LLVM. +No suitable version of LLVM was found system-wide or pointed +``` + +**Singlepass Nightly Only** + +The singlepass crate depends on nightly so you may need to add the `+nightly` cargo flag to compile this crate. +`error[E0554]: #![feature] may not be used on the stable release channel` diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index cdaae7688..eed22d39e 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/emscripten-tests/tests/emtests/_common.rs b/lib/emscripten-tests/tests/emtests/_common.rs index 8e4a70534..1e5dfba6e 100644 --- a/lib/emscripten-tests/tests/emtests/_common.rs +++ b/lib/emscripten-tests/tests/emtests/_common.rs @@ -42,7 +42,7 @@ macro_rules! assert_emscripten_output { // let module = compile(&wasm_bytes[..]) // .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ?? - let mut emscripten_globals = EmscriptenGlobals::new(&module); + let mut emscripten_globals = EmscriptenGlobals::new(&module).expect("globals are valid"); let import_object = generate_emscripten_env(&mut emscripten_globals); let mut instance = module.instantiate(&import_object) diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index d2ddc03d6..2f03dbb3b 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns @@ -14,7 +16,7 @@ use std::collections::HashMap; use std::path::PathBuf; use std::{f64, ffi::c_void}; use wasmer_runtime_core::{ - error::CallResult, + error::{CallError, CallResult, ResolveError}, export::Export, func, global::Global, @@ -371,10 +373,11 @@ pub fn run_emscripten_instance( 0 => { instance.call(func_name, &[])?; } - _ => panic!( - "The emscripten main function has received an incorrect number of params {}", - num_params - ), + _ => { + return Err(CallError::Resolve(ResolveError::ExportWrongType { + name: "main".to_string(), + })) + } }; } @@ -434,7 +437,7 @@ pub struct EmscriptenGlobals { } impl EmscriptenGlobals { - pub fn new(module: &Module /*, static_bump: u32 */) -> Self { + pub fn new(module: &Module /*, static_bump: u32 */) -> Result { let mut use_old_abort_on_cannot_grow_memory = false; for ( index, @@ -456,8 +459,8 @@ impl EmscriptenGlobals { } } - let (table_min, table_max) = get_emscripten_table_size(&module); - let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module); + let (table_min, table_max) = get_emscripten_table_size(&module)?; + let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module)?; // Memory initialization let memory_type = MemoryDescriptor { @@ -528,14 +531,14 @@ impl EmscriptenGlobals { } } - Self { + Ok(Self { data, memory, table, memory_min, memory_max, null_func_names, - } + }) } } diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 37d3ae870..246cd1686 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -33,22 +33,20 @@ pub fn is_emscripten_module(module: &Module) -> bool { false } -pub fn get_emscripten_table_size(module: &Module) -> (u32, Option) { - assert!( - module.info().imported_tables.len() > 0, - "Emscripten requires at least one imported table" - ); +pub fn get_emscripten_table_size(module: &Module) -> Result<(u32, Option), String> { + if module.info().imported_tables.len() == 0 { + return Err("Emscripten requires at least one imported table".to_string()); + } let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)]; - (table.minimum, table.maximum) + Ok((table.minimum, table.maximum)) } -pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option, bool) { - assert!( - module.info().imported_tables.len() > 0, - "Emscripten requires at least one imported memory" - ); +pub fn get_emscripten_memory_size(module: &Module) -> Result<(Pages, Option, bool), String> { + if module.info().imported_memories.len() == 0 { + return Err("Emscripten requires at least one imported memory".to_string()); + } let (_, memory) = &module.info().imported_memories[ImportedMemoryIndex::new(0)]; - (memory.minimum, memory.maximum, memory.shared) + Ok((memory.minimum, memory.maximum, memory.shared)) } /// Reads values written by `-s EMIT_EMSCRIPTEN_METADATA=1` diff --git a/lib/llvm-backend/src/lib.rs b/lib/llvm-backend/src/lib.rs index 251296e44..454fad100 100644 --- a/lib/llvm-backend/src/lib.rs +++ b/lib/llvm-backend/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index c833273de..929558f25 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 27572ee83..c12db47d9 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index d106e1708..78c6235c8 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index 70eac299b..e749e5a22 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 77eb53d12..ac9b11a86 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/lib/win-exception-handler/src/lib.rs b/lib/win-exception-handler/src/lib.rs index f2561fda0..cf5e8396f 100644 --- a/lib/win-exception-handler/src/lib.rs +++ b/lib/win-exception-handler/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/src/bin/kwasmd.rs b/src/bin/kwasmd.rs index fc67b6a60..62e22b731 100644 --- a/src/bin/kwasmd.rs +++ b/src/bin/kwasmd.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 705e38812..be0939e43 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns @@ -542,7 +544,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { // TODO: refactor this if wasmer_emscripten::is_emscripten_module(&module) { - let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module); + let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module)?; let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals); let mut instance = module .instantiate(&import_object) diff --git a/src/lib.rs b/src/lib.rs index 43534b78c..3d0b047ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![deny( dead_code, + nonstandard_style, unused_imports, + unused_mut, unused_variables, unused_unsafe, unreachable_patterns