Skip to content

Commit

Permalink
Try #2491:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jul 27, 2021
2 parents 51fdf66 + 75340e1 commit efa0bc7
Show file tree
Hide file tree
Showing 35 changed files with 29,051 additions and 1,081 deletions.
94 changes: 91 additions & 3 deletions Cargo.lock

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

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"lib/engine-dylib",
"lib/engine-staticlib",
"lib/object",
"lib/vfs",
"lib/vm",
"lib/wasi",
"lib/wasi-types",
Expand All @@ -54,6 +55,7 @@ members = [
"tests/integration/cli",
"fuzz",
]
resolver = "2"

[build-dependencies]
test-generator = { path = "tests/lib/test-generator" }
Expand All @@ -72,6 +74,10 @@ wasmer-engine-dummy = { path = "tests/lib/engine-dummy" }
compiler-test-derive = { path = "tests/lib/compiler-test-derive" }
tempfile = "3.1"
loupe = "0.1"
# For logging tests using the `RUST_LOG=debug` when testing
test-env-log = { version = "0.2", default-features = false, features = ["trace"] }
tracing = { version = "0.1", default-features = false, features = ["log"] }
tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "fmt"] }

[features]
# Don't add the compiler features in default, please add them on the Makefile
Expand All @@ -80,7 +86,6 @@ default = [
"wat",
"wast",
"universal",
"dylib",
"staticlib",
"cache",
"wasi",
Expand Down Expand Up @@ -280,4 +285,4 @@ required-features = ["cranelift"]
[[example]]
name = "features"
path = "examples/features.rs"
required-features = ["cranelift"]
required-features = ["cranelift"]
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ endif
all: build-wasmer build-capi

build-wasmer:
cargo build --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer
cargo build --release --manifest-path lib/cli/Cargo.toml --features "debug" $(compiler_features) --bin wasmer

build-wasmer-debug:
cargo build --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer
Expand Down Expand Up @@ -500,9 +500,13 @@ test-packages:
cargo test --manifest-path lib/compiler-singlepass/Cargo.toml --release --no-default-features --features=std
cargo test --manifest-path lib/cli/Cargo.toml $(compiler_features) --release

test-js:
test-js: test-js-api test-js-wasi

test-js-api:
cd lib/api && wasm-pack test --node -- --no-default-features --features js-default,wat

test-js-wasi:
cd lib/wasi && wasm-pack test --node -- --no-default-features --features=test-js

#####
#
Expand Down
19 changes: 14 additions & 5 deletions lib/api/src/js/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ impl<T: Copy, Ty> WasmPtr<T, Ty> {
}
}

#[inline(always)]
fn align_pointer(ptr: usize, align: usize) -> usize {
// clears bits below aligment amount (assumes power of 2) to align pointer
debug_assert!(align.count_ones() == 1);
ptr & !(align - 1)
}

/// Methods for `WasmPtr`s to data that can be dereferenced, namely to types
/// that implement [`ValueType`], meaning that they're valid for all possible
/// bit patterns.
Expand All @@ -102,7 +109,8 @@ impl<T: Copy + ValueType> WasmPtr<T, Item> {
if total_len > memory.size().bytes().0 || mem::size_of::<T>() == 0 {
return None;
}
let subarray = memory.uint8view().subarray(self.offset, total_len as u32);
let offset = align_pointer(self.offset as usize, mem::align_of::<T>()) as u32;
let subarray = memory.uint8view().subarray(offset, total_len as u32);
Some(WasmCell::new(subarray))
}
}
Expand Down Expand Up @@ -132,13 +140,14 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
return None;
}

let offset = align_pointer(self.offset as usize, mem::align_of::<T>()) as u32;

