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

Enhancements in support of the WASI terminal in a browser #2887

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e06bf87
Redesign the API for accessing the contents of a Wasm memory
Amanieu Oct 28, 2021
a8725d3
Cache the JS memory view
Amanieu Nov 3, 2021
56d919e
Use thiserror for MemoryAccessError
Amanieu Nov 3, 2021
3d1b42f
tests/compilers/issues.rs: update broken Memory API usage
epilys Apr 15, 2022
253434b
Add docs/migration_to_3.0.0.md
epilys Apr 26, 2022
765a6cb
api/sys: Replace ImportObject with new type Imports
epilys Apr 14, 2022
5d97730
api/js: Replace ImportObject with new type Imports
epilys Apr 21, 2022
a0418ca
Remove loupe dependency
epilys May 4, 2022
09d5d6d
Fix implementation of ValueType for __wasi_subscription_t
Amanieu May 5, 2022
9fd923c
Multiple changes required to implement the wasmer terminal on the bro…
john-sharratt Oct 28, 2021
40507ff
Redesign the API for accessing the contents of a Wasm memory
Amanieu Oct 28, 2021
6aa4143
Cache the JS memory view
Amanieu Nov 3, 2021
a561f55
Use thiserror for MemoryAccessError
Amanieu Nov 3, 2021
667e273
tests/compilers/issues.rs: update broken Memory API usage
epilys Apr 15, 2022
21e0255
Add docs/migration_to_3.0.0.md
epilys Apr 26, 2022
1e9e973
api/sys: Replace ImportObject with new type Imports
epilys Apr 14, 2022
171c12d
api/js: Replace ImportObject with new type Imports
epilys Apr 21, 2022
45c68e9
Remove loupe dependency
epilys May 4, 2022
0d3ab9b
Fix implementation of ValueType for __wasi_subscription_t
Amanieu May 5, 2022
2ecbe2f
Rename NativeFunc to TypedFunction
silwol Jun 6, 2022
b70f9a0
Merge branch 'wasmer3' into wasmer3-works
john-sharratt Jun 7, 2022
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: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2802](https://github.com/wasmerio/wasmer/pull/2802) Support Dylib engine with Singlepass
- [#2836](https://github.com/wasmerio/wasmer/pull/2836) Improve TrapInformation data stored at runtime
- [#2864](https://github.com/wasmerio/wasmer/pull/2864) `wasmer-cli`: remove wasi-experimental-io-devices from default builds
- #2864 wasmer-cli: remove wasi-experimental-io-devices from default builds
- [#2933](https://github.com/wasmerio/wasmer/pull/2933) Rename NativeFunc to TypedFunction.

### Changed
- #2868 Removed loupe crate dependency

### Fixed
- [#2829](https://github.com/wasmerio/wasmer/pull/2829) Improve error message oriented from JS object.
Expand Down
89 changes: 50 additions & 39 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ serial_test = "0.5"
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-log = { version = "0.2", default-features = false, features = ["trace"] }
tracing = { version = "0.1", default-features = false, features = ["log"] }
Expand Down
4 changes: 2 additions & 2 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri
};
let instance = Instance::new(&module, &import_object).unwrap();
let dyn_f: &Function = instance.exports.get("add").unwrap();
let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap();
let f: TypedFunction<(i32, i32), i32> = dyn_f.native().unwrap();

c.bench_function(&format!("basic static func {}", compiler_name), |b| {
b.iter(|| {
Expand All @@ -50,7 +50,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri
});

let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
let f_many: NativeFunc<
let f_many: TypedFunction<
(
i32,
i32,
Expand Down
95 changes: 95 additions & 0 deletions docs/migration_to_3.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Migrating from Wasmer 2.x to Wasmer 3.0.0

This document will describe the differences between Wasmer 2.x and Wasmer 3.0.0
and provide examples to make migrating to the new API as simple as possible.

## Table of Contents

- [Rationale for changes in 3.0.0](#rationale-for-changes-in-300)
- [How to use Wasmer 3.0.0](#how-to-use-wasmer-300)
- [Installing Wasmer CLI](#installing-wamser-cli)
- [Using Wasmer 3.0.0](#using-wamser-300)
- [Project structure](#project-structure)
- [Differences](#differences)
- [Managing imports](#managing-imports)

## Rationale for changes in 3.0.0

This version introduces the following changes to make the Wasmer API more ergonomic and safe:

1. `ImportsObject` and the traits `Resolver`, `NamedResolver`, etc have been removed and replaced with a single simple type `Imports`. This reduces the complexity of setting up an `Instance`. The helper macro `imports!` can still be used.

## How to use Wasmer 3.0.0

### Installing Wasmer CLI

See [wasmer.io] for installation instructions.

If you already have wasmer installed, run `wasmer self-update`.

Install the latest versions of Wasmer with [wasmer-nightly] or by following the
steps described in the documentation: [Getting Started][getting-started].

### Using Wasmer 3.0.0

See the [examples] to find out how to do specific things in Wasmer 3.0.0.

## Project Structure

TODO

## Differences

### Managing imports

Instantiating a Wasm module is similar to 2.x.x.:

```rust
let import_object: Imports = imports! {
"env" => {
"host_function" => host_function,
},
};
let instance = Instance::new(&module, &import_object).expect("Could not instantiate module.");
```

You can also build the `Imports` object manually:

```rust
let mut import_object: Imports = Imports::new();
import_object.define("env", "host_function", host_function);
let instance = Instance::new(&module, &import_object).expect("Could not instantiate module.");
```

#### `ChainableNamedResolver` is removed

Chaining imports with a trait has been deemed too complex for what it does; it's possible to chain (i.e. override) an `Imports`' contents by using its implementation of `std::iter::Extend` from the Rust standard library:

```rust
let imports1: Imports = todo!();
let mut imports2: Imports = todo!();

imports2.extend(&imports);
// This is equivalent to the following:
// for ((ns, name), ext) in imports1.into_iter() {
// imports2.define(&ns &name, ext);
// }
```

[examples]: https://docs.wasmer.io/integrations/examples
[wasmer]: https://crates.io/crates/wasmer
[wasmer-wasi]: https://crates.io/crates/wasmer-wasi
[wasmer-emscripten]: https://crates.io/crates/wasmer-emscripten
[wasmer-engine]: https://crates.io/crates/wasmer-engine
[wasmer-compiler]: https://crates.io/crates/wasmer-compiler
[wasmer.io]: https://wasmer.io
[wasmer-nightly]: https://github.com/wasmerio/wasmer-nightly/
[getting-started]: https://docs.wasmer.io/ecosystem/wasmer/getting-started
[instance-example]: https://docs.wasmer.io/integrations/examples/instance
[imports-exports-example]: https://docs.wasmer.io/integrations/examples/imports-and-exports
[host-functions-example]: https://docs.wasmer.io/integrations/examples/host-functions
[memory]: https://docs.wasmer.io/integrations/examples/memory
[memory-pointers]: https://docs.wasmer.io/integrations/examples/memory-pointers
[host-functions]: https://docs.wasmer.io/integrations/examples/host-functions
[errors]: https://docs.wasmer.io/integrations/examples/errors
[exit-early]: https://docs.wasmer.io/integrations/examples/exit-early
Loading