From fcf7da22019da469c9f87e408bdd7c9ed4202144 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Wed, 25 Feb 2026 18:20:23 +0100 Subject: [PATCH] feat: add `locked` option to Rust recipe Support passing `--locked` to `cargo build` for reproducible builds. This ensures the exact dependency versions from `Cargo.lock` are used, which is essential for CI environments. --- recipes/rust/README.md | 3 ++- recipes/rust/recipe.hbs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/recipes/rust/README.md b/recipes/rust/README.md index bde11fe..3fa3f77 100644 --- a/recipes/rust/README.md +++ b/recipes/rust/README.md @@ -23,6 +23,7 @@ canisters: | Parameter | Type | Required | Description | Default | |-----------|---------|----------|----------------------------------------------|---------------------------| | package | string | Yes | Name of the Rust package to build | - | +| locked | boolean | No | Use exact dependency versions from `Cargo.lock` (passes `--locked` to Cargo) | false | | candid | string | No | Path to a custom Candid interface file. If not provided, the interface is auto-extracted from the WASM using `candid-extractor` | (auto-extracted) | | metadata | array | No | Array of key-value pairs for custom metadata | [] | | shrink | boolean | No | Remove unused functions and debug info to reduce file size | false | @@ -82,7 +83,7 @@ canisters: When this recipe is executed: -1. Runs `cargo build` with the specified package for the `wasm32-unknown-unknown` target in release mode +1. Runs `cargo build` with the specified package for the `wasm32-unknown-unknown` target in release mode (with `--locked` if enabled) 2. Moves the resulting WASM file from the Cargo target directory to the output location 3. Handles package name conversion (hyphens to underscores for the WASM filename) 4. Injects Cargo version metadata ("cargo:version") diff --git a/recipes/rust/recipe.hbs b/recipes/rust/recipe.hbs index 230c3a4..7508ca6 100644 --- a/recipes/rust/recipe.hbs +++ b/recipes/rust/recipe.hbs @@ -1,5 +1,6 @@ {{! A recipe for building a rust canister }} {{! `package: string` The package to build }} +{{! `locked: boolean` Uses the exact dependency versions from Cargo.lock }} {{! `candid: string` The path to the Candid interface file }} {{! `shrink: boolean` Optimizes the wasm with ic-wasm }} {{! `compress: boolean` determines whether the wasm should be gzipped }} @@ -21,7 +22,7 @@ build: {{! We do this because the target directory might be outside of current directory if we are running in a cargo workspace }} - type: script commands: - - cargo build --package {{ package }} --target wasm32-unknown-unknown --release + - cargo build --package {{ package }} --target wasm32-unknown-unknown --release{{#if locked}} --locked{{/if}} - TARGET_DIR=$(cargo metadata --format-version 1 --no-deps | sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p'); cp "${TARGET_DIR}/wasm32-unknown-unknown/release/{{ replace "-" "_" package }}.wasm" "$ICP_WASM_OUTPUT_PATH" - type: script