mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 22:30:50 +00:00
add docs for public crates
This commit is contained in:
parent
be0451accb
commit
5f26af7990
@ -22,11 +22,10 @@ fluence-sdk-main = { path = "crates/main", version = "=0.2.0" }
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Print some internal logs by log_utf8_string
|
# Print some internal logs by log_utf8_string
|
||||||
print_logs = ["fluence-sdk-main/print_logs"]
|
debug = ["fluence-sdk-main/debug"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"crates/greeting",
|
|
||||||
"crates/main",
|
"crates/main",
|
||||||
"crates/macro",
|
"crates/macro",
|
||||||
"crates/wit-support",
|
"crates/wit-support",
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "greeting"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["vms <michail.vms@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
fluence = { path = "../../", version = "=0.2.0" }
|
|
@ -1,18 +0,0 @@
|
|||||||
use fluence::fce;
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
|
|
||||||
#[fce]
|
|
||||||
pub fn greeting(arg: String, arg2: String, arg3: i32) -> i64 {
|
|
||||||
let res = format!("Hi {} {}", arg, arg2);
|
|
||||||
ipfs(res, arg2);
|
|
||||||
ipfs1(arg);
|
|
||||||
arg3 as _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[fce]
|
|
||||||
#[link(wasm_import_module = "ipfs_node.wasm")]
|
|
||||||
extern "C" {
|
|
||||||
pub fn ipfs(cmd: String, aa: String) -> String;
|
|
||||||
pub fn ipfs1(cmd: String) -> String;
|
|
||||||
}
|
|
@ -14,6 +14,46 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//! Defines the #[fce] macro that should be used with all export functions, extern blocks.
|
||||||
|
//! At now, It supports the following types that could be used as parameters in export or foreign
|
||||||
|
//! functions: i8, i16, i32, i64, u8, u16, u32, u64, f32, f64, bool, String, Vec<u8>. Also struct
|
||||||
|
//! where all fields are public and have aforementioned types could be used as parameters. In this
|
||||||
|
//! case #[fce] should be also applied to this structs.
|
||||||
|
//!
|
||||||
|
//! # Examples
|
||||||
|
//!
|
||||||
|
//! This example shows how a function could be exported:
|
||||||
|
//! ```
|
||||||
|
//! #[fce]
|
||||||
|
//! pub fn greeting(name: String) -> String {
|
||||||
|
//! format!("Hi {}", name)
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! This more complex example shows how a function could be imported from another Wasm module
|
||||||
|
//! and how a struct could be passed:
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! #[fce]
|
||||||
|
//! struct HostReturnValue {
|
||||||
|
//! pub error_code: i32,
|
||||||
|
//! pub outcome: Vec<u8>
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! #[fce]
|
||||||
|
//! pub fn read_ipfs_file(file_path: String) -> HostReturnValue {
|
||||||
|
//! let hash = calculate_hash(file_path);
|
||||||
|
//! ipfs(hash)
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! #[fce]
|
||||||
|
//! #[link(wasm_import_module = "ipfs_node.wasm")]
|
||||||
|
//! extern "C" {
|
||||||
|
//! pub fn ipfs(file_hash: String) -> HostReturnValue;
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/fluence-sdk-macro/0.2.0")]
|
#![doc(html_root_url = "https://docs.rs/fluence-sdk-macro/0.2.0")]
|
||||||
#![deny(
|
#![deny(
|
||||||
dead_code,
|
dead_code,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "fluence-sdk-main"
|
name = "fluence-sdk-main"
|
||||||
version = "0.2.0" # remember to update html_root_url
|
version = "0.2.0" # remember to update html_root_url
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Rust SDK for writing applications for Fluence"
|
description = "Rust SDK for applications for the Fluence network"
|
||||||
documentation = "https://docs.rs/fluence/fluence-sdk-macro"
|
documentation = "https://docs.rs/fluence/fluence-sdk-macro"
|
||||||
repository = "https://github.com/fluencelabs/rust-sdk/crates/main"
|
repository = "https://github.com/fluencelabs/rust-sdk/crates/main"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
@ -26,4 +26,4 @@ lazy_static = "1.4.0" # used in doc test
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Print some internal logs by log_utf8_string
|
# Print some internal logs by log_utf8_string
|
||||||
print_logs = []
|
debug = []
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::log_utf8_string;
|
use super::log;
|
||||||
|
|
||||||
use std::alloc::alloc as global_alloc;
|
use std::alloc::alloc as global_alloc;
|
||||||
use std::alloc::dealloc as global_dealloc;
|
use std::alloc::dealloc as global_dealloc;
|
||||||
@ -31,8 +31,7 @@ pub unsafe fn allocate(size: usize) -> usize {
|
|||||||
Err(_) => return 0,
|
Err(_) => return 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = format!("sdk.allocate: {:?}\n", size);
|
log(format!("sdk.allocate: {:?}\n", size));
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
global_alloc(layout) as _
|
global_alloc(layout) as _
|
||||||
}
|
}
|
||||||
@ -48,8 +47,7 @@ pub unsafe fn deallocate(ptr: *mut u8, size: usize) {
|
|||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = format!("sdk.deallocate: {:?} {}\n", ptr, size);
|
log(format!("sdk.deallocate: {:?} {}\n", ptr, size));
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
global_dealloc(ptr, layout);
|
global_dealloc(ptr, layout);
|
||||||
}
|
}
|
@ -35,8 +35,6 @@ mod export_allocator;
|
|||||||
mod logger;
|
mod logger;
|
||||||
mod result;
|
mod result;
|
||||||
|
|
||||||
pub(crate) use logger::log_utf8_string;
|
|
||||||
|
|
||||||
pub use export_allocator::allocate;
|
pub use export_allocator::allocate;
|
||||||
pub use export_allocator::deallocate;
|
pub use export_allocator::deallocate;
|
||||||
pub use logger::WasmLogger;
|
pub use logger::WasmLogger;
|
||||||
@ -44,3 +42,13 @@ pub use result::get_result_ptr;
|
|||||||
pub use result::get_result_size;
|
pub use result::get_result_size;
|
||||||
pub use result::set_result_ptr;
|
pub use result::set_result_ptr;
|
||||||
pub use result::set_result_size;
|
pub use result::set_result_size;
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub(crate) fn log<S: AsRef<str>>(msg: S) {
|
||||||
|
// logs will be printed only if debug feature is enabled
|
||||||
|
#[cfg(debug)]
|
||||||
|
unsafe {
|
||||||
|
let msg = msg.as_ref();
|
||||||
|
logger::log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,17 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! This module enables log messages from the Wasm side. It is implemented as a logging facade for
|
//! This module allows log messages from the Wasm side. It is implemented as a logging facade for
|
||||||
//! crate [`log`]. To enable this module in your project please specify `wasm_logger` feature of
|
//! crate [`log`].
|
||||||
//! `fluence_sdk`.
|
|
||||||
//!
|
|
||||||
//! Note that this module works only for the Wasm environments and Fluence `WasmVm` - with this
|
|
||||||
//! feature set it is possible to compile applications only for Wasm targets such as
|
|
||||||
//! `wasm32-unknown-unknown`, `wasm32-wasi`. (please refer to the first example to find out a way
|
|
||||||
//! to avoid it).
|
|
||||||
//!
|
|
||||||
//! This feature should be used only for debugging purposes, you can find more info in the
|
|
||||||
//! [`backend app debugging`] section of the Fluence guide.
|
|
||||||
//!
|
//!
|
||||||
//! # Examples
|
//! # Examples
|
||||||
//!
|
//!
|
@ -14,7 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::log_utf8_string;
|
//! Contains ad-hoc implementations of returning complex data types from function calls
|
||||||
|
//! by two global variables that contain pointer and size. Will be refactored after multi-value
|
||||||
|
//! support in Wasmer.
|
||||||
|
|
||||||
|
use super::log;
|
||||||
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
|
||||||
@ -23,32 +27,28 @@ 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 = "sdk.get_result_ptr\n";
|
log("sdk.get_result_ptr\n");
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
*RESULT_PTR.get_mut()
|
*RESULT_PTR.get_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn get_result_size() -> usize {
|
pub unsafe fn get_result_size() -> usize {
|
||||||
let msg = "sdk.get_result_size\n";
|
log("sdk.get_result_size\n");
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
*RESULT_SIZE.get_mut()
|
*RESULT_SIZE.get_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn set_result_ptr(ptr: usize) {
|
pub unsafe fn set_result_ptr(ptr: usize) {
|
||||||
let msg = format!("sdk.set_result_ptr: {}\n", ptr);
|
log(format!("sdk.set_result_ptr: {}\n", ptr));
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
*RESULT_PTR.get_mut() = ptr;
|
*RESULT_PTR.get_mut() = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn set_result_size(size: usize) {
|
pub unsafe fn set_result_size(size: usize) {
|
||||||
let msg = format!("sdk.set_result_size: {}\n", size);
|
log(format!("sdk.set_result_size: {}\n", size));
|
||||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
|
||||||
|
|
||||||
*RESULT_SIZE.get_mut() = size;
|
*RESULT_SIZE.get_mut() = size;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wit"
|
name = "fluence-wit"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
@ -14,14 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! Rust backend SDK for writing applications for Fluence. This crate is just a wrapper for two
|
//! Rust backend SDK for applications on the Fluence network. This crate is just a wrapper for two
|
||||||
//! other crates: `main` and `macro`. The `main` crate is used for all memory relative operations
|
//! other crates: `main` and `macro`. The `main` crate is used for all memory relative operations
|
||||||
//! and logging, while the `macro` crate contains the invocation macro to simplify entry point
|
//! and logging, while the `macro` crate contains the invocation macro to simplify entry point
|
||||||
//! functions.
|
//! functions.
|
||||||
//!
|
//!
|
||||||
//! By default this crate turns on export-allocator feature of the `main` crate, to disable it
|
|
||||||
//! please import this crate with `default-features = false`.
|
|
||||||
//!
|
|
||||||
#![doc(html_root_url = "https://docs.rs/fluence/0.2.0")]
|
#![doc(html_root_url = "https://docs.rs/fluence/0.2.0")]
|
||||||
#![deny(
|
#![deny(
|
||||||
dead_code,
|
dead_code,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user