mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
cargo fmt all the things
This commit is contained in:
parent
541a19ff29
commit
880bb6f87e
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
mod mem;
|
mod mem;
|
||||||
mod result;
|
mod result;
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
mod mem;
|
mod mem;
|
||||||
mod result;
|
mod result;
|
||||||
|
|
||||||
@ -21,17 +23,14 @@ use crate::result::{RESULT_PTR, RESULT_SIZE};
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
||||||
let file_content = String::from_raw_parts(
|
let file_content =
|
||||||
file_content_ptr,
|
String::from_raw_parts(file_content_ptr, file_content_size, file_content_size);
|
||||||
file_content_size,
|
|
||||||
file_content_size
|
|
||||||
);
|
|
||||||
|
|
||||||
let msg = format!("from Wasm node: file content is {}\n", file_content);
|
let msg = format!("from Wasm node: file content is {}\n", file_content);
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
let cmd = format!("put {}", file_content);
|
let cmd = format!("put {}", file_content);
|
||||||
ipfs(file_content.as_ptr() as _, file_content.len() as _);
|
ipfs(cmd.as_ptr() as _, cmd.len() as _);
|
||||||
|
|
||||||
let result = "Hello from IPFS node, take your hash".to_string();
|
let result = "Hello from IPFS node, take your hash".to_string();
|
||||||
|
|
||||||
@ -42,11 +41,7 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
|
pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
|
||||||
let hash = String::from_raw_parts(
|
let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size);
|
||||||
hash_ptr,
|
|
||||||
hash_size,
|
|
||||||
hash_size
|
|
||||||
);
|
|
||||||
|
|
||||||
let msg = format!("from Wasm node: file content is {}\n", hash);
|
let msg = format!("from Wasm node: file content is {}\n", hash);
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
|
||||||
use crate::log_utf8_string;
|
use crate::log_utf8_string;
|
||||||
|
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Allocates memory area of specified size and returns its address.
|
/// Allocates memory area of specified size and returns its address.
|
||||||
|
@ -14,16 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
|
||||||
use crate::log_utf8_string;
|
use crate::log_utf8_string;
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
||||||
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
|
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get_result_ptr() -> usize {
|
pub unsafe fn get_result_ptr() -> usize {
|
||||||
let msg = format!("wasm_node: calling get_result_ptr\n");
|
let msg = "wasm_node: calling get_result_ptr\n";
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
*RESULT_PTR.get_mut()
|
*RESULT_PTR.get_mut()
|
||||||
@ -31,7 +30,7 @@ pub unsafe fn get_result_ptr() -> usize {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get_result_size() -> usize {
|
pub unsafe fn get_result_size() -> usize {
|
||||||
let msg = format!("wasm_node: calling get_result_size\n");
|
let msg = "wasm_node: calling get_result_size\n";
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
*RESULT_SIZE.get_mut()
|
*RESULT_SIZE.get_mut()
|
||||||
|
@ -13,19 +13,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
mod mem;
|
mod mem;
|
||||||
mod result;
|
mod result;
|
||||||
|
|
||||||
use crate::result::{RESULT_PTR, RESULT_SIZE};
|
// use crate::result::{RESULT_PTR, RESULT_SIZE};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn invoke(file_content_ptr: *mut u8, file_content_size: usize) {
|
pub unsafe fn invoke(file_content_ptr: *mut u8, file_content_size: usize) {
|
||||||
let file_content = String::from_raw_parts(
|
let file_content =
|
||||||
file_content_ptr,
|
String::from_raw_parts(file_content_ptr, file_content_size, file_content_size);
|
||||||
file_content_size,
|
|
||||||
file_content_size,
|
|
||||||
);
|
|
||||||
let msg = format!("from Wasm rpc: file_content is {}\n", file_content);
|
let msg = format!("from Wasm rpc: file_content is {}\n", file_content);
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
@ -54,6 +52,7 @@ extern "C" {
|
|||||||
/// Put a file to ipfs, returns ipfs hash of the file.
|
/// Put a file to ipfs, returns ipfs hash of the file.
|
||||||
fn put(ptr: i32, size: i32);
|
fn put(ptr: i32, size: i32);
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
/// Get file from ipfs by hash.
|
/// Get file from ipfs by hash.
|
||||||
fn get(ptr: i32, size: i32);
|
fn get(ptr: i32, size: i32);
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
|
||||||
use crate::log_utf8_string;
|
use crate::log_utf8_string;
|
||||||
|
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Allocates memory area of specified size and returns its address.
|
/// Allocates memory area of specified size and returns its address.
|
||||||
|
@ -14,16 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
|
||||||
use crate::log_utf8_string;
|
use crate::log_utf8_string;
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
pub static mut RESULT_PTR: AtomicUsize = AtomicUsize::new(0);
|
||||||
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
|
pub static mut RESULT_SIZE: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get_result_ptr() -> usize {
|
pub unsafe fn get_result_ptr() -> usize {
|
||||||
let msg = format!("wasm_rpc: calling get_result_ptr\n");
|
let msg = "wasm_rpc: calling get_result_ptr\n";
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
*RESULT_PTR.get_mut()
|
*RESULT_PTR.get_mut()
|
||||||
@ -31,7 +30,7 @@ pub unsafe fn get_result_ptr() -> usize {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get_result_size() -> usize {
|
pub unsafe fn get_result_size() -> usize {
|
||||||
let msg = format!("wasm_rpc: calling get_result_size\n");
|
let msg = "wasm_rpc: calling get_result_size\n";
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
|
||||||
*RESULT_SIZE.get_mut()
|
*RESULT_SIZE.get_mut()
|
||||||
|
@ -30,6 +30,7 @@ enum WITFunctionInner {
|
|||||||
outputs: Vec<InterfaceType>,
|
outputs: Vec<InterfaceType>,
|
||||||
},
|
},
|
||||||
Import {
|
Import {
|
||||||
|
// TODO: use WITInstance here instead of WITModule
|
||||||
wit_module: Arc<WITModule>,
|
wit_module: Arc<WITModule>,
|
||||||
func_name: String,
|
func_name: String,
|
||||||
inputs: Vec<InterfaceType>,
|
inputs: Vec<InterfaceType>,
|
||||||
|
@ -39,12 +39,13 @@ use wasmer_runtime_core::import::Namespace;
|
|||||||
const WIT_SECTION_NAME: &str = "interface-types";
|
const WIT_SECTION_NAME: &str = "interface-types";
|
||||||
type WITInterpreter =
|
type WITInterpreter =
|
||||||
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
|
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
|
||||||
|
type WITModuleFunc = (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>);
|
||||||
|
|
||||||
pub struct WITModule {
|
pub struct WITModule {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
instance: WasmerInstance,
|
instance: WasmerInstance,
|
||||||
wit_instance: Arc<WITInstance>,
|
wit_instance: Arc<WITInstance>,
|
||||||
funcs: HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
|
funcs: HashMap<String, WITModuleFunc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WITModule {
|
impl WITModule {
|
||||||
@ -128,10 +129,7 @@ impl WITModule {
|
|||||||
|
|
||||||
fn extract_wit_exports(
|
fn extract_wit_exports(
|
||||||
interfaces: &Interfaces,
|
interfaces: &Interfaces,
|
||||||
) -> Result<
|
) -> Result<HashMap<String, WITModuleFunc>, WITFCEError> {
|
||||||
HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
|
|
||||||
WITFCEError,
|
|
||||||
> {
|
|
||||||
let exports_type_to_names = interfaces
|
let exports_type_to_names = interfaces
|
||||||
.exports
|
.exports
|
||||||
.iter()
|
.iter()
|
||||||
@ -254,7 +252,8 @@ impl WITModule {
|
|||||||
let interpreter: WITInterpreter = instructions.try_into().unwrap();
|
let interpreter: WITInterpreter = instructions.try_into().unwrap();
|
||||||
|
|
||||||
let wit_instance = wit_instance.clone();
|
let wit_instance = wit_instance.clone();
|
||||||
let inner_import = Box::new(move |_: &mut Ctx, inputs: &[Value]| -> Vec<Value> {
|
let wit_inner_import =
|
||||||
|
Box::new(move |_: &mut Ctx, inputs: &[Value]| -> Vec<Value> {
|
||||||
// copy here to because otherwise wit_instance will be consumed by the closure
|
// copy here to because otherwise wit_instance will be consumed by the closure
|
||||||
let wit_instance_callable = wit_instance.clone();
|
let wit_instance_callable = wit_instance.clone();
|
||||||
let converted_inputs = inputs.iter().map(wval_to_ival).collect::<Vec<_>>();
|
let converted_inputs = inputs.iter().map(wval_to_ival).collect::<Vec<_>>();
|
||||||
@ -271,12 +270,13 @@ impl WITModule {
|
|||||||
vec![]
|
vec![]
|
||||||
});
|
});
|
||||||
|
|
||||||
let linking_import = dyn_func_from_imports(inputs.clone(), inner_import);
|
let wit_import = dyn_func_from_imports(inputs.clone(), wit_inner_import);
|
||||||
|
|
||||||
let mut n = Namespace::new();
|
// TODO: refactor this
|
||||||
n.insert(func_name.clone(), linking_import);
|
let mut module_namespace = Namespace::new();
|
||||||
|
module_namespace.insert(func_name.clone(), wit_import);
|
||||||
|
|
||||||
import_namespaces.insert(namespace, n);
|
import_namespaces.insert(namespace, module_namespace);
|
||||||
} else {
|
} else {
|
||||||
// TODO: change error type
|
// TODO: change error type
|
||||||
return Err(WITFCEError::WasmerResolveError(format!(
|
return Err(WITFCEError::WasmerResolveError(format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user