Skip to content

feat: Unify ic-cdk to v0.18.6#6264

Merged
lwshang merged 25 commits into
masterfrom
lwshang/SDK-2267_unify_ic_cdk
Aug 20, 2025
Merged

feat: Unify ic-cdk to v0.18.6#6264
lwshang merged 25 commits into
masterfrom
lwshang/SDK-2267_unify_ic_cdk

Conversation

@lwshang
Copy link
Copy Markdown
Contributor

@lwshang lwshang commented Aug 13, 2025

This PR unifies the ic-cdk dependency to v0.18.6.

Background

A while ago, the release of ic-cdk v0.18 caused some issues. We discovered that mixing different versions of ic-cdkwithin a single canister could break execution, a problem that often occurred when a project's dependencies relied on different ic-cdk versions.

To fix this, we extracted the asynchronous execution logic into a new crate, ic-cdk-executor. As long as different versions of ic-cdk depend on the same version of the executor crate, they can now coexist. We patched older versions of ic-cdk (v0.17 and below) to use ic-cdk-executor v0.1.0, and ic-cdk v0.18 and later now use the stable ic-cdk-executor v1.0.

Because the executor crate is designed to only allow one version in a dependency tree, we're doing a one-time migration to unify all ic-cdk dependencies in the ic mono-repo to the latest v0.18.6.

Major Changes

Dependency Upgrades

  • ic-cdk v0.18.6
  • ic-cdk-executor v1.0.2
  • ic-cdk-timers v0.12.2
  • canbench-rs v0.2.1
  • candid v0.10.17
  • ic-canister-sig-creation v1.3.0
  • ic-vetkeys 0.4.0

Wrap custom canister entry-points in executor_context

Some canister entry-points are defined using the #[export_name = "..."] annotation instead of ic-cdk macros like #[update]. The function body are now required to be wrapped in ic_cdk::futures::in_executor_context or ic_cdk::futures::in_query_executor_context. This is a replacement for the removed ic_cdk::setup().

Example:

#[export_name = "canister_query get_block_pb"]
fn get_block_() {
    ic_cdk::setup();
    ...
}

=>

#[export_name = "canister_query get_block_pb"]
fn get_block_() {
    in_query_executor_context(|| {
        ...
    })
}

Replace decoding_quota with decode_with

Example:

#[query(hidden = true, decoding_quota = 10000)]
fn some_query(arg: SomeType) { ... }

=>

#[query(decode_with = "candid::decode_one_with_decoding_quota::<100000,_>")]
fn some_query(arg: SomeType) { ... }

The entry-points using decode_with option will be rendered as blob in the auto-generated Candid interface.
To preserve the original type information, the Candid auto-generation is disabled by hidden = true. And a dummy function is added to generate the desired Candid type.

// Manually add a dummy method so that the Candid interface can be properly generated:
//   `http_request: (HttpRequest) -> (HttpResponse) query;`
// Without this dummy method, it will be `http_request: (blob) -> (HttpResponse) query;`
// because of the `decode_with` option used above.
#[::candid::candid_method(query, rename = "http_request")]
#[allow(unused_variables)]
fn __candid_method_http_request(request: HttpRequest) -> HttpResponse {
    panic!("candid dummy function called")
}

Annotate #![allow(deprecated)]

To keep this PR focused and manageable, we've used #![allow(deprecated)] to suppress warnings in files that call deprecated ic-cdk APIs. These APIs are safe to continue using for now, and this approach allows us to postpone the necessary code refactoring. The task of updating these APIs can now be handled by the respective teams that own this code.

API replacement

For files that only use a few deprecated ic-cdk APIs, we've replaced them directly. For example:

  • ic_cdk::spawn -> ic_cdk::futures::spwan_017_compat
  • ic_cdk::id -> ic_cdk::api::canister_self
  • ic_cdk::caller -> ic_cdk::api::msg_caller
  • ic_cdk::api::set_certified_data -> ic_cdk::api::certified_data_set
  • ic_cdk::api::canister_balance -> ic_cdk::api::canister_cycle_balance
  • ic_cdk::api::stable -> ic_cdk::stable

What's Next?

This migration provides the foundation for future work. Owning teams are encouraged to refactor their code away from the deprecated ic-cdk APIs. A comprehensive migration guide is available to assist with this process.

Remove ic-cdk-next which used to be ic-cdk v0.18.0-beta.2
Also bump:
  ic-canister-sig-creation = "1.3.0"
  ic-vetkeys = "0.4.0"
  canbench-rs = "0.2.1"
