Skip to content

Commit 907b7d9

Browse files
committed
Merge branch 'main' into next
2 parents 69d98b0 + 8f57d6d commit 907b7d9

File tree

16 files changed

+112
-20
lines changed

16 files changed

+112
-20
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
runs-on: ${{ matrix.os }}
4444
strategy:
4545
matrix:
46-
os: [ubuntu-latest, macos-12]
46+
os: [ubuntu-latest, macos-13-large]
4747
steps:
4848
- name: Checkout repository
4949
uses: actions/checkout@v4

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ opt-level = 'z'
3131

3232
[workspace.dependencies]
3333
ic0 = { path = "ic0", version = "0.24.0-alpha.1" }
34-
ic-cdk = { path = "ic-cdk", version = "0.17.0-alpha.1" }
34+
ic-cdk = { path = "ic-cdk", version = "0.18.0-alpha.1" }
3535
ic-cdk-management-canister = { path = "ic-cdk-management-canister", version = "0.1.0-alpha.1" }
36-
ic-cdk-timers = { path = "ic-cdk-timers", version = "0.11.0-alpha.1" }
36+
ic-cdk-timers = { path = "ic-cdk-timers", version = "0.12.0-alpha.1" }
3737

3838
candid = "0.10.4"
3939
candid_parser = "0.1.4"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2020 DFINITY LLC.
189+
Copyright 2020 DFINITY Stiftung.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

ic-cdk-macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ic-cdk-macros"
3-
version = "0.17.0-alpha.1" # sync with ic-cdk
3+
version = "0.18.0-alpha.1" # sync with ic-cdk
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

ic-cdk-macros/src/export.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ enum MethodType {
3333
Query,
3434
Heartbeat,
3535
InspectMessage,
36+
OnLowWasmMemory,
3637
}
3738

3839
impl MethodType {
3940
pub fn is_lifecycle(&self) -> bool {
40-
matches!(
41-
self,
41+
match self {
4242
MethodType::Init
43-
| MethodType::PreUpgrade
44-
| MethodType::PostUpgrade
45-
| MethodType::Heartbeat
46-
| MethodType::InspectMessage
47-
)
43+
| MethodType::PreUpgrade
44+
| MethodType::PostUpgrade
45+
| MethodType::Heartbeat
46+
| MethodType::InspectMessage
47+
| MethodType::OnLowWasmMemory => true,
48+
MethodType::Update | MethodType::Query => false,
49+
}
4850
}
4951
}
5052

@@ -58,6 +60,7 @@ impl std::fmt::Display for MethodType {
5860
MethodType::Update => f.write_str("update"),
5961
MethodType::Heartbeat => f.write_str("heartbeat"),
6062
MethodType::InspectMessage => f.write_str("inspect_message"),
63+
MethodType::OnLowWasmMemory => f.write_str("on_low_wasm_memory"),
6164
}
6265
}
6366
}
@@ -312,6 +315,13 @@ pub(crate) fn ic_inspect_message(
312315
dfn_macro(MethodType::InspectMessage, attr, item)
313316
}
314317

318+
pub(crate) fn ic_on_low_wasm_memory(
319+
attr: TokenStream,
320+
item: TokenStream,
321+
) -> Result<TokenStream, Error> {
322+
dfn_macro(MethodType::OnLowWasmMemory, attr, item)
323+
}
324+
315325
#[cfg(test)]
316326
mod test {
317327
use super::*;

ic-cdk-macros/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,13 @@ pub fn heartbeat(attr: TokenStream, item: TokenStream) -> TokenStream {
9191
pub fn inspect_message(attr: TokenStream, item: TokenStream) -> TokenStream {
9292
handle_debug_and_errors(export::ic_inspect_message, "ic_inspect_message", attr, item)
9393
}
94+
95+
#[proc_macro_attribute]
96+
pub fn on_low_wasm_memory(attr: TokenStream, item: TokenStream) -> TokenStream {
97+
handle_debug_and_errors(
98+
export::ic_on_low_wasm_memory,
99+
"ic_on_low_wasm_memory",
100+
attr,
101+
item,
102+
)
103+
}

ic-cdk-management-canister/src/core/types.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ pub enum CanisterInstallMode {
190190
Reinstall,
191191
/// Upgrade an existing canister.
192192
#[serde(rename = "upgrade")]
193-
Upgrade(Option<SkipPreUpgrade>),
193+
Upgrade(Option<UpgradeFlags>),
194194
}
195195

196-
/// If set to true, the pre_upgrade step will be skipped during the canister upgrade
196+
/// Flags for canister installation with [`CanisterInstallMode::Upgrade`].
197197
#[derive(
198198
CandidType,
199199
Serialize,
@@ -208,7 +208,37 @@ pub enum CanisterInstallMode {
208208
Copy,
209209
Default,
210210
)]
211-
pub struct SkipPreUpgrade(pub Option<bool>);
211+
pub struct UpgradeFlags {
212+
/// If set to `true`, the `pre_upgrade` step will be skipped during the canister upgrade
213+
pub skip_pre_upgrade: Option<bool>,
214+
/// If set to `Keep`, the WASM heap memory will be preserved instead of cleared.
215+
pub wasm_memory_persistence: Option<WasmPersistenceMode>,
216+
}
217+
218+
/// WASM memory persistence setting for [`UpgradeFlags`].
219+
#[derive(
220+
CandidType,
221+
Serialize,
222+
Deserialize,
223+
Debug,
224+
PartialEq,
225+
Eq,
226+
PartialOrd,
227+
Ord,
228+
Hash,
229+
Clone,
230+
Copy,
231+
Default,
232+
)]
233+
pub enum WasmPersistenceMode {
234+
/// Preserve heap memory (only officially supported by Motoko)
235+
#[serde(rename = "keep")]
236+
Keep,
237+
/// Clear heap memory
238+
#[serde(rename = "replace")]
239+
#[default]
240+
Replace,
241+
}
212242

