From a79beede727a28ccdd26456e4e0cd17d7cd9c03f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 2 Dec 2019 15:46:08 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat(wasi)=20Add=20the=20=E2=80=9Cvolatile?= =?UTF-8?q?=E2=80=9D=20`WasiVersion::Latest`=20version.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/wasi/src/lib.rs | 4 +++- lib/wasi/src/utils.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index ca439bfdbfe..712bfa4c737 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -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) + } } } diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index b19a404884b..9774abe20e8 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -7,13 +7,16 @@ 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 (for the moment, an alias to `Snapshot1`). + Latest, } /// Detect the version of WASI being used from the namespace From c916f0edaaf3520902a2c34c37c6b8ce454cf810 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 2 Dec 2019 15:55:38 +0100 Subject: [PATCH 2/3] doc(changelog) Add #1029. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1de67bf893..8340f947d4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. - [#1004](https://github.com/wasmerio/wasmer/pull/1004) Add the Auto backend to enable to adapt backend usage depending on wasm file executed. From c12dd859bbc3077bb358bd74a348d921a154d4b0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 4 Dec 2019 14:12:30 +0100 Subject: [PATCH 3/3] doc(wasi) Improve documentation of `WasiVersion::Latest`. --- lib/wasi/src/utils.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/wasi/src/utils.rs b/lib/wasi/src/utils.rs index 9774abe20e8..d57510eb5f3 100644 --- a/lib/wasi/src/utils.rs +++ b/lib/wasi/src/utils.rs @@ -15,7 +15,17 @@ pub enum WasiVersion { Snapshot0, /// `wasi_snapshot_preview1`. Snapshot1, - /// Latest version (for the moment, an alias to `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, }