Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions recipes/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@<version>"
configuration:
package: my-canister
shrink: true
```

The canister `name` in `icp.yaml` must match the `[package] name` in `Cargo.toml`.

> Replace `<version>` 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 | [] |
Expand Down Expand Up @@ -57,8 +57,6 @@ canisters:
- name: hello-rust
recipe:
type: "@dfinity/rust@<version>"
configuration:
package: hello-rust
```

### Advanced Example
Expand All @@ -69,7 +67,6 @@ canisters:
recipe:
type: "@dfinity/rust@<version>"
configuration:
package: dapp-backend
shrink: true
compress: true
metadata:
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions recipes/rust/recipe.hbs
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -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:
Expand Down
Loading