From 33aa87fa1ce391d5f8e558faa7fc0a0f1940976e Mon Sep 17 00:00:00 2001 From: vms Date: Wed, 3 Jun 2020 23:09:05 +0300 Subject: [PATCH] improve embedder --- wit_embedder/Cargo.toml | 2 +- wit_embedder/src/embedder.rs | 6 ++++-- wit_embedder/src/extracter.rs | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/wit_embedder/Cargo.toml b/wit_embedder/Cargo.toml index 9547ffda..407593ef 100644 --- a/wit_embedder/Cargo.toml +++ b/wit_embedder/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] walrus = "0.17.0" -wasmer-interface-types = { git = "https://github.com/fluencelabs/interface-types", branch = "master"} +wasmer-wit = { package = "wasmer-interface-types", git = "https://github.com/fluencelabs/interface-types", branch = "master"} options = "0.5.1" either = "1.5.3" clap = "2.33.1" diff --git a/wit_embedder/src/embedder.rs b/wit_embedder/src/embedder.rs index ce6db36a..fa14ce9d 100644 --- a/wit_embedder/src/embedder.rs +++ b/wit_embedder/src/embedder.rs @@ -1,11 +1,13 @@ use crate::custom::WITCustom; -use std::path::PathBuf; + use walrus::ModuleConfig; -use wasmer_interface_types::{ +use wasmer_wit::{ decoders::wat::{parse, Buffer}, encoders::binary::ToBytes, }; +use std::path::PathBuf; + pub struct Config { pub in_wasm_path: PathBuf, pub wit: String, diff --git a/wit_embedder/src/extracter.rs b/wit_embedder/src/extracter.rs index 49c98f46..d8a4e073 100644 --- a/wit_embedder/src/extracter.rs +++ b/wit_embedder/src/extracter.rs @@ -1,8 +1,8 @@ use crate::custom::WIT_SECTION_NAME; -use std::path::PathBuf; + use walrus::{IdsToIndices, ModuleConfig}; -pub fn extract_wit(wasm_file: PathBuf) -> Result { +pub fn extract_wit(wasm_file: std::path::PathBuf) -> Result { let module = ModuleConfig::new() .parse_file(wasm_file) .map_err(|_| "Failed to parse the Wasm module.".to_string())?; @@ -28,7 +28,7 @@ pub fn extract_wit(wasm_file: PathBuf) -> Result { let default_ids = IdsToIndices::default(); let wit_section_bytes = sections[0].1.data(&default_ids).into_owned(); - let wit = match wasmer_interface_types::decoders::binary::parse::<()>(&wit_section_bytes) { + let wit = match wasmer_wit::decoders::binary::parse::<()>(&wit_section_bytes) { Ok((remainder, wit)) if remainder.is_empty() => wit, Ok((remainder, _)) => { return Err(format!("remainder isn't empty: {:?}", remainder)); @@ -38,5 +38,5 @@ pub fn extract_wit(wasm_file: PathBuf) -> Result { } }; - Ok(format!("{:?}", wit)) + Ok((&wit).to_string()) }