Skip to content

Commit

Permalink
feat(runtime-c-api) Support WasiVersion::Latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Dec 4, 2019
1 parent f0f0657 commit 4ef799f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## **[Unreleased]**

- [#1030](https://github.com/wasmerio/wasmer/pull/1030) Ability to generate `ImportObject` for a specific version WASI version with the C API.
- [#1028](https://github.com/wasmerio/wasmer/pull/1028) Introduce strict/non-strict modes for `get_wasi_version`
- [#1029](https://github.com/wasmerio/wasmer/pull/1029) Add the “floating” `WasiVersion::Latest` version.
- [#1030](https://github.com/wasmerio/wasmer/pull/1030) Ability to generate `ImportObject` for a specific version WASI version with the C API.
- [#1028](https://github.com/wasmerio/wasmer/pull/1028) Introduce strict/non-strict modes for `get_wasi_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.
Expand Down
24 changes: 17 additions & 7 deletions lib/runtime-c-api/src/import/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ use wasmer_wasi as wasi;
pub enum Version {
/// Version cannot be detected or is unknown.
Unknown = 0,

/// Latest version. See `wasmer_wasi::WasiVersion::Latest` to
/// leran more.
Latest = 1,

/// `wasi_unstable`.
Snapshot0 = 1,
Snapshot0 = 2,

/// `wasi_snapshot_preview1`.
Snapshot1 = 2,
Snapshot1 = 3,
}

impl From<c_uchar> for Version {
fn from(value: c_uchar) -> Self {
match value {
1 => Self::Snapshot0,
2 => Self::Snapshot1,
1 => Self::Latest,
2 => Self::Snapshot0,
3 => Self::Snapshot1,
_ => Self::Unknown,
}
}
Expand Down Expand Up @@ -66,7 +73,7 @@ pub unsafe extern "C" fn wasmer_wasi_generate_import_object(
let mapped_dir_list = get_slice_checked(mapped_dirs, mapped_dirs_len as usize);

wasmer_wasi_generate_import_object_inner(
Version::Snapshot1,
Version::Latest,
arg_list,
env_list,
preopened_file_list,
Expand Down Expand Up @@ -123,6 +130,7 @@ pub unsafe extern "C" fn wasmer_wasi_get_version(module: *const wasmer_module_t)
Some(version) => match version {
wasi::WasiVersion::Snapshot0 => Version::Snapshot0,
wasi::WasiVersion::Snapshot1 => Version::Snapshot1,
wasi::WasiVersion::Latest => Version::Latest,
},
None => Version::Unknown,
}
Expand Down Expand Up @@ -151,6 +159,7 @@ fn wasmer_wasi_generate_import_object_inner(
.collect::<Result<Vec<_>, _>>()?;

let version = match version {
Version::Latest => wasi::WasiVersion::Latest,
Version::Snapshot0 => wasi::WasiVersion::Snapshot0,
Version::Snapshot1 => wasi::WasiVersion::Snapshot1,
_ => panic!("Version {:?} is invalid.", version),
Expand Down Expand Up @@ -186,7 +195,8 @@ mod tests {
#[test]
fn test_versions_from_uint() {
assert_eq!(Version::Unknown, 0.into());
assert_eq!(Version::Snapshot0, 1.into());
assert_eq!(Version::Snapshot1, 2.into());
assert_eq!(Version::Latest, 1.into());
assert_eq!(Version::Snapshot0, 2.into());
assert_eq!(Version::Snapshot1, 3.into());
}
}
9 changes: 7 additions & 2 deletions lib/runtime-c-api/wasmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ enum Version {
* Version cannot be detected or is unknown.
*/
Unknown = 0,
/**
* Latest version. See `wasmer_wasi::WasiVersion::Latest` to
* leran more.
*/
Latest = 1,
/**
* `wasi_unstable`.
*/
Snapshot0 = 1,
Snapshot0 = 2,
/**
* `wasi_snapshot_preview1`.
*/
Snapshot1 = 2,
Snapshot1 = 3,
};
typedef uint8_t Version;

Expand Down
7 changes: 5 additions & 2 deletions lib/runtime-c-api/wasmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
enum class Version : uint8_t {
/// Version cannot be detected or is unknown.
Unknown = 0,
/// Latest version. See `wasmer_wasi::WasiVersion::Latest` to
/// leran more.
Latest = 1,
/// `wasi_unstable`.
Snapshot0 = 1,
Snapshot0 = 2,
/// `wasi_snapshot_preview1`.
Snapshot1 = 2,
Snapshot1 = 3,
};

/// List of export/import kinds.
Expand Down

0 comments on commit 4ef799f

Please sign in to comment.