213243
/// WASM module.
214244
pub type WasmModule = Vec<u8>;

ic-cdk-timers/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [unreleased]
88

9+
## [0.11.0] - 2024-11-04
10+
11+
### Changed
12+
13+
- Upgrade `ic-cdk` to v0.17.
14+
915
## [0.10.0] - 2024-08-27
1016

1117
### Changed

ic-cdk-timers/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ic-cdk-timers"
3-
version = "0.11.0-alpha.1"
3+
version = "0.12.0-alpha.1"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

ic-cdk/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- Fix update/query macro could not handle function arguments with the same name as the function itself. (#525)
1212

13+
## [0.17.0] - 2024-11-04
14+
1315
### Changed
1416

1517
- Add `AllowedViewers` variant to `LogVisibility` enum. (#512)
1618

1719
### Added
1820

21+
- Attribute `#[on_low_wasm_memory]` for low-memory hook. (#528)
1922
- Support Threshold Schnorr signing management canister API. (#518)
2023

2124
## [0.16.0] - 2024-08-27

ic-cdk/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ic-cdk"
3-
version = "0.17.0-alpha.1" # sync with ic-cdk-macros
3+
version = "0.18.0-alpha.1" # sync with ic-cdk-macros
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -27,7 +27,7 @@ ic0.workspace = true
2727
# Dependents won't accidentaly upgrading ic-cdk-macros only but not ic-cdk.
2828
# ic-cdk-macros is a hidden dependency, re-exported by ic-cdk.
2929
# It should not be included by users direcly.
30-
ic-cdk-macros = { path = "../ic-cdk-macros", version = "=0.17.0-alpha.1" }
30+
ic-cdk-macros = { path = "../ic-cdk-macros", version = "=0.18.0-alpha.1" }
3131
serde.workspace = true
3232
serde_bytes.workspace = true
3333
slotmap = { workspace = true, optional = true }

ic-cdk/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ These macros are directly related to the [Internet Computer Specification](https
5858
* [`post_upgrade`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.post_upgrade.html)
5959
* [`inspect_message`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.inspect_message.html)
6060
* [`heartbeat`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.heartbeat.html)
61+
* [`on_low_wasm_memory`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.on_low_wasm_memory.html)
6162
* [`update`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.update.html)
6263
* [`query`](https://docs.rs/ic-cdk/latest/ic_cdk/attr.query.html)
6364

ic-cdk/src/macros.rs

+21
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,24 @@ pub use ic_cdk_macros::heartbeat;
313313
/// }
314314
/// ```
315315
pub use ic_cdk_macros::inspect_message;
316+
317+
/// Register the `canister_on_low_wasm_memory` entry point of a canister.
318+
///
319+
/// This attribute macro will export the function `canister_on_low_wasm_memory`
320+
/// in the canister module.
321+
///
322+
/// The function under this attribute must have no return value.
323+
///
324+
/// Each canister can only have one `canister_on_low_wasm_memory` entry point.
325+
///
326+
/// # Example
327+
///
328+
/// ```rust
329+
/// # use ic_cdk::on_low_wasm_memory;
330+
/// #[on_low_wasm_memory]
331+
/// fn low_memory_handler() {
332+
/// // ...
333+
/// # unimplemented!()
334+
/// }
335+
/// ```
336+
pub use ic_cdk_macros::on_low_wasm_memory;

ic-cdk/tests/pass/blank_methods.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use ic_cdk::{heartbeat, init, inspect_message, post_upgrade, pre_upgrade, query, update};
1+
use ic_cdk::{
2+
heartbeat, init, inspect_message, on_low_wasm_memory, post_upgrade, pre_upgrade, query, update,
3+
};
24

35
#[init]
46
fn init() {}
@@ -30,4 +32,7 @@ fn heartbeat() {}
3032
#[inspect_message]
3133
fn inspect_message() {}
3234

35+
#[on_low_wasm_memory]
36+
fn on_low_wasm_memory() {}
37+
3338
fn main() {}

library/ic-ledger-types/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [unreleased]
88

9+
## [0.14.0] - 2024-11-08
10+
11+
### Changed
12+
13+
- Upgrade `ic-cdk` to v0.17.
14+
915
### Added
1016
- as_bytes method to AccountIdentifier in ic-ledger-types
1117

library/ic-ledger-types/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ic-ledger-types"
3-
version = "0.14.0-alpha.1"
3+
version = "0.15.0-alpha.1"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

0 commit comments

Comments
 (0)