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

Introduce near_vm feature #8862

Merged
merged 5 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ near-state-viewer = { path = "tools/state-viewer", package = "state-viewer" }
near-store = { path = "core/store" }
near-telemetry = { path = "chain/telemetry" }
near-test-contracts = { path = "runtime/near-test-contracts" }
near-vm-compiler = { path = "runtime/near-vm/lib/compiler"}
near-vm-compiler-singlepass = { path = "runtime/near-vm/lib/compiler-singlepass" }
near-vm-engine = { path = "runtime/near-vm/lib/engine" }
near-vm-engine-universal = { path = "runtime/near-vm/lib/engine-universal" }
near-vm-errors = { path = "runtime/near-vm-errors" }
near-vm-logic = {path = "runtime/near-vm-logic" }
near-vm-logic = { path = "runtime/near-vm-logic" }
near-vm-runner = { path = "runtime/near-vm-runner"}
near-vm-types = { path = "runtime/near-vm/lib/types" }
near-vm-vm = { path = "runtime/near-vm/lib/vm" }
nearcore = { path = "nearcore" }
nix = "0.24"
node-runtime = { path = "runtime/runtime" }
Expand Down
16 changes: 16 additions & 0 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ wasmer-engine = { workspace = true, optional = true }
wasmer-engine-universal = { workspace = true, optional = true }
wasmer-types = { workspace = true, optional = true }
wasmer-vm = { workspace = true, optional = true }
near-vm-compiler = { workspace = true, optional = true }
near-vm-compiler-singlepass = { workspace = true, optional = true }
near-vm-engine = { workspace = true, optional = true }
near-vm-engine-universal = { workspace = true, features = ["compiler"], optional = true }
near-vm-types = { workspace = true, optional = true }
near-vm-vm = { workspace = true, optional = true }

[dev-dependencies]
arbitrary.workspace = true
Expand All @@ -64,6 +70,7 @@ default = [
"wasmer0_vm",
"wasmtime_vm",
"wasmer2_vm",
"near_vm",
]
wasmer0_vm = [ "wasmer-runtime", "wasmer-runtime-core" ]
wasmtime_vm = [ "wasmtime", "anyhow"]
Expand All @@ -75,11 +82,20 @@ wasmer2_vm = [
"wasmer-types",
"wasmer-vm"
]
near_vm = [
"near-vm-compiler",
"near-vm-compiler-singlepass",
"near-vm-engine",
"near-vm-engine-universal",
"near-vm-types",
"near-vm-vm"
]

# Force usage of a specific wasm vm irrespective of protocol version.
force_wasmer0 = ["wasmer0_vm"]
force_wasmtime = ["wasmtime_vm"]
force_wasmer2 = ["wasmer2_vm"]
force_near_vm = ["near_vm"]

no_cpu_compatibility_checks = []

Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The entry point is the `runner::run` function.
There's a bunch of unit-tests in this crate. You can run them with

```console
$ cargo t -p near-vm-runner --features wasmer0_vm,wasmer2_vm,wasmtime_vm
$ cargo t -p near-vm-runner --features wasmer0_vm,wasmer2_vm,wasmtime_vm,near_vm
```

The tests use either a short wasm snippets specified inline, or a couple of
Expand Down
3 changes: 0 additions & 3 deletions runtime/near-vm/lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ readme = "README.md"
edition = "2021"
publish = false

[lib]
name = "wasmer"

# Shared dependencies.
[dependencies]
# - Mandatory shared dependencies.
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm/lib/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here is a small example of using Wasmer to run a WebAssembly module
written with its WAT format (textual format):

