diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 40a265cff..672a1704c 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -25,6 +25,22 @@ #include #include +enum Version { + /** + * Version cannot be detected or is unknown. + */ + Unknown, + /** + * `wasi_unstable`. + */ + Snapshot0, + /** + * `wasi_snapshot_preview1`. + */ + Snapshot1, +}; +typedef uint8_t Version; + /** * List of export/import kinds. */ @@ -890,4 +906,27 @@ wasmer_import_object_t *wasmer_wasi_generate_import_object(const wasmer_byte_arr const wasmer_wasi_map_dir_entry_t *mapped_dirs, unsigned int mapped_dirs_len); +/** + * Creates a WASI import object. + * + * This function is similar to `wasmer_wasi_generate_import_object` + * except that the first argument describes the WASI version. + */ +wasmer_import_object_t *wasmer_wasi_generate_import_object_for_version(Version version, + const wasmer_byte_array *args, + unsigned int args_len, + const wasmer_byte_array *envs, + unsigned int envs_len, + const wasmer_byte_array *preopened_files, + unsigned int preopened_files_len, + const wasmer_wasi_map_dir_entry_t *mapped_dirs, + unsigned int mapped_dirs_len); + +/** + * Find the version of WASI used by the module. + * + * In case of error, the returned version is `Version::Unknown`. + */ +Version wasmer_wasi_get_version(const wasmer_module_t *module); + #endif /* WASMER_H */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index b437edd4b..d293c817e 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -25,6 +25,15 @@ #include #include +enum class Version : uint8_t { + /// Version cannot be detected or is unknown. + Unknown, + /// `wasi_unstable`. + Snapshot0, + /// `wasi_snapshot_preview1`. + Snapshot1, +}; + /// List of export/import kinds. enum class wasmer_import_export_kind : uint32_t { WASM_FUNCTION = 0, @@ -702,6 +711,25 @@ wasmer_import_object_t *wasmer_wasi_generate_import_object(const wasmer_byte_arr const wasmer_wasi_map_dir_entry_t *mapped_dirs, unsigned int mapped_dirs_len); +/// Creates a WASI import object. +/// +/// This function is similar to `wasmer_wasi_generate_import_object` +/// except that the first argument describes the WASI version. +wasmer_import_object_t *wasmer_wasi_generate_import_object_for_version(Version version, + const wasmer_byte_array *args, + unsigned int args_len, + const wasmer_byte_array *envs, + unsigned int envs_len, + const wasmer_byte_array *preopened_files, + unsigned int preopened_files_len, + const wasmer_wasi_map_dir_entry_t *mapped_dirs, + unsigned int mapped_dirs_len); + +/// Find the version of WASI used by the module. +/// +/// In case of error, the returned version is `Version::Unknown`. +Version wasmer_wasi_get_version(const wasmer_module_t *module); + } // extern "C" #endif // WASMER_H