so that they transitively depend on ic-cdk v0.18.

Fix ic-vetkeys API usage change in ic/rs/tests/consensus/vetkd/vetkd_key_life_cycle_test.rs
If async code is involved, also use spawn_017_compat.
If the change needed is straight-forward (replace few API), then just
change it.
@lwshang lwshang changed the title feat!(deps): Unify ic-cdk to v0.18.5 feat: Unify ic-cdk to v0.18.5 Aug 13, 2025
@github-actions github-actions Bot added the feat label Aug 13, 2025
lwshang added 17 commits August 14, 2025 00:11
Remove explicit usage of candid_method.
Add dummy methods for http_request to generate valid did.
Also include `ic-cdk-executor` in external_crates.bzl
and specify it with the latest v1.0.2 which contains a fix.
These files have #[cfg(target_arch = "wasm32")], but `cargo clippy
--all-targets` couldn't detect deprecated code under it.
by update IC0_TRAP_BACKTRACE in
rs/execution_environment/tests/backtraces.rs.
The change is caused by `ic-cdk-executor` v1.0.2.
…_tests/storage_reservation_test

by update the RESERVED_BY_SNAPSHOT constant.
@lwshang lwshang marked this pull request as ready for review August 19, 2025 15:42
@lwshang lwshang requested review from a team as code owners August 19, 2025 15:42
@lwshang lwshang dismissed github-actions[bot]’s stale review August 19, 2025 15:45

This is majorly a dependency upgrade. No behavior changes is expected.
We rely on existing CI to detect any regression.

Comment thread rs/nns/integration_tests/src/bad_input.rs Outdated
@gregorydemay gregorydemay added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Aug 19, 2025
Copy link
Copy Markdown
Contributor

@gregorydemay gregorydemay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lwshang for this huge effort!

Use a different entry-point which takes arguments so that the default
skipping quota takes effect.
@lwshang lwshang changed the title feat: Unify ic-cdk to v0.18.5 feat: Unify ic-cdk to v0.18.6 Aug 19, 2025
Comment thread rs/sns/governance/canister/canister.rs
Comment thread rs/sns/governance/src/governance.rs
Comment thread rs/sns/treasury_manager/mock/src/main.rs
@lwshang lwshang added this pull request to the merge queue Aug 20, 2025
Merged via the queue into master with commit 49d659c Aug 20, 2025
32 checks passed
@lwshang lwshang deleted the lwshang/SDK-2267_unify_ic_cdk branch August 20, 2025 15:08
github-merge-queue Bot pushed a commit that referenced this pull request Sep 18, 2025
Follow-up to #6264 to remove the introduced `#![allow(deprecated)]` in
the code of the `ic-ckbtc-minter` canister:

1. in
[`rs/bitcoin/ckbtc/minter/src/main.rs`](https://github.com/dfinity/ic/blob/3794e29f4a7b0174dd40539262a22ef48bd7d6de/rs/bitcoin/ckbtc/minter/src/main.rs#L1)
2. in
[`rs/bitcoin/ckbtc/minter/src/lib.rs`](https://github.com/dfinity/ic/blob/3794e29f4a7b0174dd40539262a22ef48bd7d6de/rs/bitcoin/ckbtc/minter/src/lib.rs#L1)
3. in
[`rs/bitcoin/ckbtc/minter/tests/tests.rs`](https://github.com/dfinity/ic/blob/3794e29f4a7b0174dd40539262a22ef48bd7d6de/rs/bitcoin/ckbtc/minter/tests/tests.rs#L1)

The changes in the ckBTC minter API are due to changes in the return
type of `get_canister_status`, which is a debug endpoint where
backwards-compatibility is not guaranteed.
github-merge-queue Bot pushed a commit that referenced this pull request Sep 26, 2025
Follow-up to #6264 to remove the introduced `#![allow(deprecated)]` in
the code of the `ic-btc-checker` canister:

1. in
[`rs/bitcoin/checker/src/main.rs`](https://github.com/dfinity/ic/blob/9f9baad64d118b2f357a69a6021891019f0e8350/rs/bitcoin/checker/src/main.rs#L1)
2. in
[`rs/bitcoin/checker/tests/tests.rs`](https://github.com/dfinity/ic/blob/9f9baad64d118b2f357a69a6021891019f0e8350/rs/bitcoin/checker/tests/tests.rs#L1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants