diff --git a/crates/wit-generator/src/instructions_generator/foreign_mod_instructions.rs b/crates/wit-generator/src/instructions_generator/foreign_mod_instructions.rs index c532c3a3..010f5aee 100644 --- a/crates/wit-generator/src/instructions_generator/foreign_mod_instructions.rs +++ b/crates/wit-generator/src/instructions_generator/foreign_mod_instructions.rs @@ -26,8 +26,15 @@ use fluence_sdk_wit::ParsedType; use wasmer_wit::interpreter::Instruction; use crate::instructions_generator::utils::wtype_to_itype; +const HOST_NAMESPACE_NAME: &str = "host"; + impl WITGenerator for AstExternModItem { fn generate_wit<'a>(&'a self, interfaces: &mut Interfaces<'a>) { + // host imports should be left as is + if self.namespace == HOST_NAMESPACE_NAME { + return; + } + for import in &self.imports { generate_wit_for_import(import, &self.namespace, interfaces); } diff --git a/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm b/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm index 5866c181..8821a79b 100644 Binary files a/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm and b/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm differ diff --git a/examples/ipfs_node/wasm/ipfs_node/src/main.rs b/examples/ipfs_node/wasm/ipfs_node/src/main.rs index b4bc71bc..ad0c1a60 100644 --- a/examples/ipfs_node/wasm/ipfs_node/src/main.rs +++ b/examples/ipfs_node/wasm/ipfs_node/src/main.rs @@ -39,7 +39,7 @@ pub fn put(file_path: String) -> String { let timeout = std::env::var(TIMEOUT_ENV_NAME).unwrap_or_else(|_| "1s".to_string()); let cmd = format!("add --timeout {} -Q {}", timeout, file_path); - call_ipfs(cmd) + ipfs(cmd) } /// Get file by provided hash from IPFS, saves it to a temporary file and returns a path to it. @@ -55,7 +55,7 @@ pub fn get(hash: String) -> String { timeout, result_file_path, hash ); - call_ipfs(cmd); + ipfs(cmd); RESULT_FILE_PATH.to_string() } @@ -71,22 +71,9 @@ pub fn get_address() -> String { } } -fn call_ipfs(cmd: String) -> String { - unsafe { - // TODO: better error handling - match ipfs(cmd.as_ptr() as _, cmd.len() as _) { - 0 => String::from_raw_parts( - fluence::internal::get_result_ptr() as _, - fluence::internal::get_result_size(), - fluence::internal::get_result_size(), - ), - _ => "host ipfs call failed".to_string(), - } - } -} - +#[fce] #[link(wasm_import_module = "host")] extern "C" { - /// Put a file to ipfs, returns ipfs hash of the file. - fn ipfs(ptr: i32, size: i32) -> i32; + /// Execute provided cmd as a parameters of ipfs cli, return result. + pub fn ipfs(cmd: String) -> String; } diff --git a/fluence-faas/src/misc/imports.rs b/fluence-faas/src/misc/imports.rs index 2e0c94bd..c5813cca 100644 --- a/fluence-faas/src/misc/imports.rs +++ b/fluence-faas/src/misc/imports.rs @@ -93,7 +93,7 @@ where }; DynamicFunc::new( - std::sync::Arc::new(FuncSig::new(vec![Type::I32, Type::I32], vec![Type::I32])), + std::sync::Arc::new(FuncSig::new(vec![Type::I32, Type::I32], vec![])), func, ) }