From 043af06af65a29b0df548f6d65ab7f026a20aab7 Mon Sep 17 00:00:00 2001 From: vms Date: Tue, 14 Jul 2020 00:36:23 +0300 Subject: [PATCH] add logger feature --- Cargo.toml | 3 +++ crates/macro/Cargo.toml | 2 +- crates/main/Cargo.toml | 3 +++ crates/main/src/lib.rs | 2 ++ crates/wit/src/token_stream_generator/fn_generator.rs | 3 ++- .../wit/src/token_stream_generator/foreign_mod_generator.rs | 6 +++--- crates/wit/src/token_stream_generator/record_generator.rs | 1 - src/lib.rs | 1 + 8 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25bf9bd..588fbc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,9 @@ fluence-sdk-main = { path = "crates/main", version = "=0.2.0" } # Print some internal logs by log_utf8_string debug = ["fluence-sdk-main/debug"] +# Print some internal logs by log_utf8_string +logger = ["fluence-sdk-main/logger"] + [workspace] members = [ "crates/main", diff --git a/crates/macro/Cargo.toml b/crates/macro/Cargo.toml index 02d851f..2688df7 100644 --- a/crates/macro/Cargo.toml +++ b/crates/macro/Cargo.toml @@ -17,4 +17,4 @@ all-features = true proc-macro = true [dependencies] -fluence-sdk-wit = { path = "../wit" } +fluence-sdk-wit = { path = "../wit", version = "=0.2.0" } diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index f93de22..7c814dc 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -27,3 +27,6 @@ lazy_static = "1.4.0" # used in doc test [features] # Print some internal logs by log_utf8_string debug = [] + +# Enable logger, this will cause log_utf8_string to appear in imports +logger = [] diff --git a/crates/main/src/lib.rs b/crates/main/src/lib.rs index a2ae431..97fb746 100644 --- a/crates/main/src/lib.rs +++ b/crates/main/src/lib.rs @@ -32,11 +32,13 @@ #![warn(rust_2018_idioms)] mod export_allocator; +#[cfg(feature = "logger")] mod logger; mod result; pub use export_allocator::allocate; pub use export_allocator::deallocate; +#[cfg(feature = "logger")] pub use logger::WasmLogger; pub use result::get_result_ptr; pub use result::get_result_size; diff --git a/crates/wit/src/token_stream_generator/fn_generator.rs b/crates/wit/src/token_stream_generator/fn_generator.rs index 46df060..4f76491 100644 --- a/crates/wit/src/token_stream_generator/fn_generator.rs +++ b/crates/wit/src/token_stream_generator/fn_generator.rs @@ -68,6 +68,7 @@ impl quote::ToTokens for fce_ast_types::AstFunctionItem { #[doc(hidden)] #[allow(clippy::all)] pub unsafe fn #func_name(#(#raw_arg_names: #raw_arg_types),*) #fn_return_type { + // arguments conversation from Wasm types to Rust types #prolog // calling the original function with converted args @@ -77,7 +78,7 @@ impl quote::ToTokens for fce_ast_types::AstFunctionItem { #epilog } - // #[cfg(target_arch = "wasm32")] + #[cfg(target_arch = "wasm32")] #[doc(hidden)] #[allow(clippy::all)] #[link_section = #section_name] diff --git a/crates/wit/src/token_stream_generator/foreign_mod_generator.rs b/crates/wit/src/token_stream_generator/foreign_mod_generator.rs index 0c19119..9d600c7 100644 --- a/crates/wit/src/token_stream_generator/foreign_mod_generator.rs +++ b/crates/wit/src/token_stream_generator/foreign_mod_generator.rs @@ -40,14 +40,14 @@ impl quote::ToTokens for fce_ast_types::AstExternModItem { let glue_code = quote! { #[link(wasm_import_module = #wasm_import_module_name)] - // #[cfg(target_arch = "wasm32")] + #[cfg(target_arch = "wasm32")] extern "C" { #generated_imports } #wrapper_functions - // #[cfg(target_arch = "wasm32")] + #[cfg(target_arch = "wasm32")] #[doc(hidden)] #[allow(clippy::all)] #[link_section = #section_name] @@ -113,7 +113,7 @@ fn generate_wrapper_functions(extern_item: &fce_ast_types::AstExternModItem) -> let epilog = signature.output_type.generate_wrapper_epilog(); let wrapper_func = quote! { - // #[cfg(target_arch = "wasm32")] + #[cfg(target_arch = "wasm32")] #[doc(hidden)] #[allow(clippy::all)] #visibility fn #func_name(#(#arg_names: #arg_types), *) #return_type { diff --git a/crates/wit/src/token_stream_generator/record_generator.rs b/crates/wit/src/token_stream_generator/record_generator.rs index 8af4bb9..c9f207f 100644 --- a/crates/wit/src/token_stream_generator/record_generator.rs +++ b/crates/wit/src/token_stream_generator/record_generator.rs @@ -37,7 +37,6 @@ impl quote::ToTokens for fce_ast_types::AstRecordItem { #[allow(clippy::all)] #[link_section = #section_name] pub static #global_static_name: [u8; #data_size] = { *#data }; - }; tokens.extend(glue_code); diff --git a/src/lib.rs b/src/lib.rs index b0a83c7..61a856d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ extern crate fluence_sdk_macro; extern crate fluence_sdk_main; pub use fluence_sdk_macro::fce; +#[cfg(feature = "logger")] pub use fluence_sdk_main::WasmLogger; /// These API functions are intended for internal usage in generated code.