mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-12 22:41:26 +00:00
reexport interfaces from wit-parser
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "fce-wit-parser"
|
||||
description = "Fluence FCE interface type helper crate"
|
||||
version = "0.2.0"
|
||||
version = "0.4.0"
|
||||
authors = ["Fluence Labs"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
@ -11,7 +11,7 @@ name = "fce_wit_parser"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[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"
|
||||
walrus = "0.18.0"
|
||||
|
@ -22,22 +22,39 @@ pub use wit::*;
|
||||
|
||||
use crate::Result;
|
||||
use crate::WITParserError;
|
||||
|
||||
use fce_wit_interfaces::FCEWITInterfaces;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn module_interface<P>(module_path: P) -> Result<ServiceInterface>
|
||||
where
|
||||
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()
|
||||
.parse_file(module_path)
|
||||
.map_err(WITParserError::CorruptedWasmFile)?;
|
||||
|
||||
let raw_custom_section = extract_custom_section(&module)?;
|
||||
let custom_section_bytes = raw_custom_section.as_ref();
|
||||
let wit = extract_wit_from_bytes(custom_section_bytes)?;
|
||||
|
||||
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::rc::Rc;
|
||||
|
||||
pub type RecordTypes = HashMap<u64, Rc<IRecordType>>;
|
||||
pub type FCERecordTypes = HashMap<u64, Rc<IRecordType>>;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub struct FCEFunctionSignature {
|
||||
@ -38,22 +38,27 @@ pub struct FCEFunctionSignature {
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
|
||||
pub struct FCEModuleInterface {
|
||||
pub record_types: RecordTypes,
|
||||
pub record_types: FCERecordTypes,
|
||||
pub function_signatures: Vec<FCEFunctionSignature>,
|
||||
}
|
||||
|
||||
pub fn get_interface(wit: &FCEWITInterfaces<'_>) -> Result<ServiceInterface> {
|
||||
let function_signatures = get_exports(wit)?;
|
||||
let record_types = extract_record_types(wit);
|
||||
pub fn get_interface(fce_it_interface: &FCEWITInterfaces<'_>) -> Result<ServiceInterface> {
|
||||
let fce_interface = get_raw_interface(fce_it_interface)?;
|
||||
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 {
|
||||
record_types,
|
||||
function_signatures,
|
||||
};
|
||||
|
||||
let service_interface = into_service_interface(fce_interface);
|
||||
|
||||
Ok(service_interface)
|
||||
Ok(fce_interface)
|
||||
}
|
||||
|
||||
fn get_exports(wit: &FCEWITInterfaces<'_>) -> Result<Vec<FCEFunctionSignature>> {
|
||||
@ -97,7 +102,7 @@ fn get_exports(wit: &FCEWITInterfaces<'_>) -> 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;
|
||||
|
||||
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(
|
||||
signature: FCEFunctionSignature,
|
||||
record_types: &RecordTypes,
|
||||
record_types: &FCERecordTypes,
|
||||
) -> FunctionSignature {
|
||||
let arguments = signature
|
||||
.arguments
|
||||
@ -182,7 +187,7 @@ fn serialize_function_signature(
|
||||
fn serialize_record_type<'a, 'b>(
|
||||
id: u64,
|
||||
record: Rc<IRecordType>,
|
||||
record_types: &RecordTypes,
|
||||
record_types: &FCERecordTypes,
|
||||
) -> RecordType {
|
||||
let fields = record
|
||||
.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 {
|
||||
IType::Record(record_type_id) => {
|
||||
// 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_from_file;
|
||||
|
||||
pub use embedder::embed_wit;
|
||||
pub use embedder::embed_text_wit;
|
||||
|
||||
pub use extractor::extract_wit_from_module;
|
||||
pub use extractor::extract_version_from_module;
|
||||
pub use extractor::extract_text_wit;
|
||||
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>;
|
||||
|
Reference in New Issue
Block a user