diff --git a/recipes/rust/README.md b/recipes/rust/README.md index 3fa3f77..317b1e4 100644 --- a/recipes/rust/README.md +++ b/recipes/rust/README.md @@ -8,21 +8,21 @@ Example of how to reference this recipe in an `icp.yaml` file: ```yaml canisters: - - name: backend + - name: my-canister recipe: type: "@dfinity/rust@" configuration: - package: my-canister shrink: true ``` +The canister `name` in `icp.yaml` must match the `[package] name` in `Cargo.toml`. + > Replace `` with a release version (e.g. `v3.0.0`). See [available versions](https://github.com/dfinity/icp-cli-recipes/releases?q=rust&expanded=true). ## Configuration Parameters | 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 | [] | @@ -57,8 +57,6 @@ canisters: - name: hello-rust recipe: type: "@dfinity/rust@" - configuration: - package: hello-rust ``` ### Advanced Example @@ -69,7 +67,6 @@ canisters: recipe: type: "@dfinity/rust@" configuration: - package: dapp-backend shrink: true compress: true metadata: @@ -135,7 +132,7 @@ serde = { version = "1.0", features = ["derive"] } ### Issue 2 **Problem**: Package not found during build -**Solution**: Verify the package name matches exactly with the name in your `Cargo.toml` file +**Solution**: Verify the canister `name` in `icp.yaml` matches the `[package] name` in `Cargo.toml` exactly ### Issue 3 diff --git a/recipes/rust/recipe.hbs b/recipes/rust/recipe.hbs index 7508ca6..75e9ecf 100644 --- a/recipes/rust/recipe.hbs +++ b/recipes/rust/recipe.hbs @@ -1,5 +1,4 @@ {{! 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 }} @@ -22,8 +21,8 @@ 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{{#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" + - cargo build --package {{ _.canister.name }} --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 "-" "_" _.canister.name }}.wasm" "$ICP_WASM_OUTPUT_PATH" - type: script commands: