mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-23 03:31:37 +00:00
bump rust-sdk version
This commit is contained in:
118
Cargo.lock
generated
118
Cargo.lock
generated
@ -2,18 +2,18 @@
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.12.2"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "602d785912f476e480434627e8732e6766b760c045bbf897d9dfaa9f4fbd399c"
|
||||
checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072"
|
||||
dependencies = [
|
||||
"gimli 0.21.0",
|
||||
"gimli 0.22.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler32"
|
||||
version = "1.1.0"
|
||||
name = "adler"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d"
|
||||
checksum = "ccc9a9dd069569f212bc4330af9f17c4afb5e8ce185e83dbb14f1349dda18b10"
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
@ -61,9 +61,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.49"
|
||||
version = "0.3.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05100821de9e028f12ae3d189176b41ee198341eb8f369956407fea2f5cc666c"
|
||||
checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cfg-if",
|
||||
@ -112,9 +112,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.56"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77c1f1d60091c1b73e2b1f4560ab419204b178e625fa945ded7b660becd2bd46"
|
||||
checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
@ -370,7 +370,7 @@ dependencies = [
|
||||
name = "fce"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fce_wit_interfaces",
|
||||
"fce-wit-interfaces",
|
||||
"log",
|
||||
"multimap",
|
||||
"parity-wasm",
|
||||
@ -380,7 +380,15 @@ dependencies = [
|
||||
"wasmer-runtime",
|
||||
"wasmer-runtime-core",
|
||||
"wasmer-wasi",
|
||||
"wit_parser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fce-wit-interfaces"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"multimap",
|
||||
"wasmer-interface-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -392,16 +400,8 @@ dependencies = [
|
||||
"failure",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wit",
|
||||
"wit_parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fce_wit_interfaces"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"multimap",
|
||||
"wasmer-interface-types",
|
||||
"wit-generator",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -420,6 +420,20 @@ dependencies = [
|
||||
"wasmer-wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#d3f5a15730f97f642f07d64f50efab061218cc9f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
"uuid",
|
||||
"wasmer-interface-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.55"
|
||||
@ -479,9 +493,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.21.0"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
|
||||
checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
@ -494,9 +508,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.14"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
|
||||
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@ -586,9 +600,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.71"
|
||||
version = "0.2.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
|
||||
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
@ -632,20 +646,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.5.4"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
|
||||
checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.3.7"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
|
||||
checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f"
|
||||
dependencies = [
|
||||
"adler32",
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -949,9 +963,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.4.0"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
|
||||
checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
@ -1339,27 +1353,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "wit"
|
||||
name = "wit-generator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"walrus",
|
||||
"wasmer-interface-types",
|
||||
"wit-support",
|
||||
"wit_parser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-support"
|
||||
version = "0.2.0"
|
||||
name = "wit-parser"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn",
|
||||
"uuid",
|
||||
"anyhow",
|
||||
"fce-wit-interfaces",
|
||||
"walrus",
|
||||
"wasmer-interface-types",
|
||||
"wasmer-runtime-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1369,16 +1382,5 @@ dependencies = [
|
||||
"clap",
|
||||
"exitfailure",
|
||||
"failure",
|
||||
"wit_parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit_parser"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"fce_wit_interfaces",
|
||||
"walrus",
|
||||
"wasmer-interface-types",
|
||||
"wasmer-runtime-core",
|
||||
"wit-parser",
|
||||
]
|
||||
|
@ -1,14 +1,15 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/fce_wit_interfaces",
|
||||
"crates/wit_parser",
|
||||
"crates/fce-wit-interfaces",
|
||||
"crates/wit-generator",
|
||||
"crates/wit-parser",
|
||||
"engine",
|
||||
"examples/ipfs_node",
|
||||
"examples/ipfs_node/wasm/ipfs_node",
|
||||
"examples/ipfs_node/wasm/ipfs_rpc",
|
||||
"examples/simple_greeting",
|
||||
"fluence-faas",
|
||||
"tools/fce_cli",
|
||||
"tools/fce-cli",
|
||||
"tools/wit_embedder",
|
||||
]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "fce_wit_interfaces"
|
||||
name = "fce-wit-interfaces"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
13
crates/wit-generator/Cargo.toml
Normal file
13
crates/wit-generator/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "wit-generator"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
wit-parser = { path = "../wit-parser" }
|
||||
walrus = "0.17.0"
|
||||
fluence-sdk-wit = { git = "https://github.com/fluencelabs/rust-sdk" }
|
||||
wasmer-wit = { package = "wasmer-interface-types", git = "http://github.com/fluencelabs/interface-types", branch = "master", features = ["serde"] }
|
||||
serde = { version = "1.0.110", features = ["derive"] }
|
||||
serde_json = "1.0.56"
|
109
crates/wit-generator/src/lib.rs
Normal file
109
crates/wit-generator/src/lib.rs
Normal file
@ -0,0 +1,109 @@
|
||||
mod wit_generator;
|
||||
mod wasm_ast_extractor;
|
||||
|
||||
use wit_generator::WITGenerator;
|
||||
|
||||
pub use fluence_sdk_wit::FCEAst;
|
||||
use wasmer_wit::ast::Interfaces;
|
||||
|
||||
pub fn embed_wit(path: std::path::PathBuf) {
|
||||
let ast_set = wasm_ast_extractor::wasm_ast_extractor(path.clone()).unwrap();
|
||||
let interfaces = generate_interfaces(&ast_set);
|
||||
wit_parser::embed_wit(path.clone(), path.clone(), &interfaces).unwrap();
|
||||
}
|
||||
|
||||
fn generate_interfaces(ast_set: &[FCEAst]) -> Interfaces<'_> {
|
||||
let mut interfaces = Interfaces::default();
|
||||
generate_default_api(&mut interfaces);
|
||||
|
||||
for ast in ast_set {
|
||||
ast.generate_wit(&mut interfaces);
|
||||
}
|
||||
|
||||
interfaces
|
||||
}
|
||||
|
||||
fn generate_default_api(interfaces: &mut Interfaces) {
|
||||
use wasmer_wit::ast::Type;
|
||||
use wasmer_wit::ast::Export;
|
||||
use wasmer_wit::types::InterfaceType as IType;
|
||||
|
||||
let allocate_inputs = vec![IType::I32];
|
||||
let allocate_outputs = vec![IType::I32];
|
||||
let allocate_func_type = Type::Function {
|
||||
inputs: allocate_inputs,
|
||||
outputs: allocate_outputs,
|
||||
};
|
||||
|
||||
let deallocate_inputs = vec![IType::I32, IType::I32];
|
||||
let deallocate_outputs = vec![];
|
||||
let deallocate_func_type = Type::Function {
|
||||
inputs: deallocate_inputs,
|
||||
outputs: deallocate_outputs,
|
||||
};
|
||||
|
||||
let get_result_inputs = vec![];
|
||||
let get_result_outputs = vec![IType::I32];
|
||||
let get_result_size_func_type = Type::Function {
|
||||
inputs: get_result_inputs.clone(),
|
||||
outputs: get_result_outputs.clone(),
|
||||
};
|
||||
let get_result_ptr_func_type = Type::Function {
|
||||
inputs: get_result_inputs,
|
||||
outputs: get_result_outputs,
|
||||
};
|
||||
|
||||
let set_result_inputs = vec![IType::I32];
|
||||
let set_result_outputs = vec![];
|
||||
let set_result_size_func_type = Type::Function {
|
||||
inputs: set_result_inputs.clone(),
|
||||
outputs: set_result_outputs.clone(),
|
||||
};
|
||||
let set_result_ptr_func_type = Type::Function {
|
||||
inputs: set_result_inputs,
|
||||
outputs: set_result_outputs,
|
||||
};
|
||||
|
||||
interfaces.types.push(allocate_func_type);
|
||||
interfaces.types.push(deallocate_func_type);
|
||||
interfaces.types.push(get_result_size_func_type);
|
||||
interfaces.types.push(get_result_ptr_func_type);
|
||||
interfaces.types.push(set_result_size_func_type);
|
||||
interfaces.types.push(set_result_ptr_func_type);
|
||||
|
||||
let allocate_export = Export {
|
||||
name: "allocate",
|
||||
function_type: 0,
|
||||
};
|
||||
interfaces.exports.push(allocate_export);
|
||||
|
||||
let deallocate_export = Export {
|
||||
name: "deallocate",
|
||||
function_type: 1,
|
||||
};
|
||||
interfaces.exports.push(deallocate_export);
|
||||
|
||||
let get_result_size_export = Export {
|
||||
name: "get_result_size",
|
||||
function_type: 2,
|
||||
};
|
||||
interfaces.exports.push(get_result_size_export);
|
||||
|
||||
let get_result_ptr_export = Export {
|
||||
name: "get_result_ptr",
|
||||
function_type: 3,
|
||||
};
|
||||
interfaces.exports.push(get_result_ptr_export);
|
||||
|
||||
let set_result_size_export = Export {
|
||||
name: "set_result_size",
|
||||
function_type: 4,
|
||||
};
|
||||
interfaces.exports.push(set_result_size_export);
|
||||
|
||||
let set_result_ptr_export = Export {
|
||||
name: "set_result_ptr",
|
||||
function_type: 5,
|
||||
};
|
||||
interfaces.exports.push(set_result_ptr_export);
|
||||
}
|
28
crates/wit-generator/src/wasm_ast_extractor.rs
Normal file
28
crates/wit-generator/src/wasm_ast_extractor.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use walrus::ModuleConfig;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
struct WasmAst {
|
||||
exports: Vec<fluence_sdk_wit::AstFunctionItem>,
|
||||
imports: Vec<fluence_sdk_wit::AstExternModItem>,
|
||||
records: Vec<fluence_sdk_wit::AstRecordItem>,
|
||||
}
|
||||
|
||||
pub(crate) fn wasm_ast_extractor(
|
||||
wasm_path: std::path::PathBuf,
|
||||
) -> Result<Vec<fluence_sdk_wit::FCEAst>, std::io::Error> {
|
||||
let module = ModuleConfig::new().parse_file(wasm_path).unwrap();
|
||||
let mut decoded_ast = Vec::new();
|
||||
|
||||
for custom_module in module.customs.iter().filter(|(_, section)| {
|
||||
section
|
||||
.name()
|
||||
.starts_with(fluence_sdk_wit::GENERATED_SECTION_PREFIX)
|
||||
}) {
|
||||
let default_ids = walrus::IdsToIndices::default();
|
||||
let raw_data = custom_module.1.data(&default_ids);
|
||||
let decoded_json: fluence_sdk_wit::FCEAst = serde_json::from_slice(&raw_data).unwrap();
|
||||
decoded_ast.push(decoded_json);
|
||||
}
|
||||
|
||||
Ok(decoded_ast)
|
||||
}
|
36
crates/wit-generator/src/wit_generator.rs
Normal file
36
crates/wit-generator/src/wit_generator.rs
Normal file
@ -0,0 +1,36 @@
|
||||
mod fn_wit_generator;
|
||||
mod foreign_mod_wit_generator;
|
||||
mod record_wit_generator;
|
||||
mod utils;
|
||||
|
||||
use super::FCEAst;
|
||||
|
||||
use wasmer_wit::types::InterfaceType as IType;
|
||||
use wasmer_wit::ast::Interfaces;
|
||||
use wasmer_wit::interpreter::Instruction;
|
||||
|
||||
pub trait WITGenerator {
|
||||
fn generate_wit<'a>(&'a self, interfaces: &mut Interfaces<'a>);
|
||||
}
|
||||
|
||||
trait FnInstructionGenerator {
|
||||
fn generate_instructions_for_input_type(&self, arg_id: u32) -> Vec<Instruction>;
|
||||
|
||||
fn generate_instructions_for_output_type(&self) -> Vec<Instruction>;
|
||||
}
|
||||
|
||||
trait ForeignModInstructionGenerator {
|
||||
fn generate_instructions_for_input_type(&self, arg_id: u32) -> Vec<Instruction>;
|
||||
|
||||
fn generate_instructions_for_output_type(&self) -> Vec<Instruction>;
|
||||
}
|
||||
|
||||
impl WITGenerator for FCEAst {
|
||||
fn generate_wit<'a>(&'a self, interfaces: &mut Interfaces<'a>) {
|
||||
match self {
|
||||
FCEAst::Function(func) => func.generate_wit(interfaces),
|
||||
FCEAst::ExternMod(extern_mod) => extern_mod.generate_wit(interfaces),
|
||||
FCEAst::Record(record) => record.generate_wit(interfaces),
|
||||
}
|
||||
}
|
||||
}
|
139
crates/wit-generator/src/wit_generator/fn_wit_generator.rs
Normal file
139
crates/wit-generator/src/wit_generator/fn_wit_generator.rs
Normal file
@ -0,0 +1,139 @@
|
||||
use super::WITGenerator;
|
||||
use super::Interfaces;
|
||||
use super::utils::ptype_to_itype;
|
||||
use super::FnInstructionGenerator;
|
||||
|
||||
use fluence_sdk_wit::AstFunctionItem;
|
||||
use fluence_sdk_wit::ParsedType;
|
||||
use wasmer_wit::interpreter::Instruction;
|
||||
|
||||
impl WITGenerator for AstFunctionItem {
|
||||
fn generate_wit<'a>(&'a self, interfaces: &mut Interfaces<'a>) {
|
||||
use wasmer_wit::ast::Type;
|
||||
use wasmer_wit::ast::Adapter;
|
||||
|
||||
let inputs = self
|
||||
.signature
|
||||
.input_types
|
||||
.iter()
|
||||
.map(ptype_to_itype)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let outputs = match self.signature.output_type {
|
||||
Some(ref output_type) => vec![ptype_to_itype(output_type)],
|
||||
None => vec![],
|
||||
};
|
||||
|
||||
interfaces.types.push(Type::Function {
|
||||
inputs: inputs.clone(),
|
||||
outputs: outputs.clone(),
|
||||
});
|
||||
|
||||
// TODO: replace with Wasm types
|
||||
interfaces.types.push(Type::Function { inputs, outputs });
|
||||
|
||||
let adapter_idx = (interfaces.types.len() - 2) as u32;
|
||||
let export_idx = (interfaces.types.len() - 1) as u32;
|
||||
|
||||
interfaces.exports.push(wasmer_wit::ast::Export {
|
||||
name: &self.signature.name,
|
||||
function_type: export_idx,
|
||||
});
|
||||
|
||||
let mut instructions: Vec<Instruction> = self
|
||||
.signature
|
||||
.input_types
|
||||
.iter()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.map(|(id, input_type)| input_type.generate_instructions_for_input_type(id as _))
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
instructions.push(Instruction::CallCore {
|
||||
function_index: export_idx,
|
||||
});
|
||||
|
||||
instructions.extend(match &self.signature.output_type {
|
||||
Some(output_type) => output_type.generate_instructions_for_output_type(),
|
||||
None => vec![],
|
||||
});
|
||||
|
||||
let adapter = Adapter {
|
||||
function_type: adapter_idx,
|
||||
instructions,
|
||||
};
|
||||
|
||||
interfaces.adapters.push(adapter);
|
||||
|
||||
let implementation = wasmer_wit::ast::Implementation {
|
||||
core_function_type: export_idx,
|
||||
adapter_function_type: adapter_idx,
|
||||
};
|
||||
interfaces.implementations.push(implementation);
|
||||
}
|
||||
}
|
||||
|
||||
impl FnInstructionGenerator for ParsedType {
|
||||
fn generate_instructions_for_input_type(&self, index: u32) -> Vec<Instruction> {
|
||||
match self {
|
||||
ParsedType::I8 => vec![Instruction::ArgumentGet { index }, Instruction::I32FromS8],
|
||||
ParsedType::I16 => vec![Instruction::ArgumentGet { index }, Instruction::I32FromS16],
|
||||
ParsedType::I32 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::I64 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::U8 => vec![Instruction::ArgumentGet { index }, Instruction::I32FromU8],
|
||||
ParsedType::U16 => vec![Instruction::ArgumentGet { index }, Instruction::I32FromU16],
|
||||
ParsedType::U32 => vec![Instruction::ArgumentGet { index }, Instruction::I32FromU32],
|
||||
ParsedType::U64 => vec![Instruction::ArgumentGet { index }, Instruction::I64FromU64],
|
||||
ParsedType::F32 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::F64 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::Utf8String => vec![
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::StringSize,
|
||||
Instruction::CallCore { function_index: 0 },
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::StringLowerMemory,
|
||||
],
|
||||
ParsedType::ByteVector => vec![
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::StringSize,
|
||||
Instruction::CallCore { function_index: 0 },
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::StringLowerMemory,
|
||||
],
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_instructions_for_output_type(&self) -> Vec<Instruction> {
|
||||
match self {
|
||||
ParsedType::I8 => vec![Instruction::S8FromI32],
|
||||
ParsedType::I16 => vec![Instruction::S16FromI32],
|
||||
ParsedType::I32 => vec![],
|
||||
ParsedType::I64 => vec![],
|
||||
ParsedType::U8 => vec![Instruction::U8FromI32],
|
||||
ParsedType::U16 => vec![Instruction::U16FromI32],
|
||||
ParsedType::U32 => vec![Instruction::U32FromI32],
|
||||
ParsedType::U64 => vec![Instruction::U64FromI64],
|
||||
ParsedType::F32 => vec![],
|
||||
ParsedType::F64 => vec![],
|
||||
ParsedType::Utf8String => vec![
|
||||
Instruction::CallCore { function_index: 3 },
|
||||
Instruction::CallCore { function_index: 2 },
|
||||
Instruction::StringLiftMemory,
|
||||
Instruction::CallCore { function_index: 3 },
|
||||
Instruction::CallCore { function_index: 2 },
|
||||
Instruction::CallCore { function_index: 1 },
|
||||
],
|
||||
ParsedType::ByteVector => vec![
|
||||
Instruction::CallCore { function_index: 3 },
|
||||
Instruction::CallCore { function_index: 2 },
|
||||
Instruction::StringLiftMemory,
|
||||
Instruction::CallCore { function_index: 3 },
|
||||
Instruction::CallCore { function_index: 2 },
|
||||
Instruction::CallCore { function_index: 1 },
|
||||
],
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
use super::WITGenerator;
|
||||
use super::Interfaces;
|
||||
use super::utils::ptype_to_itype;
|
||||
use super::ForeignModInstructionGenerator;
|
||||
|
||||
use fluence_sdk_wit::AstExternModItem;
|
||||
use fluence_sdk_wit::AstExternFnItem;
|
||||
use fluence_sdk_wit::ParsedType;
|
||||
use wasmer_wit::interpreter::Instruction;
|
||||
|
||||
impl WITGenerator for AstExternModItem {
|
||||
fn generate_wit<'a>(&'a self, interfaces: &mut Interfaces<'a>) {
|
||||
for import in &self.imports {
|
||||
generate_wit_for_import(import, &self.namespace, interfaces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_wit_for_import<'a>(
|
||||
import: &'a AstExternFnItem,
|
||||
namespace: &'a String,
|
||||
interfaces: &mut Interfaces<'a>,
|
||||
) {
|
||||
use wasmer_wit::ast::Type;
|
||||
use wasmer_wit::ast::Adapter;
|
||||
|
||||
let inputs = import
|
||||
.signature
|
||||
.input_types
|
||||
.iter()
|
||||
.map(ptype_to_itype)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let outputs = match import.signature.output_type {
|
||||
Some(ref output_type) => vec![ptype_to_itype(output_type)],
|
||||
None => vec![],
|
||||
};
|
||||
interfaces.types.push(Type::Function {
|
||||
inputs: inputs.clone(),
|
||||
outputs: outputs.clone(),
|
||||
});
|
||||
|
||||
// TODO: replace with Wasm types
|
||||
interfaces.types.push(Type::Function { inputs, outputs });
|
||||
|
||||
let adapter_idx = (interfaces.types.len() - 2) as u32;
|
||||
let import_idx = (interfaces.types.len() - 1) as u32;
|
||||
|
||||
interfaces.imports.push(wasmer_wit::ast::Import {
|
||||
namespace: &namespace,
|
||||
name: &import.signature.name,
|
||||
function_type: import_idx,
|
||||
});
|
||||
|
||||
let mut instructions: Vec<Instruction> = import
|
||||
.signature
|
||||
.input_types
|
||||
.iter()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.map(|(id, input_type)| input_type.generate_instructions_for_input_type(id as _))
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
instructions.push(Instruction::CallCore {
|
||||
function_index: import_idx,
|
||||
});
|
||||
|
||||
instructions.extend(match &import.signature.output_type {
|
||||
Some(output_type) => output_type.generate_instructions_for_output_type(),
|
||||
None => vec![],
|
||||
});
|
||||
|
||||
let adapter = Adapter {
|
||||
function_type: adapter_idx,
|
||||
instructions,
|
||||
};
|
||||
interfaces.adapters.push(adapter);
|
||||
|
||||
let implementation = wasmer_wit::ast::Implementation {
|
||||
core_function_type: import_idx,
|
||||
adapter_function_type: adapter_idx,
|
||||
};
|
||||
interfaces.implementations.push(implementation);
|
||||
}
|
||||
|
||||
impl ForeignModInstructionGenerator for ParsedType {
|
||||
fn generate_instructions_for_input_type(&self, index: u32) -> Vec<Instruction> {
|
||||
match self {
|
||||
ParsedType::I8 => vec![Instruction::ArgumentGet { index }, Instruction::S8FromI32],
|
||||
ParsedType::I16 => vec![Instruction::ArgumentGet { index }, Instruction::S16FromI32],
|
||||
ParsedType::I32 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::I64 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::U8 => vec![Instruction::ArgumentGet { index }, Instruction::U8FromI32],
|
||||
ParsedType::U16 => vec![Instruction::ArgumentGet { index }, Instruction::U16FromI32],
|
||||
ParsedType::U32 => vec![Instruction::ArgumentGet { index }, Instruction::U32FromI32],
|
||||
ParsedType::U64 => vec![Instruction::ArgumentGet { index }, Instruction::U64FromI64],
|
||||
ParsedType::F32 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::F64 => vec![Instruction::ArgumentGet { index }],
|
||||
ParsedType::Utf8String => vec![
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::ArgumentGet { index: index + 1 },
|
||||
Instruction::StringLiftMemory,
|
||||
],
|
||||
ParsedType::ByteVector => vec![
|
||||
Instruction::ArgumentGet { index },
|
||||
Instruction::ArgumentGet { index: index + 1 },
|
||||
Instruction::StringLiftMemory,
|
||||
],
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_instructions_for_output_type(&self) -> Vec<Instruction> {
|
||||
match self {
|
||||
ParsedType::I8 => vec![Instruction::I32FromS8],
|
||||
ParsedType::I16 => vec![Instruction::I32FromS16],
|
||||
ParsedType::I32 => vec![],
|
||||
ParsedType::I64 => vec![],
|
||||
ParsedType::U8 => vec![Instruction::I32FromU8],
|
||||
ParsedType::U16 => vec![Instruction::I32FromU16],
|
||||
ParsedType::U32 => vec![Instruction::I32FromU32],
|
||||
ParsedType::U64 => vec![Instruction::I64FromU64],
|
||||
ParsedType::F32 => vec![],
|
||||
ParsedType::F64 => vec![],
|
||||
ParsedType::Utf8String => vec![
|
||||
Instruction::Dup,
|
||||
Instruction::StringSize,
|
||||
Instruction::CallCore { function_index: 0 },
|
||||
Instruction::Swap2,
|
||||
Instruction::StringLowerMemory,
|
||||
Instruction::CallCore { function_index: 4 },
|
||||
Instruction::CallCore { function_index: 5 },
|
||||
],
|
||||
ParsedType::ByteVector => vec![
|
||||
Instruction::Dup,
|
||||
Instruction::StringSize,
|
||||
Instruction::CallCore { function_index: 0 },
|
||||
Instruction::Swap2,
|
||||
Instruction::StringLowerMemory,
|
||||
Instruction::CallCore { function_index: 4 },
|
||||
Instruction::CallCore { function_index: 5 },
|
||||
],
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
use super::WITGenerator;
|
||||
use super::Interfaces;
|
||||
|
||||
use fluence_sdk_wit::AstRecordItem;
|
||||
|
||||
impl WITGenerator for AstRecordItem {
|
||||
fn generate_wit<'a>(&'a self, _interfaces: &mut Interfaces<'a>) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
21
crates/wit-generator/src/wit_generator/utils.rs
Normal file
21
crates/wit-generator/src/wit_generator/utils.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use super::IType;
|
||||
use fluence_sdk_wit::ParsedType;
|
||||
|
||||
pub(crate) fn ptype_to_itype(pty: &ParsedType) -> IType {
|
||||
match pty {
|
||||
ParsedType::I8 => IType::S8,
|
||||
ParsedType::I16 => IType::S16,
|
||||
ParsedType::I32 => IType::S32,
|
||||
ParsedType::I64 => IType::S64,
|
||||
ParsedType::U8 => IType::U8,
|
||||
ParsedType::U16 => IType::U16,
|
||||
ParsedType::U32 => IType::U32,
|
||||
ParsedType::U64 => IType::U64,
|
||||
ParsedType::F32 => IType::F32,
|
||||
ParsedType::F64 => IType::F64,
|
||||
ParsedType::Boolean => IType::I32,
|
||||
ParsedType::Utf8String => IType::String,
|
||||
ParsedType::ByteVector => IType::String,
|
||||
ParsedType::Record(_) => unimplemented!(),
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "wit_parser"
|
||||
name = "wit-parser"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
@ -12,6 +12,6 @@ path = "src/lib.rs"
|
||||
walrus = "0.17.0"
|
||||
wasmer-core = { package = "wasmer-runtime-core", git = "https://github.com/fluencelabs/wasmer", branch = "fluence" }
|
||||
wasmer-wit = { package = "wasmer-interface-types", git = "https://github.com/fluencelabs/interface-types", branch = "master" }
|
||||
fce_wit_interfaces = { path = "../fce_wit_interfaces" }
|
||||
fce-wit-interfaces = { path = "../fce-wit-interfaces" }
|
||||
|
||||
anyhow = "1.0.31"
|
@ -5,8 +5,8 @@ authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
fce_wit_interfaces = { path = "../crates/fce_wit_interfaces", version = "0.1.0" }
|
||||
wit_parser = { path = "../crates/wit_parser", version = "0.1.0" }
|
||||
fce-wit-interfaces = { path = "../crates/fce-wit-interfaces", version = "0.1.0" }
|
||||
wit-parser = { path = "../crates/wit-parser", version = "0.1.0" }
|
||||
|
||||
wasmer-runtime = { git = "https://github.com/fluencelabs/wasmer", branch = "fluence" }
|
||||
# dynamicfunc-fat-closures allows using state inside DynamicFunc
|
||||
|
@ -9,10 +9,11 @@ name = "fce_cli"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
wit_parser = { path = "../../crates/wit_parser" }
|
||||
wit-generator = { path = "../../crates/wit-generator" }
|
||||
wit-parser = { path = "../../crates/wit-parser" }
|
||||
|
||||
clap = "2.33.1"
|
||||
exitfailure = "0.5.1"
|
||||
failure = "0.1.5"
|
||||
wit = { path = "/Users/mike/dev/work/fluence/wasm/rust-sdk/crates/wit" }
|
||||
serde = "1.0.114"
|
||||
serde_json = "1.0.56"
|
@ -29,7 +29,6 @@ mod args;
|
||||
use args::*;
|
||||
|
||||
use clap::{App, AppSettings};
|
||||
// use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@ -37,17 +36,8 @@ use std::process::Command;
|
||||
enum DiagnosticMessage {
|
||||
BuildScriptExecuted,
|
||||
BuildFinished,
|
||||
CompilerArtifact {
|
||||
executable: String,
|
||||
/*
|
||||
filenames: Vec<String>,
|
||||
profile: Profile,
|
||||
fresh: bool,
|
||||
*/
|
||||
},
|
||||
RunWithArgs {
|
||||
// args: Vec<String>,
|
||||
},
|
||||
CompilerArtifact { executable: String },
|
||||
RunWithArgs,
|
||||
}
|
||||
|
||||
pub fn main() -> Result<(), exitfailure::ExitFailure> {
|
||||
@ -94,7 +84,7 @@ pub fn main() -> Result<(), exitfailure::ExitFailure> {
|
||||
}
|
||||
|
||||
let wasm_path = std::path::PathBuf::from(wasms.first().unwrap());
|
||||
wit::embed_wit(wasm_path);
|
||||
wit_generator::embed_wit(wasm_path);
|
||||
|
||||
Ok(())
|
||||
}
|
@ -9,7 +9,7 @@ name = "wit_embedder"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
wit_parser = { path = "../../crates/wit_parser" }
|
||||
wit-parser = { path = "../../crates/wit-parser" }
|
||||
clap = "2.33.1"
|
||||
exitfailure = "0.5.1"
|
||||
failure = "0.1.5"
|
||||
|
Reference in New Issue
Block a user