From 681008a386f7d508256031e64c1da43e371743bd Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Wed, 10 Apr 2024 17:37:26 +0200 Subject: [PATCH] feat: Re-generate bindings if canister id or candid path change (#479) --- src/ic-cdk-bindgen/CHANGELOG.md | 2 ++ src/ic-cdk-bindgen/src/lib.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/ic-cdk-bindgen/CHANGELOG.md b/src/ic-cdk-bindgen/CHANGELOG.md index 31b9ef646..4ea9e69e3 100644 --- a/src/ic-cdk-bindgen/CHANGELOG.md +++ b/src/ic-cdk-bindgen/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +- Re-generate bindings if the canister ids changed (e.g. when switching networks) or when the path to the candid file of a dependency changed. + ## [0.1.3] - 2024-02-27 - Resolve CANISTER_CANDID_PATH and CANISTER_ID from standardized environment variables (uppercase canister names). diff --git a/src/ic-cdk-bindgen/src/lib.rs b/src/ic-cdk-bindgen/src/lib.rs index 4773b4f47..265351ecc 100644 --- a/src/ic-cdk-bindgen/src/lib.rs +++ b/src/ic-cdk-bindgen/src/lib.rs @@ -53,6 +53,8 @@ fn resolve_candid_path_and_canister_id(canister_name: &str) -> (PathBuf, Princip let candid_path_var_name = format!("CANISTER_CANDID_PATH_{}", canister_name_upper); let candid_path_var_name_legacy = format!("CANISTER_CANDID_PATH_{}", canister_name); + println!("cargo:rerun-if-env-changed={candid_path_var_name}"); + println!("cargo:rerun-if-env-changed={candid_path_var_name_legacy}"); let candid_path_str = if let Ok(candid_path_str) = env::var(&candid_path_var_name) { candid_path_str @@ -69,6 +71,8 @@ fn resolve_candid_path_and_canister_id(canister_name: &str) -> (PathBuf, Princip let canister_id_var_name = format!("CANISTER_ID_{}", canister_name_upper); let canister_id_var_name_legacy = format!("CANISTER_ID_{}", canister_name); + println!("cargo:rerun-if-env-changed={canister_id_var_name}"); + println!("cargo:rerun-if-env-changed={canister_id_var_name_legacy}"); let canister_id_str = if let Ok(canister_id_str) = env::var(&canister_id_var_name) { canister_id_str } else if let Ok(canister_id_str) = env::var(&canister_id_var_name_legacy) {