Skip to content

Commit

Permalink
chore: Upgrade candid to v0.10 (#448)
Browse files Browse the repository at this point in the history
* chore: Upgrade candid to v0.10

This upgrades candid to the new libary version which has been split into
smaller pieces, hence reducing the size of the dependencies for
downstream projects.

* Adapt cdk-bindgen to new candid_parser library

* Remove setting default value again

* Remove candid dependency from ic-cdk-bindgen

* Reword changelog entry

* Accommodate candid changes with regards to Nat conversions

* Update remaining candid references

* Update even more candid references

* Fix counter example

* Fix nat comparison

* bump versions and changelog

* cargo update

* bump ic-cdk-macros

* mv compile tests to ic-cdk

* bump ic-cdk-bindgen

* README

---------

Co-authored-by: Linwei Shang <linwei.shang@dfinity.org>
  • Loading branch information
Frederik Rothenberger and lwshang authored Nov 23, 2023
1 parent 917a02e commit 710a6cd
Show file tree
Hide file tree
Showing 35 changed files with 401 additions and 442 deletions.
733 changes: 332 additions & 401 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ opt-level = 'z'

[workspace.dependencies]
ic0 = { path = "src/ic0", version = "0.21.1" }
ic-cdk = { path = "src/ic-cdk", version = "0.11.4" }
ic-cdk-timers = { path = "src/ic-cdk-timers", version = "0.5.1" }
ic-cdk = { path = "src/ic-cdk", version = "0.12.0" }
ic-cdk-timers = { path = "src/ic-cdk-timers", version = "0.6.0" }

candid = "0.9.6"
candid = "0.10"
candid_parser = "0.1.0"
futures = "0.3"
hex = "0.4"
quote = "1"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ In Cargo.toml:
crate-type = ["cdylib"]

[dependencies]
candid = "0.9" # this version is required if you want to define Candid data types
ic-cdk = "0.11"
candid = "0.10" # this version is required if you want to define Candid data types
ic-cdk = "0.12"
```

Then in your rust source code:
Expand Down
16 changes: 8 additions & 8 deletions e2e-tests/canisters/management_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mod main {
let arg = CreateCanisterArgument {
settings: Some(CanisterSettings {
controllers: Some(vec![ic_cdk::id()]),
compute_allocation: Some(0.into()),
memory_allocation: Some(10000.into()),
freezing_threshold: Some(10000.into()),
compute_allocation: Some(0u8.into()),
memory_allocation: Some(10000u16.into()),
freezing_threshold: Some(10000u16.into()),
}),
};
let canister_id = create_canister(arg, 100_000_000_000u128 / 13)
Expand Down Expand Up @@ -55,12 +55,12 @@ mod provisional {
async fn execute_provisional_methods() {
let settings = CanisterSettings {
controllers: Some(vec![ic_cdk::caller()]),
compute_allocation: Some(50.into()),
memory_allocation: Some(10000.into()),
freezing_threshold: Some(10000.into()),
compute_allocation: Some(50u8.into()),
memory_allocation: Some(10000u16.into()),
freezing_threshold: Some(10000u16.into()),
};
let arg = ProvisionalCreateCanisterWithCyclesArgument {
amount: Some(1_000_000_000.into()),
amount: Some(1_000_000_000u64.into()),
settings: Some(settings),
};
let canister_id = provisional_create_canister_with_cycles(arg)
Expand All @@ -71,7 +71,7 @@ mod provisional {

let arg = ProvisionalTopUpCanisterArgument {
canister_id,
amount: 1_000_000_000.into(),
amount: 1_000_000_000u64.into(),
};
provisional_top_up_canister(arg).await.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/asset_storage/src/asset_storage_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
candid = "0.9"
candid = "0.10"
ic-cdk = { path = "../../../../src/ic-cdk" }
2 changes: 1 addition & 1 deletion examples/chess/src/chess_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
candid = "0.9.0"
candid = "0.10"
ic-cdk = { path = "../../../../src/ic-cdk" }
serde = "1.0.111"
tanton = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
members = ["src/counter_rs", "src/inter_rs", "src/inter2_rs"]

[workspace.dependencies]
candid = "0.9"
candid = "0.10"
ic-cdk = { path = "../../src/ic-cdk" }
ic-cdk-bindgen = { path = "../../src/ic-cdk-bindgen" }
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 @@ -3,7 +3,7 @@ use ic_cdk::{api::call::ManualReply, init, query, update};
use std::cell::{Cell, RefCell};

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

Expand Down
2 changes: 1 addition & 1 deletion examples/management_canister/src/caller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
candid = "0.9"
candid = "0.10"
ic-cdk = { path = "../../../../src/ic-cdk", features = ["transform-closure"] }
sha2 = "0.10"
2 changes: 1 addition & 1 deletion examples/management_canister/src/caller/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod http_request {
.await
.unwrap()
.0;
assert_eq!(response.status, 200);
assert_eq!(response.status, 200u8);
assert_eq!(response.headers.get(0), Some(&header));
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/print/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ members = ["src/print_rs"]

[workspace.dependencies]
ic-cdk = { path = "../../src/ic-cdk" }
candid = "0.9"
candid = "0.10"
2 changes: 1 addition & 1 deletion examples/profile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["src/profile_rs", "src/profile_inter_rs"]

[workspace.dependencies]
candid = "0.9"
candid = "0.10"
ic-cdk = { path = "../../src/ic-cdk" }
ic-cdk-bindgen = { path = "../../src/ic-cdk-bindgen" }
serde = "1"
5 changes: 5 additions & 0 deletions library/ic-ledger-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.9.0] - 2023-11-23

### Changed
- Upgrade `ic-cdk` to v0.12 and `candid` to v0.10.

## [0.8.0] - 2023-09-18

### Changed
Expand Down
2 changes: 1 addition & 1 deletion library/ic-ledger-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-ledger-types"
version = "0.8.0"
version = "0.9.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions src/ic-cdk-bindgen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.1.2] - 2023-11-23

- Change `candid` dependency to the new `candid_parser` library.
More details here: https://github.com/dfinity/candid/blob/master/Changelog.md#2023-11-16-rust-0100

## [0.1.1] - 2023-09-18

- Update `candid` dependency to 0.9.6 which change the Rust bindings.
Expand Down
4 changes: 2 additions & 2 deletions src/ic-cdk-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-cdk-bindgen"
version = "0.1.1"
version = "0.1.2"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -13,4 +13,4 @@ keywords = ["internet-computer", "types", "dfinity", "canister", "cdk"]
include = ["src", "Cargo.toml", "LICENSE", "README.md"]

[dependencies]
candid = { workspace = true, features = ["parser"] }
candid_parser.workspace = true
20 changes: 11 additions & 9 deletions src/ic-cdk-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use candid::{bindings::rust, pretty_check_file, Principal};
use candid_parser::{bindings::rust, pretty_check_file, Principal};
use std::env;
use std::fs;
use std::io::Write;
Expand All @@ -11,6 +11,7 @@ pub struct Config {
pub skip_existing_files: bool,
pub binding: rust::Config,
}

impl Config {
pub fn new(canister_name: &str) -> Self {
let candid_path_var_name = format!("CANISTER_CANDID_PATH_{}", canister_name);
Expand All @@ -20,18 +21,19 @@ impl Config {
let canister_id =
Principal::from_text(env::var(canister_id_var_name).expect("Cannot find canister id"))
.unwrap();
let mut binding = rust::Config::new();
binding
// User will depend on candid crate directly
.set_candid_crate("candid".to_string())
.set_canister_id(canister_id)
.set_service_name(canister_name.to_string())
.set_target(rust::Target::CanisterCall);

Config {
canister_name: canister_name.to_string(),
candid_path,
skip_existing_files: false,
binding: rust::Config {
// User will depend on candid crate directly
candid_crate: "candid".to_string(),
type_attributes: "".to_string(),
canister_id: Some(canister_id),
service_name: canister_name.to_string(),
target: rust::Target::CanisterCall,
},
binding,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/ic-cdk-macros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.8.2] - 2023-11-23

### Changed

- Upgrade `candid` to `0.10`. (#448)

## [0.8.1] - 2023-10-02

### Fixed
Expand Down
6 changes: 1 addition & 5 deletions src/ic-cdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-cdk-macros"
version = "0.8.1" # no need to sync with ic-cdk
version = "0.8.2" # no need to sync with ic-cdk
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down Expand Up @@ -29,7 +29,3 @@ quote.workspace = true
serde.workspace = true
serde_tokenstream = "0.1.0"
syn = { workspace = true, features = ["fold", "full"] }

[dev-dependencies]
trybuild = "1.0"
ic-cdk.workspace = true
6 changes: 6 additions & 0 deletions src/ic-cdk-timers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.6.0] - 2023-11-23

### Changed

- Upgrade `ic-cdk` to v0.12.

## [0.5.0] - 2023-09-18

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/ic-cdk-timers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-cdk-timers"
version = "0.5.1"
version = "0.6.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions src/ic-cdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.12.0] - 2023-11-23

### Changed

- Upgrade `candid` to `0.10`. (#448)

## [0.11.4] - 2023-11-20

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/ic-cdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-cdk"
version = "0.11.4"
version = "0.12.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -22,13 +22,14 @@ include = ["src", "Cargo.toml", "LICENSE", "README.md"]
[dependencies]
candid.workspace = true
ic0.workspace = true
ic-cdk-macros = { path = "../ic-cdk-macros", version = "0.8.0" }
ic-cdk-macros = { path = "../ic-cdk-macros", version = "0.8.2" }
serde.workspace = true
serde_bytes.workspace = true
slotmap = { workspace = true, optional = true }

[dev-dependencies]
rstest = "0.12.0"
trybuild = "1.0"

[features]
transform-closure = ["dep:slotmap"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 710a6cd

Please sign in to comment.