Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ic-cdk-bindgen v0.2 to support Trait-Bound Canister Development #487

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 81 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ic0 = { path = "src/ic0", version = "0.23.0" }
ic-cdk = { path = "src/ic-cdk", version = "0.16.0" }
ic-cdk-timers = { path = "src/ic-cdk-timers", version = "0.10.0" }

candid = "0.10.4"
candid_parser = "0.1.4"
candid = "0.10.9"
candid_parser = "0.2.0-beta.3"
futures = "0.3"
hex = "0.4"
quote = "1"
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/src/counter_rs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::cell::{Cell, RefCell};

thread_local! {
static COUNTER: RefCell<candid::Nat> = RefCell::new(candid::Nat::from(0u8));
static OWNER: Cell<Principal> = Cell::new(Principal::from_slice(&[]));
static OWNER: Cell<Principal> = const {Cell::new(Principal::from_slice(&[]))};
}

#[init]
Expand Down
13 changes: 4 additions & 9 deletions examples/counter/src/inter2_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use ic_cdk_bindgen::{Builder, Config};
use std::path::PathBuf;

fn main() {
let manifest_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("Cannot find manifest dir"));
let inter_mo = Config::new("inter_mo");
let mut builder = Builder::new();
builder.add(inter_mo);
builder.build(Some(manifest_dir.join("declarations")));
println!("cargo:rerun-if-changed=build.rs");
ic_cdk_bindgen::Builder::new("inter_mo")
.generate_consumer()
.unwrap();
}
6 changes: 4 additions & 2 deletions examples/counter/src/inter2_rs/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ic_cdk::update;

mod declarations;
use declarations::inter_mo::inter_mo;
mod inter_mo {
include!(concat!(env!("OUT_DIR"), "/consumer/inter_mo.rs"));
}
use inter_mo::inter_mo;

#[update]
async fn read() -> candid::Nat {
Expand Down
13 changes: 4 additions & 9 deletions examples/counter/src/inter_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use ic_cdk_bindgen::{Builder, Config};
use std::path::PathBuf;

fn main() {
let manifest_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("Cannot find manifest dir"));
let counter = Config::new("counter_mo");
let mut builder = Builder::new();
builder.add(counter);
builder.build(Some(manifest_dir.join("declarations")));
println!("cargo:rerun-if-changed=build.rs");
ic_cdk_bindgen::Builder::new("counter_mo")
.generate_consumer()
.unwrap();
}
6 changes: 4 additions & 2 deletions examples/counter/src/inter_rs/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ic_cdk::update;

mod declarations;
use declarations::counter_mo::counter_mo;
mod counter_mo {
include!(concat!(env!("OUT_DIR"), "/consumer/counter_mo.rs"));
}
use counter_mo::counter_mo;

#[update]
async fn read() -> candid::Nat {
Expand Down
22 changes: 11 additions & 11 deletions examples/profile/src/profile_inter_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use ic_cdk_bindgen::{Builder, Config};
use std::path::PathBuf;

fn main() {
// A workaround to force always rerun build.rs
println!("cargo:rerun-if-changed=NULL");
let manifest_dir =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("Cannot find manifest dir"));
let profile_rs = Config::new("profile_rs");
let mut builder = Builder::new();
builder.add(profile_rs);
builder.build(Some(manifest_dir.join("declarations")));
// println!("cargo:rerun-if-changed=build.rs");
ic_cdk_bindgen::Builder::new("profile_rs")
.candid_path("../profile_rs/profile.did")
.generate_consumer()
.unwrap();

ic_cdk_bindgen::Builder::new("profile_inter_rs")
.candid_path("profile.did")
.out_dir("declarations")
.generate_type()
.unwrap();
}
6 changes: 4 additions & 2 deletions examples/profile/src/profile_inter_rs/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ic_cdk::update;

mod declarations;
use declarations::profile_rs::{profile_rs, Profile};
mod profile_rs {
include!(concat!(env!("OUT_DIR"), "/consumer/profile_rs.rs"));
}
use profile_rs::{profile_rs, Profile};

#[update(name = "getSelf")]
async fn get_self() -> Profile {
Expand Down
10 changes: 4 additions & 6 deletions examples/profile/tests/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ teardown() {
assert_output '(opt record { name = "def"; description = "456"; keywords = vec {} })'
}

@test "ic-cdk-bindgen warns about deprecated env vars when running with dfx v0.13.1" {
dfxvm install 0.13.1
run dfx +0.13.1 build --check
@test "profile_inter_rs build.rs can generate type bindings in specified dir" {
dfx build --check
run test -f src/profile_inter_rs/declarations/type/profile_inter_rs.rs
assert_success
assert_regex "$output" "The environment variable CANISTER_CANDID_PATH_profile_rs is deprecated. Please set CANISTER_CANDID_PATH_PROFILE_RS instead. Upgrading dfx may fix this issue."
assert_regex "$output" "The environment variable CANISTER_ID_profile_rs is deprecated. Please set CANISTER_ID_PROFILE_RS instead. Upgrading dfx may fix this issue."
}
}
3 changes: 1 addition & 2 deletions src/ic-cdk-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ include = ["src", "Cargo.toml", "LICENSE", "README.md"]
[dependencies]
candid.workspace = true
candid_parser.workspace = true
convert_case = "0.6"
pretty = "0.12"
thiserror = "1.0"
Loading