improve embedder

This commit is contained in:
vms 2020-06-03 23:09:05 +03:00
parent 44c098ec5b
commit 33aa87fa1c
3 changed files with 9 additions and 7 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
walrus = "0.17.0" 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" options = "0.5.1"
either = "1.5.3" either = "1.5.3"
clap = "2.33.1" clap = "2.33.1"

View File

@ -1,11 +1,13 @@
use crate::custom::WITCustom; use crate::custom::WITCustom;
use std::path::PathBuf;
use walrus::ModuleConfig; use walrus::ModuleConfig;
use wasmer_interface_types::{ use wasmer_wit::{
decoders::wat::{parse, Buffer}, decoders::wat::{parse, Buffer},
encoders::binary::ToBytes, encoders::binary::ToBytes,
}; };
use std::path::PathBuf;
pub struct Config { pub struct Config {
pub in_wasm_path: PathBuf, pub in_wasm_path: PathBuf,
pub wit: String, pub wit: String,

View File

@ -1,8 +1,8 @@
use crate::custom::WIT_SECTION_NAME; use crate::custom::WIT_SECTION_NAME;
use std::path::PathBuf;
use walrus::{IdsToIndices, ModuleConfig}; use walrus::{IdsToIndices, ModuleConfig};
pub fn extract_wit(wasm_file: PathBuf) -> Result<String, String> { pub fn extract_wit(wasm_file: std::path::PathBuf) -> Result<String, String> {
let module = ModuleConfig::new() let module = ModuleConfig::new()
.parse_file(wasm_file) .parse_file(wasm_file)
.map_err(|_| "Failed to parse the Wasm module.".to_string())?; .map_err(|_| "Failed to parse the Wasm module.".to_string())?;
@ -28,7 +28,7 @@ pub fn extract_wit(wasm_file: PathBuf) -> Result<String, String> {
let default_ids = IdsToIndices::default(); let default_ids = IdsToIndices::default();
let wit_section_bytes = sections[0].1.data(&default_ids).into_owned(); 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, wit)) if remainder.is_empty() => wit,
Ok((remainder, _)) => { Ok((remainder, _)) => {
return Err(format!("remainder isn't empty: {:?}", remainder)); return Err(format!("remainder isn't empty: {:?}", remainder));
@ -38,5 +38,5 @@ pub fn extract_wit(wasm_file: PathBuf) -> Result<String, String> {
} }
}; };
Ok(format!("{:?}", wit)) Ok((&wit).to_string())
} }