From 46ac364c69bb1111f19b1965a14cd05105c73174 Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 11 Jun 2020 19:11:34 +0300 Subject: [PATCH] support of _start --- Cargo.lock | 51 ++++++++++--------- examples/ipfs_node/src/errors.rs | 2 +- examples/ipfs_node/src/lib.rs | 2 + examples/ipfs_node/wasm/ipfs_node/Cargo.toml | 5 +- .../wasm/ipfs_node/src/{lib.rs => main.rs} | 16 +++--- examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml | 5 +- .../wasm/ipfs_rpc/src/{lib.rs => main.rs} | 29 +++++------ fce/src/vm/module/fce_module.rs | 6 +++ 8 files changed, 61 insertions(+), 55 deletions(-) rename examples/ipfs_node/wasm/ipfs_node/src/{lib.rs => main.rs} (82%) rename examples/ipfs_node/wasm/ipfs_rpc/src/{lib.rs => main.rs} (75%) diff --git a/Cargo.lock b/Cargo.lock index 4dc4e59f..d00fe227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -242,12 +242,13 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ "cfg-if", "crossbeam-utils", + "maybe-uninit", ] [[package]] @@ -273,9 +274,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf6b25ee9ac1995c54d7adb2eff8cfffb7260bc774fb63c601ec65467f43cd9d" +checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227" dependencies = [ "quote", "syn", @@ -479,9 +480,9 @@ checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "indexmap" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" dependencies = [ "autocfg", "serde", @@ -706,9 +707,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" dependencies = [ "unicode-xid", ] @@ -726,9 +727,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] @@ -791,9 +792,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "scopeguard" @@ -837,9 +838,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bf487fbf5c6239d7ea2ff8b10cb6b811cd4b5080d1c2aeed1dec18753c06e10" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" dependencies = [ "serde", ] @@ -857,9 +858,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.53" +version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" +checksum = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226" dependencies = [ "itoa", "ryu", @@ -892,9 +893,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "syn" -version = "1.0.27" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef781e621ee763a2a40721a8861ec519cb76966aee03bb5d00adb6a31dc1c1de" +checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6" dependencies = [ "proc-macro2", "quote", @@ -903,9 +904,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", @@ -975,9 +976,9 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "typetag" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ebb2c484029d695fb68a06d80e1536c68d491b3e0cf874c66abed255e831cfe" +checksum = "9275125decb5d75fe57ebfe92debd119b15757aae27c56d7cb61ecab871960bc" dependencies = [ "erased-serde", "inventory", @@ -988,9 +989,9 @@ dependencies = [ [[package]] name = "typetag-impl" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63fd4799e4d0ec5cf0b055ebb8e2c3a657bbf76a84f6edc77ca60780e000204" +checksum = "dc232cda3b1d82664153e6c95d1071809aa0f1011f306c3d6989f33d8c6ede17" dependencies = [ "proc-macro2", "quote", @@ -1128,7 +1129,7 @@ dependencies = [ [[package]] name = "wasmer-interface-types" version = "0.17.0" -source = "git+https://github.com/fluencelabs/interface-types#c2f2a23c38af049bce7a3e93a51ff287b3898410" +source = "git+https://github.com/fluencelabs/interface-types#82986d10358f02c8ae64850ed0b79efb4e823c54" dependencies = [ "nom", "serde", diff --git a/examples/ipfs_node/src/errors.rs b/examples/ipfs_node/src/errors.rs index 8b14db9c..398797e6 100644 --- a/examples/ipfs_node/src/errors.rs +++ b/examples/ipfs_node/src/errors.rs @@ -24,7 +24,7 @@ pub enum NodeError { /// An error related to config parsing. ConfigParseError(String), - /// Various errors related to file io. + /// Various errors related to file i/o. IOError(String), /// WIT doesn't contain such type. diff --git a/examples/ipfs_node/src/lib.rs b/examples/ipfs_node/src/lib.rs index 353ea2c7..f951f12b 100644 --- a/examples/ipfs_node/src/lib.rs +++ b/examples/ipfs_node/src/lib.rs @@ -20,6 +20,8 @@ mod config; mod imports; mod node_public_interface; +pub use fce::IValue; + pub use node::IpfsNode; pub use node_public_interface::NodePublicInterface; pub use node_public_interface::NodeModulePublicInterface; diff --git a/examples/ipfs_node/wasm/ipfs_node/Cargo.toml b/examples/ipfs_node/wasm/ipfs_node/Cargo.toml index 11b12371..3fea3b4c 100644 --- a/examples/ipfs_node/wasm/ipfs_node/Cargo.toml +++ b/examples/ipfs_node/wasm/ipfs_node/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["Fluence Labs"] edition = "2018" -[lib] +[[bin]] name = "wasm_ipfs_node" -path = "src/lib.rs" -crate-type = ["cdylib"] +path = "src/main.rs" diff --git a/examples/ipfs_node/wasm/ipfs_node/src/lib.rs b/examples/ipfs_node/wasm/ipfs_node/src/main.rs similarity index 82% rename from examples/ipfs_node/wasm/ipfs_node/src/lib.rs rename to examples/ipfs_node/wasm/ipfs_node/src/main.rs index d7af2cee..554a998c 100644 --- a/examples/ipfs_node/wasm/ipfs_node/src/lib.rs +++ b/examples/ipfs_node/wasm/ipfs_node/src/main.rs @@ -23,12 +23,15 @@ use crate::result::{RESULT_PTR, RESULT_SIZE}; const RESULT_PATH: &str = "/tmp/ipfs_rpc_file"; +pub fn main() { + println!("ipfs_node.main: WASI initialization finished"); +} + #[no_mangle] pub unsafe fn put(file_path_ptr: *mut u8, file_path_size: usize) { let file_path = String::from_raw_parts(file_path_ptr, file_path_size, file_path_size); - let msg = format!("ipfs_node.put: file path is {}\n", file_path); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_node.put: file path is {}\n", file_path); let cmd = format!("add -Q {}", file_path); let result = ipfs(cmd.as_ptr() as _, cmd.len() as _); @@ -43,8 +46,7 @@ pub unsafe fn put(file_path_ptr: *mut u8, file_path_size: usize) { "host ipfs call failed".to_string() }; - let msg = format!("ipfs_node.put: file add wtih hash is {} \n", hash); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_node.put: file add wtih hash is {} \n", hash); *RESULT_PTR.get_mut() = hash.as_ptr() as _; *RESULT_SIZE.get_mut() = hash.len(); @@ -55,8 +57,7 @@ pub unsafe fn put(file_path_ptr: *mut u8, file_path_size: usize) { pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size); - let msg = format!("ipfs_node.get: file hash is {}\n", hash); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_node.get: file hash is {}\n", hash); let cmd = format!("get -o {} {}", RESULT_PATH, hash); let _result = ipfs(cmd.as_ptr() as _, cmd.len() as _); @@ -70,8 +71,7 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { // TODO: check output let file_path = RESULT_PATH.to_string(); - let msg = format!("ipfs_node.get: file path is {}", file_path); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_node.get: file path is {}", file_path); *RESULT_PTR.get_mut() = file_path.as_ptr() as _; *RESULT_SIZE.get_mut() = file_path.len(); diff --git a/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml b/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml index 37e2bc95..8755eb6c 100644 --- a/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml +++ b/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" authors = ["Fluence Labs"] edition = "2018" -[lib] +[[bin]] name = "wasm_ipfs_rpc" -path = "src/lib.rs" -crate-type = ["cdylib"] +path = "src/main.rs" diff --git a/examples/ipfs_node/wasm/ipfs_rpc/src/lib.rs b/examples/ipfs_node/wasm/ipfs_rpc/src/main.rs similarity index 75% rename from examples/ipfs_node/wasm/ipfs_rpc/src/lib.rs rename to examples/ipfs_node/wasm/ipfs_rpc/src/main.rs index 83b366c5..0e55c83f 100644 --- a/examples/ipfs_node/wasm/ipfs_rpc/src/lib.rs +++ b/examples/ipfs_node/wasm/ipfs_rpc/src/main.rs @@ -22,13 +22,17 @@ use crate::result::{RESULT_PTR, RESULT_SIZE}; use std::fs; use std::path::PathBuf; +const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file"; + +pub fn main() { + println!("ipfs_rpc.main: WASI initialization finished"); +} + #[no_mangle] pub unsafe fn invoke(_ptr: *mut u8, _size: usize) { - let msg = "ipfs_rpc.invoke: invoke called"; - log_utf8_string(msg.as_ptr() as _, msg.len() as _); - - let result = "IFPFS_RPC wasm example, it allow:\nput\nget".to_string(); + println!("ipfs_rpc.invoke: invoke called"); + let result = "IPFS_RPC wasm example, it allow:\nput\nget".to_string(); *RESULT_PTR.get_mut() = result.as_ptr() as _; *RESULT_SIZE.get_mut() = result.len(); std::mem::forget(result); @@ -39,15 +43,13 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) { let file_content = String::from_raw_parts(file_content_ptr, file_content_size, file_content_size); - let msg = format!("ipfs_rpc.put: file_content is {}\n", file_content); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_rpc.put: file_content is {}\n", file_content); - let rpc_tmp_filepath = "/tmp/ipfs_rpc.tmp".to_string(); + let rpc_tmp_filepath = RPC_TMP_FILEPATH.to_string(); let r = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content); if let Err(e) = r { - let msg: String = e.to_string(); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("{}", e); } ipfs_put(rpc_tmp_filepath.as_ptr() as _, rpc_tmp_filepath.len() as _); @@ -59,8 +61,7 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) { *RESULT_SIZE.get_mut(), ); - let msg = format!("ipfs_rpc.put: file add with hash {}\n", hash); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_rpc.put: file add with hash {}\n", hash); *RESULT_PTR.get_mut() = hash.as_ptr() as _; *RESULT_SIZE.get_mut() = hash.len(); @@ -71,8 +72,7 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) { pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size); - let msg = format!("ipfs_rpc.get: getting file with hash {}\n", hash); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_rpc.get: getting file with hash {}\n", hash); ipfs_get(hash.as_ptr() as _, hash.len() as _); @@ -82,8 +82,7 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { *RESULT_SIZE.get_mut(), ); - let msg = format!("ipfs_rpc.get: reading file from {}\n", file_path); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); + println!("ipfs_rpc.get: reading file from {}\n", file_path); let file_content = fs::read(file_path).unwrap_or_else(|_| b"error while reading file".to_vec()); diff --git a/fce/src/vm/module/fce_module.rs b/fce/src/vm/module/fce_module.rs index 0ccf4c86..7261e12a 100644 --- a/fce/src/vm/module/fce_module.rs +++ b/fce/src/vm/module/fce_module.rs @@ -81,6 +81,8 @@ impl FCEModule { mut fce_imports: ImportObject, modules: &HashMap, ) -> Result { + use wasmer_runtime::Func; + let wasmer_module = compile(&wasm_bytes)?; let wit = extract_wit(&wasmer_module)?; let fce_wit = FCEWITInterfaces::new(wit); @@ -100,6 +102,10 @@ impl FCEModule { let exports_funcs = Self::instantiate_wit_exports(wit_instance, &fce_wit)?; + if let Ok(start_func) = wasmer_instance.exports.get::>("_start") { + start_func.call()?; + } + Ok(Self { wamser_instance: Box::new(wasmer_instance), import_object,