From 81ea09a33e19d4d7599aa06b950521c8f5fe9311 Mon Sep 17 00:00:00 2001 From: Parsa Ghadimi Date: Sat, 3 Sep 2022 12:34:40 +0300 Subject: [PATCH] the kit-wasm-export feature should be present to export function for WASM this allows a canister to import another canister as crate without re-implementing that canister --- examples/counter/Cargo.toml | 6 +++--- examples/counter/src/main.rs | 3 --- examples/factory_counter/Cargo.toml | 6 +++--- examples/factory_counter/src/main.rs | 2 -- examples/fib/Cargo.toml | 6 +++--- examples/fib/src/main.rs | 2 -- examples/multi_counter/Cargo.toml | 8 ++++---- examples/multi_counter/src/canister.rs | 3 ++- examples/multi_counter/src/main.rs | 2 -- examples/naming_system/Cargo.toml | 6 +++--- examples/naming_system/src/main.rs | 2 -- ic-kit-macros/src/entry.rs | 19 ++++++++++--------- 12 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 examples/counter/src/main.rs delete mode 100644 examples/factory_counter/src/main.rs delete mode 100644 examples/fib/src/main.rs delete mode 100644 examples/multi_counter/src/main.rs delete mode 100644 examples/naming_system/src/main.rs diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 7ad73c8..ef51747 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -8,6 +8,6 @@ edition = "2021" [dependencies] ic-kit = {path="../../ic-kit"} -[[bin]] -name = "ic_kit_example_counter" -path = "src/main.rs" +[features] +default = ["kit-wasm-export"] +kit-wasm-export = [] diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs deleted file mode 100644 index c53437a..0000000 --- a/examples/counter/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod canister; - -fn main() {} diff --git a/examples/factory_counter/Cargo.toml b/examples/factory_counter/Cargo.toml index d3762eb..d0f9975 100644 --- a/examples/factory_counter/Cargo.toml +++ b/examples/factory_counter/Cargo.toml @@ -9,6 +9,6 @@ edition = "2021" ic-kit = {path="../../ic-kit"} ic_kit_example_counter = {path="../counter"} -[[bin]] -name = "ic_kit_example_factory_counter" -path = "src/main.rs" +[features] +default = ["kit-wasm-export"] +kit-wasm-export = [] diff --git a/examples/factory_counter/src/main.rs b/examples/factory_counter/src/main.rs deleted file mode 100644 index 8fc52ee..0000000 --- a/examples/factory_counter/src/main.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod canister; -fn main() {} diff --git a/examples/fib/Cargo.toml b/examples/fib/Cargo.toml index 083f3b2..8e6b9e3 100644 --- a/examples/fib/Cargo.toml +++ b/examples/fib/Cargo.toml @@ -8,6 +8,6 @@ edition = "2021" [dependencies] ic-kit = {path="../../ic-kit"} -[[bin]] -name = "ic_kit_example_fib" -path = "src/main.rs" +[features] +default = ["kit-wasm-export"] +kit-wasm-export = [] diff --git a/examples/fib/src/main.rs b/examples/fib/src/main.rs deleted file mode 100644 index 8fc52ee..0000000 --- a/examples/fib/src/main.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod canister; -fn main() {} diff --git a/examples/multi_counter/Cargo.toml b/examples/multi_counter/Cargo.toml index 2ec2d94..d46729f 100644 --- a/examples/multi_counter/Cargo.toml +++ b/examples/multi_counter/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] ic-kit = {path="../../ic-kit"} -ic_kit_example_counter = {path="../counter"} +ic_kit_example_counter = {path="../counter", default-features=false} -[[bin]] -name = "ic_kit_example_multi_counter" -path = "src/main.rs" +[features] +default = ["kit-wasm-export"] +kit-wasm-export = [] diff --git a/examples/multi_counter/src/canister.rs b/examples/multi_counter/src/canister.rs index ec9d386..d35c6b7 100644 --- a/examples/multi_counter/src/canister.rs +++ b/examples/multi_counter/src/canister.rs @@ -1,6 +1,8 @@ use ic_kit::prelude::*; use std::collections::HashSet; +use ic_kit_example_counter::CounterCanister; + #[derive(Default)] struct MultiCounter { canister_ids: HashSet, @@ -32,7 +34,6 @@ pub struct MultiCounterCanister; #[cfg(test)] mod tests { use super::*; - use ic_kit_example_counter::CounterCanister; #[kit_test] async fn test_multi_canister(replica: Replica) { diff --git a/examples/multi_counter/src/main.rs b/examples/multi_counter/src/main.rs deleted file mode 100644 index 8fc52ee..0000000 --- a/examples/multi_counter/src/main.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod canister; -fn main() {} diff --git a/examples/naming_system/Cargo.toml b/examples/naming_system/Cargo.toml index 7831ace..95c5b8a 100644 --- a/examples/naming_system/Cargo.toml +++ b/examples/naming_system/Cargo.toml @@ -8,6 +8,6 @@ edition = "2021" [dependencies] ic-kit = {path="../../ic-kit"} -[[bin]] -name = "ic_kit_example_naming_system" -path = "src/main.rs" +[features] +default = ["kit-wasm-export"] +kit-wasm-export = [] diff --git a/examples/naming_system/src/main.rs b/examples/naming_system/src/main.rs deleted file mode 100644 index 8fc52ee..0000000 --- a/examples/naming_system/src/main.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod canister; -fn main() {} diff --git a/ic-kit-macros/src/entry.rs b/ic-kit-macros/src/entry.rs index 93921cc..9fafc86 100644 --- a/ic-kit-macros/src/entry.rs +++ b/ic-kit-macros/src/entry.rs @@ -148,6 +148,11 @@ pub fn gen_entry_point_code( Span::call_site(), ); + let export_function_dent = Ident::new( + &format!("_ic_kit_exported_canister_{}_{}", entry_point, name), + Span::call_site(), + ); + let guard = if let Some(guard_name) = attrs.guard { let guard_ident = Ident::new(&guard_name, Span::call_site()); @@ -299,9 +304,8 @@ pub fn gen_entry_point_code( } } - #[cfg(target_family = "wasm")] #[doc(hidden)] - #[export_name = #export_name] + #[inline(always)] fn #outer_function_ident() { #[cfg(target_family = "wasm")] ic_kit::setup_hooks(); @@ -310,14 +314,11 @@ pub fn gen_entry_point_code( #body } - #[cfg(not(target_family = "wasm"))] + #[cfg(feature="kit-wasm-export")] + #[export_name = #export_name] #[doc(hidden)] - fn #outer_function_ident() { - #[cfg(target_family = "wasm")] - ic_kit::setup_hooks(); - - #guard - #body + fn #export_function_dent() { + #outer_function_ident } #[inline(always)]