mirror of
https://github.com/mii443/wasmer.git
synced 2025-09-01 23:19:14 +00:00
Improved examples
This commit is contained in:
57
Cargo.toml
57
Cargo.toml
@ -13,7 +13,7 @@ autoexamples = false
|
|||||||
wasmer = { version = "=3.2.0-alpha.1", path = "lib/api", default-features = false }
|
wasmer = { version = "=3.2.0-alpha.1", path = "lib/api", default-features = false }
|
||||||
wasmer-compiler = { version = "=3.2.0-alpha.1", path = "lib/compiler", features = [
|
wasmer-compiler = { version = "=3.2.0-alpha.1", path = "lib/compiler", features = [
|
||||||
"compiler",
|
"compiler",
|
||||||
] }
|
], optional=true }
|
||||||
wasmer-compiler-cranelift = { version = "=3.2.0-alpha.1", path = "lib/compiler-cranelift", optional = true }
|
wasmer-compiler-cranelift = { version = "=3.2.0-alpha.1", path = "lib/compiler-cranelift", optional = true }
|
||||||
wasmer-compiler-singlepass = { version = "=3.2.0-alpha.1", path = "lib/compiler-singlepass", optional = true }
|
wasmer-compiler-singlepass = { version = "=3.2.0-alpha.1", path = "lib/compiler-singlepass", optional = true }
|
||||||
wasmer-compiler-llvm = { version = "=3.2.0-alpha.1", path = "lib/compiler-llvm", optional = true }
|
wasmer-compiler-llvm = { version = "=3.2.0-alpha.1", path = "lib/compiler-llvm", optional = true }
|
||||||
@ -74,7 +74,7 @@ rustc_version = "0.4"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasmer = { version = "=3.2.0-alpha.1", path = "lib/api", default-features = false, features = [
|
wasmer = { version = "=3.2.0-alpha.1", path = "lib/api", default-features = false, features = [
|
||||||
"cranelift",
|
"jsc",
|
||||||
] }
|
] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
@ -102,6 +102,7 @@ default = [
|
|||||||
"emscripten",
|
"emscripten",
|
||||||
"middlewares",
|
"middlewares",
|
||||||
]
|
]
|
||||||
|
jsc = ["wasmer/jsc", "wat", "wasmer/std"]
|
||||||
engine = ["universal"]
|
engine = ["universal"]
|
||||||
universal = []
|
universal = []
|
||||||
cache = ["wasmer-cache"]
|
cache = ["wasmer-cache"]
|
||||||
@ -140,10 +141,10 @@ split-debuginfo = "unpacked"
|
|||||||
name = "static_and_dynamic_functions"
|
name = "static_and_dynamic_functions"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[[example]]
|
# [[example]]
|
||||||
name = "early-exit"
|
# name = "early-exit"
|
||||||
path = "examples/early_exit.rs"
|
# path = "examples/early_exit.rs"
|
||||||
required-features = ["cranelift"]
|
# required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "engine"
|
name = "engine"
|
||||||
@ -183,27 +184,27 @@ required-features = ["llvm"]
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "exported-function"
|
name = "exported-function"
|
||||||
path = "examples/exports_function.rs"
|
path = "examples/exports_function.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "exported-global"
|
name = "exported-global"
|
||||||
path = "examples/exports_global.rs"
|
path = "examples/exports_global.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
# [[example]]
|
||||||
name = "exported-memory"
|
# name = "exported-memory"
|
||||||
path = "examples/exports_memory.rs"
|
# path = "examples/exports_memory.rs"
|
||||||
required-features = ["cranelift"]
|
# required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "imported-function"
|
name = "imported-function"
|
||||||
path = "examples/imports_function.rs"
|
path = "examples/imports_function.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "imported-global"
|
name = "imported-global"
|
||||||
path = "examples/imports_global.rs"
|
path = "examples/imports_global.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "tunables-limit-memory"
|
name = "tunables-limit-memory"
|
||||||
@ -213,52 +214,52 @@ required-features = ["cranelift"]
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
path = "examples/wasi.rs"
|
path = "examples/wasi.rs"
|
||||||
required-features = ["cranelift", "wasi"]
|
required-features = ["wasi"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "wasi-manual-setup"
|
name = "wasi-manual-setup"
|
||||||
path = "examples/wasi_manual_setup.rs"
|
path = "examples/wasi_manual_setup.rs"
|
||||||
required-features = ["cranelift", "wasi"]
|
required-features = ["wasi"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "wasi-pipes"
|
name = "wasi-pipes"
|
||||||
path = "examples/wasi_pipes.rs"
|
path = "examples/wasi_pipes.rs"
|
||||||
required-features = ["cranelift", "wasi"]
|
required-features = ["wasi"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "table"
|
name = "table"
|
||||||
path = "examples/table.rs"
|
path = "examples/table.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
# [[example]]
|
||||||
name = "memory"
|
# name = "memory"
|
||||||
path = "examples/memory.rs"
|
# path = "examples/memory.rs"
|
||||||
required-features = ["cranelift"]
|
# required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "instance"
|
name = "instance"
|
||||||
path = "examples/instance.rs"
|
path = "examples/instance.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "errors"
|
name = "errors"
|
||||||
path = "examples/errors.rs"
|
path = "examples/errors.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = ["sys"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "imported-function-env"
|
name = "imported-function-env"
|
||||||
path = "examples/imports_function_env.rs"
|
path = "examples/imports_function_env.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "imported-function-env-global"
|
name = "imported-function-env-global"
|
||||||
path = "examples/imports_function_env_global.rs"
|
path = "examples/imports_function_env_global.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "hello-world"
|
name = "hello-world"
|
||||||
path = "examples/hello_world.rs"
|
path = "examples/hello_world.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "metering"
|
name = "metering"
|
||||||
@ -268,7 +269,7 @@ required-features = ["cranelift"]
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "imports-exports"
|
name = "imports-exports"
|
||||||
path = "examples/imports_exports.rs"
|
path = "examples/imports_exports.rs"
|
||||||
required-features = ["cranelift"]
|
required-features = []
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "features"
|
name = "features"
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
// First we need to create an error type that we'll use to signal the end of execution.
|
// First we need to create an error type that we'll use to signal the end of execution.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@ -51,10 +50,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -38,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let mut store = Store::new(Cranelift::default());
|
let mut store = Store::default();
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, Value};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -36,10 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Mutability, Store, Type, TypedFunction, Value};
|
use wasmer::{imports, wat2wasm, Instance, Module, Mutability, Store, Type, TypedFunction, Value};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -34,10 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
@ -105,10 +101,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Trying to set the value of a immutable global (`const`)
|
// Trying to set the value of a immutable global (`const`)
|
||||||
// will result in a `RuntimeError`.
|
// will result in a `RuntimeError`.
|
||||||
let result = one.set(&mut store, Value::F32(42.0));
|
let result = one.set(&mut store, Value::F32(42.0));
|
||||||
assert_eq!(
|
// The global is immutable
|
||||||
result.expect_err("Expected an error").message(),
|
assert!(result.is_err());
|
||||||
"Attempted to set an immutable global"
|
// assert_eq!(
|
||||||
);
|
// result.expect_err("Expected an error").message(),
|
||||||
|
// "Attempted to set an immutable global"
|
||||||
|
// );
|
||||||
|
|
||||||
let one_result = one.get(&mut store);
|
let one_result = one.get(&mut store);
|
||||||
println!("`one` value after `set`: {:?}", one_result);
|
println!("`one` value after `set`: {:?}", one_result);
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, WasmPtr};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction, WasmPtr};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -33,10 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
// First we create a simple Wasm program to use with Wasmer.
|
// First we create a simple Wasm program to use with Wasmer.
|
||||||
@ -34,16 +33,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Next we create the `Store`, the top level type in the Wasmer API.
|
// Create a Store.
|
||||||
//
|
let mut store = Store::default();
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
//
|
|
||||||
// However for the purposes of showing what's happening, we create a compiler
|
|
||||||
// (`Cranelift`) and pass it to an engine (`Universal`). We then pass the engine to
|
|
||||||
// the store and are now ready to compile and run WebAssembly!
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
// We then use our store and Wasm bytes to compile a `Module`.
|
// We then use our store and Wasm bytes to compile a `Module`.
|
||||||
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
|
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
|
||||||
|
@ -19,7 +19,6 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionType, Global, Instance, Memory, Module, Store, Table,
|
imports, wat2wasm, Function, FunctionType, Global, Instance, Memory, Module, Store, Table,
|
||||||
Type, Value,
|
Type, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module.
|
// Let's declare the Wasm module.
|
||||||
@ -40,10 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -21,7 +21,6 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, FunctionType, Instance, Module,
|
||||||
Store, Type, TypedFunction, Value,
|
Store, Type, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -41,10 +40,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
struct MyEnv;
|
struct MyEnv;
|
||||||
let env = FunctionEnv::new(&mut store, MyEnv {});
|
let env = FunctionEnv::new(&mut store, MyEnv {});
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Instance, Module, Store,
|
||||||
TypedFunction,
|
TypedFunction,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -48,10 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -25,7 +25,6 @@ use wasmer::{
|
|||||||
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Global, Instance, Module, Store,
|
imports, wat2wasm, Function, FunctionEnv, FunctionEnvMut, Global, Instance, Module, Store,
|
||||||
TypedFunction, Value,
|
TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -50,10 +49,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Global, Instance, Module, Store, TypedFunction, Value};
|
use wasmer::{imports, wat2wasm, Global, Instance, Module, Store, TypedFunction, Value};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module with the text representation.
|
// Let's declare the Wasm module with the text representation.
|
||||||
@ -34,10 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
@ -88,10 +84,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Trying to set the value of a immutable global (`const`)
|
// Trying to set the value of a immutable global (`const`)
|
||||||
// will result in a `RuntimeError`.
|
// will result in a `RuntimeError`.
|
||||||
let result = some.set(&mut store, Value::F32(42.0));
|
let result = some.set(&mut store, Value::F32(42.0));
|
||||||
assert_eq!(
|
assert!(result.is_err());
|
||||||
result.expect_err("Expected an error").message(),
|
|
||||||
"Attempted to set an immutable global"
|
|
||||||
);
|
|
||||||
|
|
||||||
other.set(&mut store, Value::F32(21.0))?;
|
other.set(&mut store, Value::F32(21.0))?;
|
||||||
let other_result = other.get(&mut store);
|
let other_result = other.get(&mut store);
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, Instance, Module, Store, TypedFunction};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Let's declare the Wasm module.
|
// Let's declare the Wasm module.
|
||||||
@ -38,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
// Note that we don't need to specify the engine/compiler if we want to use
|
||||||
// the default provided by Wasmer.
|
// the default provided by Wasmer.
|
||||||
// You can use `Store::default()` for that.
|
// You can use `Store::default()` for that.
|
||||||
let mut store = Store::new(Cranelift::default());
|
let mut store = Store::default();
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction};
|
use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
// this example is a work in progress:
|
// this example is a work in progress:
|
||||||
// TODO: clean it up and comment it https://github.com/wasmerio/wasmer/issues/1749
|
// TODO: clean it up and comment it https://github.com/wasmerio/wasmer/issues/1749
|
||||||
@ -53,10 +52,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports, wat2wasm, Function, Instance, Module, Store, TableType, Type, TypedFunction, Value,
|
imports, wat2wasm, Function, Instance, Module, Store, TableType, Type, TypedFunction, Value,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
|
|
||||||
/// A function we'll call through a table.
|
/// A function we'll call through a table.
|
||||||
fn host_callback(arg1: i32, arg2: i32) -> i32 {
|
fn host_callback(arg1: i32, arg2: i32) -> i32 {
|
||||||
@ -49,8 +48,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// We set up our store with an engine and a compiler.
|
// Create a Store.
|
||||||
let mut store = Store::new(Cranelift::default());
|
let mut store = Store::default();
|
||||||
// Then compile our Wasm.
|
// Then compile our Wasm.
|
||||||
let module = Module::new(&store, wasm_bytes)?;
|
let module = Module::new(&store, wasm_bytes)?;
|
||||||
let import_object = imports! {};
|
let import_object = imports! {};
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use wasmer::{Module, Store};
|
use wasmer::{Module, Store};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
use wasmer_wasi::{Pipe, WasiEnv};
|
use wasmer_wasi::{Pipe, WasiEnv};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@ -29,10 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let wasm_bytes = std::fs::read(wasm_path)?;
|
let wasm_bytes = std::fs::read(wasm_path)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
//! Ready?
|
//! Ready?
|
||||||
|
|
||||||
use wasmer::{Instance, Module, Store};
|
use wasmer::{Instance, Module, Store};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
use wasmer_wasi::WasiEnv;
|
use wasmer_wasi::WasiEnv;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@ -28,10 +27,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let wasm_bytes = std::fs::read(wasm_path)?;
|
let wasm_bytes = std::fs::read(wasm_path)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use wasmer::{Module, Store};
|
use wasmer::{Module, Store};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
|
||||||
use wasmer_wasi::{Pipe, WasiEnv};
|
use wasmer_wasi::{Pipe, WasiEnv};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@ -25,10 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let wasm_bytes = std::fs::read(wasm_path)?;
|
let wasm_bytes = std::fs::read(wasm_path)?;
|
||||||
|
|
||||||
// Create a Store.
|
// Create a Store.
|
||||||
// Note that we don't need to specify the engine/compiler if we want to use
|
let mut store = Store::default();
|
||||||
// the default provided by Wasmer.
|
|
||||||
// You can use `Store::default()` for that.
|
|
||||||
let mut store = Store::new(Cranelift::default());
|
|
||||||
|
|
||||||
println!("Compiling module...");
|
println!("Compiling module...");
|
||||||
// Let's compile the Wasm module.
|
// Let's compile the Wasm module.
|
||||||
|
Reference in New Issue
Block a user