mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-18 09:21:29 +00:00
reexport interfaces from wit-parser
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -734,7 +734,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fce-wit-interfaces"
|
name = "fce-wit-interfaces"
|
||||||
version = "0.1.29"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"multimap",
|
"multimap",
|
||||||
"wasmer-interface-types-fl",
|
"wasmer-interface-types-fl",
|
||||||
@ -742,7 +742,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fce-wit-parser"
|
name = "fce-wit-parser"
|
||||||
version = "0.2.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"fce-wit-interfaces",
|
"fce-wit-interfaces",
|
||||||
|
@ -11,7 +11,7 @@ name = "fce_wit_generator"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fce-wit-parser = { path = "../wit-parser", version = "0.2.0"}
|
fce-wit-parser = { path = "../wit-parser", version = "0.4.0"}
|
||||||
fluence-sdk-wit = "=0.5.0"
|
fluence-sdk-wit = "=0.5.0"
|
||||||
|
|
||||||
walrus = "0.18.0"
|
walrus = "0.18.0"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fce-wit-interfaces"
|
name = "fce-wit-interfaces"
|
||||||
description = "Fluence FCE interface type helper crate"
|
description = "Fluence FCE interface type helper crate"
|
||||||
version = "0.1.29"
|
version = "0.2.0"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fce-wit-parser"
|
name = "fce-wit-parser"
|
||||||
description = "Fluence FCE interface type helper crate"
|
description = "Fluence FCE interface type helper crate"
|
||||||
version = "0.2.0"
|
version = "0.4.0"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@ -11,7 +11,7 @@ name = "fce_wit_parser"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fce-wit-interfaces = { path = "../wit-interfaces", version = "0.1.29" }
|
fce-wit-interfaces = { path = "../wit-interfaces", version = "0.2.0" }
|
||||||
|
|
||||||
anyhow = "1.0.31"
|
anyhow = "1.0.31"
|
||||||
walrus = "0.18.0"
|
walrus = "0.18.0"
|
||||||
|
@ -22,22 +22,39 @@ pub use wit::*;
|
|||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::WITParserError;
|
use crate::WITParserError;
|
||||||
|
|
||||||
|
use fce_wit_interfaces::FCEWITInterfaces;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn module_interface<P>(module_path: P) -> Result<ServiceInterface>
|
pub fn module_interface<P>(module_path: P) -> Result<ServiceInterface>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
use fce_wit_interfaces::FCEWITInterfaces;
|
create_fce_it_with(module_path, |it| get_interface(&it))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_raw_interface<P>(module_path: P) -> Result<FCEModuleInterface>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
|
create_fce_it_with(module_path, |it| get_raw_interface(&it))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_fce_it_with<P, T>(
|
||||||
|
module_path: P,
|
||||||
|
transformer: impl FnOnce(FCEWITInterfaces<'_>) -> Result<T>,
|
||||||
|
) -> Result<T>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
let module = walrus::ModuleConfig::new()
|
let module = walrus::ModuleConfig::new()
|
||||||
.parse_file(module_path)
|
.parse_file(module_path)
|
||||||
.map_err(WITParserError::CorruptedWasmFile)?;
|
.map_err(WITParserError::CorruptedWasmFile)?;
|
||||||
|
|
||||||
let raw_custom_section = extract_custom_section(&module)?;
|
let raw_custom_section = extract_custom_section(&module)?;
|
||||||
let custom_section_bytes = raw_custom_section.as_ref();
|
let custom_section_bytes = raw_custom_section.as_ref();
|
||||||
let wit = extract_wit_from_bytes(custom_section_bytes)?;
|
let wit = extract_wit_from_bytes(custom_section_bytes)?;
|
||||||
|
|
||||||
let fce_interface = FCEWITInterfaces::new(wit);
|
let fce_interface = FCEWITInterfaces::new(wit);
|
||||||
|
|
||||||
get_interface(&fce_interface)
|
transformer(fce_interface)
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ use serde::Deserialize;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub type RecordTypes = HashMap<u64, Rc<IRecordType>>;
|
pub type FCERecordTypes = HashMap<u64, Rc<IRecordType>>;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||||
pub struct FCEFunctionSignature {
|
pub struct FCEFunctionSignature {
|
||||||
@ -38,22 +38,27 @@ pub struct FCEFunctionSignature {
|
|||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
|
#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
|
||||||
pub struct FCEModuleInterface {
|
pub struct FCEModuleInterface {
|
||||||
pub record_types: RecordTypes,
|
pub record_types: FCERecordTypes,
|
||||||
pub function_signatures: Vec<FCEFunctionSignature>,
|
pub function_signatures: Vec<FCEFunctionSignature>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_interface(wit: &FCEWITInterfaces<'_>) -> Result<ServiceInterface> {
|
pub fn get_interface(fce_it_interface: &FCEWITInterfaces<'_>) -> Result<ServiceInterface> {
|
||||||
let function_signatures = get_exports(wit)?;
|
let fce_interface = get_raw_interface(fce_it_interface)?;
|
||||||
let record_types = extract_record_types(wit);
|
let service_interface = into_service_interface(fce_interface);
|
||||||
|
|
||||||
|
Ok(service_interface)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_raw_interface(fce_it_interface: &FCEWITInterfaces<'_>) -> Result<FCEModuleInterface> {
|
||||||
|
let function_signatures = get_exports(fce_it_interface)?;
|
||||||
|
let record_types = extract_record_types(fce_it_interface);
|
||||||
|
|
||||||
let fce_interface = FCEModuleInterface {
|
let fce_interface = FCEModuleInterface {
|
||||||
record_types,
|
record_types,
|
||||||
function_signatures,
|
function_signatures,
|
||||||
};
|
};
|
||||||
|
|
||||||
let service_interface = into_service_interface(fce_interface);
|
Ok(fce_interface)
|
||||||
|
|
||||||
Ok(service_interface)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_exports(wit: &FCEWITInterfaces<'_>) -> Result<Vec<FCEFunctionSignature>> {
|
fn get_exports(wit: &FCEWITInterfaces<'_>) -> Result<Vec<FCEFunctionSignature>> {
|
||||||
@ -97,7 +102,7 @@ fn get_exports(wit: &FCEWITInterfaces<'_>) -> Result<Vec<FCEFunctionSignature>>
|
|||||||
.collect::<Result<Vec<FCEFunctionSignature>>>()
|
.collect::<Result<Vec<FCEFunctionSignature>>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_record_types(wit: &FCEWITInterfaces<'_>) -> RecordTypes {
|
fn extract_record_types(wit: &FCEWITInterfaces<'_>) -> FCERecordTypes {
|
||||||
use fce_wit_interfaces::WITAstType;
|
use fce_wit_interfaces::WITAstType;
|
||||||
|
|
||||||
let (record_types_by_id, _) = wit.types().fold(
|
let (record_types_by_id, _) = wit.types().fold(
|
||||||
@ -158,7 +163,7 @@ pub(crate) fn into_service_interface(fce_interface: FCEModuleInterface) -> Servi
|
|||||||
|
|
||||||
fn serialize_function_signature(
|
fn serialize_function_signature(
|
||||||
signature: FCEFunctionSignature,
|
signature: FCEFunctionSignature,
|
||||||
record_types: &RecordTypes,
|
record_types: &FCERecordTypes,
|
||||||
) -> FunctionSignature {
|
) -> FunctionSignature {
|
||||||
let arguments = signature
|
let arguments = signature
|
||||||
.arguments
|
.arguments
|
||||||
@ -182,7 +187,7 @@ fn serialize_function_signature(
|
|||||||
fn serialize_record_type<'a, 'b>(
|
fn serialize_record_type<'a, 'b>(
|
||||||
id: u64,
|
id: u64,
|
||||||
record: Rc<IRecordType>,
|
record: Rc<IRecordType>,
|
||||||
record_types: &RecordTypes,
|
record_types: &FCERecordTypes,
|
||||||
) -> RecordType {
|
) -> RecordType {
|
||||||
let fields = record
|
let fields = record
|
||||||
.fields
|
.fields
|
||||||
@ -197,7 +202,7 @@ fn serialize_record_type<'a, 'b>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn itype_text_view(arg_ty: &IType, record_types: &RecordTypes) -> String {
|
fn itype_text_view(arg_ty: &IType, record_types: &FCERecordTypes) -> String {
|
||||||
match arg_ty {
|
match arg_ty {
|
||||||
IType::Record(record_type_id) => {
|
IType::Record(record_type_id) => {
|
||||||
// unwrap is safe because FaaSInterface here is well-formed
|
// unwrap is safe because FaaSInterface here is well-formed
|
||||||
|
@ -34,11 +34,30 @@ pub use errors::WITParserError;
|
|||||||
|
|
||||||
pub use deleter::delete_wit_section;
|
pub use deleter::delete_wit_section;
|
||||||
pub use deleter::delete_wit_section_from_file;
|
pub use deleter::delete_wit_section_from_file;
|
||||||
|
|
||||||
pub use embedder::embed_wit;
|
pub use embedder::embed_wit;
|
||||||
pub use embedder::embed_text_wit;
|
pub use embedder::embed_text_wit;
|
||||||
|
|
||||||
pub use extractor::extract_wit_from_module;
|
pub use extractor::extract_wit_from_module;
|
||||||
pub use extractor::extract_version_from_module;
|
pub use extractor::extract_version_from_module;
|
||||||
pub use extractor::extract_text_wit;
|
pub use extractor::extract_text_wit;
|
||||||
pub use extractor::module_interface;
|
pub use extractor::module_interface;
|
||||||
|
pub use extractor::module_raw_interface;
|
||||||
|
|
||||||
|
pub mod interface {
|
||||||
|
pub use crate::extractor::ServiceInterface;
|
||||||
|
pub use crate::extractor::RecordType;
|
||||||
|
pub use crate::extractor::FunctionSignature;
|
||||||
|
|
||||||
|
pub use crate::extractor::FCEModuleInterface;
|
||||||
|
pub use crate::extractor::FCERecordTypes;
|
||||||
|
pub use crate::extractor::FCEFunctionSignature;
|
||||||
|
pub mod it {
|
||||||
|
pub use wasmer_wit::IType;
|
||||||
|
pub use wasmer_wit::ast::FunctionArg as IFunctionArg;
|
||||||
|
pub use wasmer_wit::IRecordType;
|
||||||
|
pub use wasmer_wit::IRecordFieldType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) type Result<T> = std::result::Result<T, WITParserError>;
|
pub(crate) type Result<T> = std::result::Result<T, WITParserError>;
|
||||||
|
@ -12,8 +12,8 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fce-module-info-parser = { path = "../crates/module-info-parser", version = "0.1.0" }
|
fce-module-info-parser = { path = "../crates/module-info-parser", version = "0.1.0" }
|
||||||
fce-wit-interfaces = { path = "../crates/wit-interfaces", version = "0.1.29" }
|
fce-wit-interfaces = { path = "../crates/wit-interfaces", version = "0.2.0" }
|
||||||
fce-wit-parser = { path = "../crates/wit-parser", version = "0.2.0" }
|
fce-wit-parser = { path = "../crates/wit-parser", version = "0.4.0" }
|
||||||
fce-wit-generator = { path = "../crates/wit-generator", version = "0.2.0" }
|
fce-wit-generator = { path = "../crates/wit-generator", version = "0.2.0" }
|
||||||
fce-utils = { path = "../crates/utils", version = "0.1.29" }
|
fce-utils = { path = "../crates/utils", version = "0.1.29" }
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fce-wit-generator = { path = "../../crates/wit-generator", version = "0.2.0" }
|
fce-wit-generator = { path = "../../crates/wit-generator", version = "0.2.0" }
|
||||||
fce-wit-parser = { path = "../../crates/wit-parser", version = "0.2.0" }
|
fce-wit-parser = { path = "../../crates/wit-parser", version = "0.4.0" }
|
||||||
fce-module-info-parser = { path = "../../crates/module-info-parser", version = "0.1.0" }
|
fce-module-info-parser = { path = "../../crates/module-info-parser", version = "0.1.0" }
|
||||||
|
|
||||||
semver = "0.11.0"
|
semver = "0.11.0"
|
||||||
|
@ -145,18 +145,17 @@ impl REPL {
|
|||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
// TODO: add support of call parameters
|
// TODO: add support of call parameters
|
||||||
let result = match self.app_service.call_module(
|
let result =
|
||||||
module_name,
|
match self
|
||||||
func_name,
|
.app_service
|
||||||
module_arg,
|
.call_module(module_name, func_name, module_arg, <_>::default())
|
||||||
<_>::default(),
|
{
|
||||||
) {
|
Ok(result) => {
|
||||||
Ok(result) => {
|
let elapsed_time = start.elapsed();
|
||||||
let elapsed_time = start.elapsed();
|
format!("result: {:?}\n elapsed time: {:?}", result, elapsed_time)
|
||||||
format!("result: {:?}\n elapsed time: {:?}", result, elapsed_time)
|
}
|
||||||
}
|
Err(e) => format!("call failed with: {}", e),
|
||||||
Err(e) => format!("call failed with: {}", e),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user