Skip to content

Commit

Permalink
the kit-wasm-export feature should be present to export function for …
Browse files Browse the repository at this point in the history
…WASM

this allows a canister to import another canister as crate without re-implementing that canister
  • Loading branch information
qti3e committed Sep 3, 2022
1 parent 406cd63 commit 81ea09a
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 37 deletions.
6 changes: 3 additions & 3 deletions examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
3 changes: 0 additions & 3 deletions examples/counter/src/main.rs

This file was deleted.

6 changes: 3 additions & 3 deletions examples/factory_counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
2 changes: 0 additions & 2 deletions examples/factory_counter/src/main.rs

This file was deleted.

6 changes: 3 additions & 3 deletions examples/fib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
2 changes: 0 additions & 2 deletions examples/fib/src/main.rs

This file was deleted.

8 changes: 4 additions & 4 deletions examples/multi_counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
3 changes: 2 additions & 1 deletion examples/multi_counter/src/canister.rs
Original file line number Diff line number Diff line change
@@ -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<Principal>,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions examples/multi_counter/src/main.rs

This file was deleted.

6 changes: 3 additions & 3 deletions examples/naming_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
2 changes: 0 additions & 2 deletions examples/naming_system/src/main.rs

This file was deleted.

19 changes: 10 additions & 9 deletions ic-kit-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand All @@ -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)]
Expand Down

0 comments on commit 81ea09a

Please sign in to comment.