Skip to content

Commit

Permalink
Merge #1029
Browse files Browse the repository at this point in the history
1029: feat(wasi) Add the “floating” `WasiVersion::Latest` version. r=Hywan a=Hywan

In addition to `Snapshot0` and `Snapshot1`, I believe it is an
interesting API to provide the `Latest` version, so that the user can
write:

```rust
generate_import_object_for_version(WasiVersion::Latest, …);
```

This is a way to ensure that modules will run only if they come with
the latest WASI version (in case of security issues for instance), by
just updating the runtime.

Note that it can be dangerous if not used carefully, but we assume the
user knows what it does by sticking on a specific “floating” version.

Also note that the `Latest` version is never returned by any API. It
is provided only by the user.

Co-authored-by: Ivan Enderlin <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored Dec 4, 2019
2 parents 7aa044e + 9d42af8 commit e7b3931
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#1029](https://github.com/wasmerio/wasmer/pull/1029) Add the “floating” `WasiVersion::Latest` version.
- [#1006](https://github.com/wasmerio/wasmer/pull/1006) Fix minor panic issue when `wasmer::compile_with` called with llvm backend
- [#1009](https://github.com/wasmerio/wasmer/pull/1009) Enable LLVM verifier for all tests, add new llvm-backend-tests crate.
- [#1022](https://github.com/wasmerio/wasmer/pull/1022) Add caching support for Singlepass backend.
Expand Down
4 changes: 3 additions & 1 deletion lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ pub fn generate_import_object_for_version(
WasiVersion::Snapshot0 => {
generate_import_object_snapshot0(args, envs, preopened_files, mapped_dirs)
}
WasiVersion::Snapshot1 => generate_import_object(args, envs, preopened_files, mapped_dirs),
WasiVersion::Snapshot1 | WasiVersion::Latest => {
generate_import_object(args, envs, preopened_files, mapped_dirs)
}
}
}

Expand Down
19 changes: 16 additions & 3 deletions lib/wasi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ pub fn is_wasi_module(module: &Module) -> bool {
get_wasi_version(module).is_some()
}

/// The version of WASI. This is determined by the namespace string
/// The version of WASI. This is determined by the imports namespace
/// string.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum WasiVersion {
/// "wasi_unstable"
/// `wasi_unstable`.
Snapshot0,
/// "wasi_snapshot_preview1"
/// `wasi_snapshot_preview1`.
Snapshot1,

/// Latest version.
///
/// It's a “floating” version, i.e. it's an alias to the latest
/// version (for the moment, `Snapshot1`). Using this version is a
/// way to ensure that modules will run only if they come with the
/// latest WASI version (in case of security issues for instance),
/// by just updating the runtime.
///
/// Note that this version is never returned by an API. It is
/// provided only by the user.
Latest,
}

/// Detect the version of WASI being used from the namespace
Expand Down

0 comments on commit e7b3931

Please sign in to comment.