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

Stable rust #9

Merged
merged 3 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
keys:
- v4-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
- run: sudo apt-get install -y cmake
- run: rustup default nightly-2018-10-07
- run: make test
- run:
command: |
Expand Down Expand Up @@ -50,9 +49,9 @@ jobs:
tar xf cmake-3.4.1-Darwin-x86_64.tar.gz
export PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin:$PATH"
- run:
name: Install Rust Nightly
name: Install Rust
command: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2018-10-07
curl https://sh.rustup.rs -sSf | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"
cargo --version
- run:
Expand Down
27 changes: 13 additions & 14 deletions Cargo.lock

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

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "wasmer"
version = "0.1.0"
authors = ["Syrus Akbary <[email protected]>"]
edition = "2018"
# edition = "2018"
repository = "https://github.com/wafoundation/wasmer"
publish = true
description = "High-Performance WebAssembly JIT interpreter"
Expand Down Expand Up @@ -34,18 +34,19 @@ serde_derive = "1.0.55"
tempdir = "0.3.7"
error-chain = "0.12.0"
structopt = "0.2.11"
wabt = "0.6.0"
wabt = "0.7.1"
wasmparser = "0.20.0"
region = "0.3.0"
memmap = "0.6.2"
spin = "0.4.10"
# spin = "0.4.10"
log = "0.4.5"
target-lexicon = { version = "0.0.3", default-features = false }
libc = "0.2"
# libc = "0.2"
libc = { git = "https://github.com/rust-lang/libc" }
nix = "0.11"

[build-dependencies]
wabt = "0.6.0"
wabt = "0.7.1"

# [dev-dependencies]
# libffi = "0.6.4"
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ To build this project you will need Rust and Cargo.
git clone https://github.com/wafoundation/wasmer.git
cd wasmer

# Use rust nightly (we use 2018-10-07 as latest are failing)
rustup default nightly-2018-10-07

# install tools
# make sure that `python` is accessible.
cargo install
Expand All @@ -44,7 +41,7 @@ Thanks to [spectests](https://github.com/WAFoundation/wasmer/tree/master/spectes
Tests can be run with:

```sh
cargo test
make test
```

If you need to re-generate the Rust tests from the spectests
Expand Down
40 changes: 18 additions & 22 deletions src/build_spectests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This file will run at build time to autogenerate Rust tests based on
//! WebAssembly spec tests. It will convert the files indicated in TESTS
//! from "/spectests/{MODULE}.wast" to "/src/spectests/{MODULE}.rs".
extern crate wabt;

use std::collections::HashMap;
use std::env;
use std::fs;
Expand Down Expand Up @@ -205,8 +207,7 @@ fn test_module_{}() {{
module,
module,
calls.join("\n ")
)
.as_str(),
).as_str(),
);
}
self.module_calls.remove(&module);
Expand All @@ -215,7 +216,8 @@ fn test_module_{}() {{
fn visit_module(&mut self, module: &ModuleBinary, _name: &Option<String>) {
let wasm_binary: Vec<u8> = module.clone().into_vec();
let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
self.flush_module_calls(self.last_module);
let last_module = self.last_module;
self.flush_module_calls(last_module);
self.last_module = self.last_module + 1;
// self.module_calls.insert(self.last_module, vec![]);
self.buffer.push_str(
Expand All @@ -231,8 +233,7 @@ fn test_module_{}() {{
.replace("\n", "\n ")
.replace("\\", "\\\\")
.replace("\"", "\\\""),
)
.as_str(),
).as_str(),
);

// We set the start call to the module
Expand All @@ -243,8 +244,7 @@ fn test_module_{}() {{
result_object.instance.start();
}}\n",
start_module_call
)
.as_str(),
).as_str(),
);
self.module_calls
.entry(self.last_module)
Expand All @@ -255,6 +255,7 @@ fn test_module_{}() {{
fn visit_assert_invalid(&mut self, module: &ModuleBinary) {
let wasm_binary: Vec<u8> = module.clone().into_vec();
// let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
let command_name = self.command_name();
self.buffer.push_str(
format!(
"#[test]
Expand All @@ -263,13 +264,12 @@ fn {}_assert_invalid() {{
let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), \"WASM should not compile as is invalid\");
}}\n",
self.command_name(),
command_name,
wasm_binary,
// We do this to ident four spaces back
// String::from_utf8_lossy(&wasm_binary),
// wast_string.replace("\n", "\n "),
)
.as_str(),
).as_str(),
);
}