Some(
(0..length)
.map(|i| {
let subarray = memory.uint8view().subarray(
self.offset + i * item_size,
self.offset + (i + 1) * item_size,
);
let subarray = memory
.uint8view()
.subarray(offset + i * item_size, offset + (i + 1) * item_size);
WasmCell::new(subarray)
})
.collect::<Vec<_>>(),
Expand Down
5 changes: 5 additions & 0 deletions lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) }
}

/// A uint8view
pub fn uint8view(&self) -> MemoryView<u8> {
self.view()
}

pub(crate) fn from_vm_export(store: &Store, vm_memory: VMMemory) -> Self {
Self {
store: store.clone(),
Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wasmer-engine-universal = { version = "2.0.0", path = "../engine-universal", opt
wasmer-engine-dylib = { version = "2.0.0", path = "../engine-dylib", optional = true }
wasmer-engine-staticlib = { version = "2.0.0", path = "../engine-staticlib", optional = true }
wasmer-middlewares = { version = "2.0.0", path = "../middlewares", optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, features = ["host_fs"], optional = true }
wasmer-types = { version = "2.0.0", path = "../types" }
enumset = "1.0"
cfg-if = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ wasmer-engine-universal = { version = "2.0.0", path = "../engine-universal", opt
wasmer-engine-dylib = { version = "2.0.0", path = "../engine-dylib", optional = true }
wasmer-engine-staticlib = { version = "2.0.0", path = "../engine-staticlib", optional = true }
wasmer-vm = { version = "2.0.0", path = "../vm" }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, features = ["host_fs"], optional = true }
wasmer-wasi-experimental-io-devices = { version = "2.0.0", path = "../wasi-experimental-io-devices", optional = true }
wasmer-wast = { version = "2.0.0", path = "../../tests/lib/wast", optional = true }
wasmer-cache = { version = "2.0.0", path = "../cache", optional = true }
wasmer-types = { version = "2.0.0", path = "../types" }
wasmer-vfs = { version = "2.0.0", path = "../vfs" }
atty = "0.2"
colored = "2.0"
anyhow = "1.0"
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub struct Run {
#[structopt(long = "debug", short = "d")]
debug: bool,

#[structopt(short, long, parse(from_occurrences))]
verbose: u8,

/// Application arguments
#[structopt(name = "--", multiple = true)]
args: Vec<String>,
Expand All @@ -74,7 +77,7 @@ impl Run {
pub fn execute(&self) -> Result<()> {
#[cfg(feature = "debug")]
if self.debug {
logging::set_up_logging().unwrap();
logging::set_up_logging(self.verbose).unwrap();
}
self.inner_execute().with_context(|| {
format!(
Expand Down
12 changes: 10 additions & 2 deletions lib/cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
//! Logging functions for the debug feature.
use crate::utils::wasmer_should_print_color;
use anyhow::Result;
use fern::colors::{Color, ColoredLevelConfig};
use std::time;

/// The debug level
pub type DebugLevel = log::LevelFilter;

/// Subroutine to instantiate the loggers
pub fn set_up_logging() -> Result<(), String> {
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
let colors_line = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.trace(Color::BrightBlack);
let should_color = wasmer_should_print_color();

let colors_level = colors_line.info(Color::Green);
let level = match verbose {
1 => DebugLevel::Debug,
2 | _ => DebugLevel::Trace,
};
let dispatch = fern::Dispatch::new()
.level(log::LevelFilter::Debug)
.level(level)
.chain({
let base = if should_color {
fern::Dispatch::new().format(move |out, message, record| {
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage {
}

// Implementation of `Upcastable` taken from https://users.rust-lang.org/t/why-does-downcasting-not-work-for-subtraits/33286/7 .
/// Trait needed to get downcasting from `WasiFile` to work.
/// Trait needed to get downcasting of `Engine`s to work.
pub trait Upcastable {
fn upcast_any_ref(&'_ self) -> &'_ dyn Any;
fn upcast_any_mut(&'_ mut self) -> &'_ mut dyn Any;
Expand Down
Loading

0 comments on commit efa0bc7

Please sign in to comment.