|
1 | 1 | use serde::Deserialize; |
2 | 2 | use snafu::{ResultExt, Snafu}; |
3 | 3 |
|
4 | | -/// Known adapter types that can be used to build a canister. |
5 | | -/// These correspond to the values found in `build.adapter.type` in the YAML. |
| 4 | +/// Configuration for a Rust-based canister build adapter. |
6 | 5 | #[derive(Debug, Deserialize)] |
7 | | -#[serde(rename_all = "lowercase")] |
8 | | -pub enum AdapterType { |
9 | | - /// A canister written in Rust. |
10 | | - Rust, |
| 6 | +pub struct RustAdapter { |
| 7 | + /// The name of the Cargo package to build. |
| 8 | + pub package: String, |
| 9 | +} |
11 | 10 |
|
12 | | - /// A canister written in Motoko. |
13 | | - Motoko, |
| 11 | +/// Configuration for a Motoko-based canister build adapter. |
| 12 | +#[derive(Debug, Deserialize)] |
| 13 | +pub struct MotokoAdapter { |
| 14 | + /// Optional path to the main Motoko source file. |
| 15 | + /// If omitted, a default like `main.mo` may be assumed. |
| 16 | + #[serde(default)] |
| 17 | + pub main: Option<String>, |
| 18 | +} |
14 | 19 |
|
15 | | - /// A canister built using custom instructions, |
16 | | - /// such as a shell script or other manual build process. |
17 | | - Custom, |
| 20 | +/// Configuration for a custom canister build adapter. |
| 21 | +#[derive(Debug, Deserialize)] |
| 22 | +pub struct CustomAdapter { |
| 23 | + /// Path to a script or executable used to build the canister. |
| 24 | + pub script: String, |
| 25 | +} |
18 | 26 |
|
19 | | - /// An assets canister used to serve front-end applications |
20 | | - /// or static assets on the Internet Computer. |
21 | | - Assets, |
| 27 | +/// Configuration for an asset canister used to serve static content. |
| 28 | +#[derive(Debug, Deserialize)] |
| 29 | +pub struct AssetsAdapter { |
| 30 | + /// Directory containing the static assets to include in the canister. |
| 31 | + pub source: String, |
22 | 32 | } |
23 | 33 |
|
24 | 34 | /// Identifies the type of adapter used to build the canister, |
25 | | -/// e.g. "motoko", "rust", or "custom". |
| 35 | +/// along with its configuration. |
| 36 | +/// |
| 37 | +/// The adapter type is specified via the `type` field in the YAML file. |
| 38 | +/// For example: |
| 39 | +/// |
| 40 | +/// ```yaml |
| 41 | +/// type: rust |
| 42 | +/// package: my_canister |
| 43 | +/// ``` |
26 | 44 | #[derive(Debug, Deserialize)] |
27 | | -pub struct Adapter { |
28 | | - #[serde(rename = "type")] |
29 | | - pub typ: AdapterType, |
| 45 | +#[serde(tag = "type", rename_all = "lowercase")] |
| 46 | +pub enum Adapter { |
| 47 | + /// A canister written in Rust. |
| 48 | + Rust(RustAdapter), |
| 49 | + |
| 50 | + /// A canister written in Motoko. |
| 51 | + Motoko(MotokoAdapter), |
| 52 | + |
| 53 | + /// A canister built using a custom script or command. |
| 54 | + Custom(CustomAdapter), |
| 55 | + |
| 56 | + /// A static asset canister. |
| 57 | + Assets(AssetsAdapter), |
30 | 58 | } |
31 | 59 |
|
32 | 60 | /// Describes how the canister should be built into WebAssembly, |
@@ -59,7 +87,4 @@ impl CanisterManifest { |
59 | 87 | pub enum CanisterManifestError { |
60 | 88 | #[snafu(display("failed to parse canister manifest: {}", source))] |
61 | 89 | Parse { source: serde_yaml::Error }, |
62 | | - |
63 | | - #[snafu(display("invalid UTF-8 in canister path"))] |
64 | | - InvalidPathUtf8, |
65 | 90 | } |
0 commit comments