```rust
use wasmer::{Store, Module, Instance, Value, imports};
use near_vm::{Store, Module, Instance, Value, imports};

fn main() -> anyhow::Result<()> {
let module_wat = r#"
Expand Down
6 changes: 3 additions & 3 deletions runtime/near-vm/lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! written with its WAT format (textual format):
//!
//! ```rust
//! use wasmer::{Store, Module, Instance, InstanceConfig, Value, Export, imports};
//! use near_vm::{Store, Module, Instance, InstanceConfig, Value, Export, imports};
//!
//! fn main() -> anyhow::Result<()> {
//! let module_wat = r#"
Expand Down Expand Up @@ -144,7 +144,7 @@
//! [`imports`] macro:
//!
//! ```
//! # use wasmer::{imports, Function, Memory, MemoryType, Store, ImportObject};
//! # use near_vm::{imports, Function, Memory, MemoryType, Store, ImportObject};
//! # fn imports_example(store: &Store) -> ImportObject {
//! let memory = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
//! imports! {
Expand All @@ -160,7 +160,7 @@
//! from any instance via `instance.exports`:
//!
//! ```
//! # use wasmer::{imports, Instance, Function, Memory, NativeFunc};
//! # use near_vm::{imports, Instance, Function, Memory, NativeFunc};
//! # fn exports_example(instance: &Instance) -> anyhow::Result<()> {
//! let memory = instance.lookup("memory").unwrap();
//! let memory = instance.lookup("some_other_memory").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm/lib/api/src/sys/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a, T> WasmCell<'a, T> {
///
/// ```
/// use std::cell::Cell;
/// use wasmer::WasmCell;
/// use near_vm::WasmCell;
///
/// let cell = Cell::new(5);
/// let wasm_cell = WasmCell::new(&cell);
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm/lib/api/src/sys/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl From<ExportError> for HostEnvInitError {
///
/// This trait may also be implemented manually:
/// ```
/// # use wasmer::{WasmerEnv, LazyInit, Memory, Instance, HostEnvInitError};
/// # use near_vm::{WasmerEnv, LazyInit, Memory, Instance, HostEnvInitError};
/// #[derive(Clone)]
/// pub struct MyEnv {
/// memory: LazyInit<Memory>,
Expand Down
4 changes: 2 additions & 2 deletions runtime/near-vm/lib/api/src/sys/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use wasmer_vm::Export;
/// ## Incompatible export type
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value, ExportError};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value, ExportError};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
Expand All @@ -32,7 +32,7 @@ use wasmer_vm::Export;
/// ## Missing export
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value, ExportError};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value, ExportError};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm("(module)".as_bytes()).unwrap();
/// # let module = Module::new(&store, wasm_bytes).unwrap();
Expand Down
26 changes: 13 additions & 13 deletions runtime/near-vm/lib/api/src/sys/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value};
/// # use near_vm::{Function, FunctionType, Type, Store, Value};
/// # let store = Store::default();
/// #
/// let signature = FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]);
Expand All @@ -169,7 +169,7 @@ impl Function {
/// With constant signature:
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value};
/// # use near_vm::{Function, FunctionType, Type, Store, Value};
/// # let store = Store::default();
/// #
/// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]);
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # use near_vm::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # let store = Store::default();
/// #
/// #[derive(Clone)]
Expand All @@ -220,7 +220,7 @@ impl Function {
/// With constant signature:
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # use near_vm::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # let store = Store::default();
/// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]);
///
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Store, Function};
/// # use near_vm::{Store, Function};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
Expand Down Expand Up @@ -349,7 +349,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Store, Function, WasmerEnv};
/// # use near_vm::{Store, Function, WasmerEnv};
/// # let store = Store::default();
/// #
/// #[derive(Clone)]
Expand Down Expand Up @@ -404,7 +404,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use near_vm::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
Expand Down Expand Up @@ -498,7 +498,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use near_vm::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
Expand All @@ -518,7 +518,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use near_vm::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
Expand All @@ -544,7 +544,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
Expand Down Expand Up @@ -604,7 +604,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
Expand All @@ -630,7 +630,7 @@ impl Function {
/// an error will be raised:
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
Expand All @@ -654,7 +654,7 @@ impl Function {
/// an error will be raised:
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # use near_vm::{imports, wat2wasm, Function, Instance, InstanceConfig, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
Expand Down
16 changes: 8 additions & 8 deletions runtime/near-vm/lib/api/src/sys/externals/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Value};
/// # use near_vm::{Global, Mutability, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
Expand All @@ -42,7 +42,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Value};
/// # use near_vm::{Global, Mutability, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new_mut(&store, Value::I32(1));
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Type, Value, GlobalType};
/// # use near_vm::{Global, Mutability, Store, Type, Value, GlobalType};
/// # let store = Store::default();
/// #
/// let c = Global::new(&store, Value::I32(1));
Expand All @@ -95,7 +95,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use near_vm::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
Expand All @@ -111,7 +111,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use near_vm::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
Expand All @@ -127,7 +127,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use near_vm::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new_mut(&store, Value::I32(1));
Expand All @@ -144,7 +144,7 @@ impl Global {
/// Trying to mutate a immutable global will raise an error:
///
/// ```should_panic
/// # use wasmer::{Global, Store, Value};
/// # use near_vm::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
Expand All @@ -155,7 +155,7 @@ impl Global {
/// Trying to set a value of a incompatible type will raise an error:
///
/// ```should_panic
/// # use wasmer::{Global, Store, Value};
/// # use near_vm::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
Expand Down
10 changes: 5 additions & 5 deletions runtime/near-vm/lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use near_vm::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use near_vm::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let mt = MemoryType::new(1, None, false);
Expand All @@ -83,7 +83,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use near_vm::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use near_vm::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
Expand All @@ -166,7 +166,7 @@ impl Memory {
/// # Usage:
///
/// ```
/// # use wasmer::{Memory, MemoryView};
/// # use near_vm::{Memory, MemoryView};
/// # use std::{cell::Cell, sync::atomic::Ordering};
/// # fn view_memory(memory: Memory) {
/// // Without synchronization.
Expand Down
Loading