Expand Down Expand Up @@ -311,8 +311,7 @@ fn {}_assert_invalid() {{
func_return,
args_values.join(", "),
assertion,
)
.as_str(),
).as_str(),
);
self.module_calls
.entry(self.last_module)
Expand Down Expand Up @@ -369,8 +368,7 @@ fn {}_assert_invalid() {{
func_return,
args_values.join(", "),
assertion,
)
.as_str(),
).as_str(),
);
self.module_calls
.entry(self.last_module)
Expand All @@ -385,6 +383,7 @@ fn {}_assert_invalid() {{

fn visit_assert_malformed(&mut self, module: &ModuleBinary) {
let wasm_binary: Vec<u8> = module.clone().into_vec();
let command_name = self.command_name();
// let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
self.buffer.push_str(
format!(
Expand All @@ -394,13 +393,12 @@ fn {}_assert_malformed() {{
let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), \"WASM should not compile as is malformed\");
}}\n",
self.command_name(),
command_name,
wasm_binary,
// We do this to ident four spaces back
// String::from_utf8_lossy(&wasm_binary),
// wast_string.replace("\n", "\n "),
)
.as_str(),
).as_str(),
);
}

Expand Down Expand Up @@ -464,8 +462,7 @@ fn {}_assert_malformed() {{
func_return,
args_values.join(", "),
assertion,
)
.as_str(),
).as_str(),
);
Some(func_name)
// let mut module_calls = self.module_calls.get(&self.last_module).unwrap();
Expand All @@ -486,7 +483,7 @@ fn {}_assert_malformed() {{
.or_insert(Vec::new())
.push(action_fn_name.unwrap());
}

fn visit_perform_action(&mut self, action: &Action) {
let action_fn_name = self.visit_action(action, None);

Expand Down Expand Up @@ -520,8 +517,7 @@ fn {}() {{
trap_func_name,
self.last_module,
action_fn_name.unwrap(),
)
.as_str(),
).as_str(),
);

// We don't group trap calls as they may cause memory faults
Expand Down
4 changes: 1 addition & 3 deletions src/linkers/emscripten/abort.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

use crate::webassembly::Instance;
use std::process;


pub extern "C" fn abort(_code: i32, _instance: &Instance) {
process::abort();
// abort!("Aborted")
}
}
2 changes: 1 addition & 1 deletion src/linkers/emscripten/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::webassembly::ImportObject;

mod abort;
mod printf;
mod putchar;
mod abort;

pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
let mut import_object = ImportObject::new();
Expand Down
1 change: 0 additions & 1 deletion src/linkers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub mod emscripten;

pub use self::emscripten::generate_emscripten_env;
21 changes: 13 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#![feature(test, libc, core_intrinsics)]

extern crate test;
#[macro_use]
extern crate error_chain;
extern crate cranelift_codegen;
extern crate cranelift_entity;
extern crate cranelift_native;
extern crate cranelift_wasm;
extern crate libc;
extern crate memmap;
extern crate region;
extern crate structopt;
extern crate wabt;
extern crate wasmparser;
#[macro_use]
extern crate target_lexicon;
extern crate nix;
extern crate spin;

// use std::alloc::System;
// use std::time::{Duration, Instant};
Expand All @@ -23,7 +23,6 @@ extern crate spin;
#[macro_use]
extern crate log;

// use libc;
use std::fs::File;
use std::io;
use std::io::Read;
Expand Down Expand Up @@ -69,10 +68,16 @@ fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {

/// Execute a WASM/WAT file
fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
let mut wasm_binary: Vec<u8> =
read_file_contents(&wasm_path).map_err(|err| format!("Can't read the file {}: {}", wasm_path.as_os_str().to_string_lossy(), err))?;
let mut wasm_binary: Vec<u8> = read_file_contents(&wasm_path).map_err(|err| {
format!(
"Can't read the file {}: {}",
wasm_path.as_os_str().to_string_lossy(),
err
)
})?;
if !webassembly::utils::is_wasm_binary(&wasm_binary) {
wasm_binary = wabt::wat2wasm(wasm_binary).map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?;
wasm_binary = wabt::wat2wasm(wasm_binary)
.map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?;
}

let import_object = linkers::generate_emscripten_env();
Expand Down
2 changes: 1 addition & 1 deletion src/sighandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15
//! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622
use nix::sys::signal::{
sigaction, Signal, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
};

static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27];
Expand Down
Loading