Skip to content

Commit c6c3de8

Browse files
committed
put adapter definitions in adapter enum
1 parent a40140e commit c6c3de8

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

bin/icp-cli/src/commands/build.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub async fn dispatch(_cmd: Cmd) -> Result<(), BuildCommandError> {
1919
return Err(BuildCommandError::ProjectNotFound);
2020
}
2121

22-
let bs = read(mpath).context(ProjectLoadSnafu)?;
23-
let pm = ProjectManifest::from_bytes(&bs).context(ProjectParseSnafu)?;
22+
let bs = read(mpath)?;
23+
let pm = ProjectManifest::from_bytes(&bs)?;
2424

2525
// List canisters in project
2626
let mut cs = Vec::new();
@@ -33,13 +33,14 @@ pub async fn dispatch(_cmd: Cmd) -> Result<(), BuildCommandError> {
3333
});
3434
}
3535

36-
let bs = read(mpath).context(CanisterLoadSnafu)?;
37-
let cm = CanisterManifest::from_bytes(&bs).context(CanisterParseSnafu)?;
36+
let bs = read(mpath)?;
37+
let cm = CanisterManifest::from_bytes(&bs)?;
3838

3939
cs.push(cm);
4040
}
4141

4242
// Build canisters
43+
println!("{cs:?}");
4344

4445
Ok(())
4546
}
@@ -49,18 +50,15 @@ pub enum BuildCommandError {
4950
#[snafu(display("no project (icp.yaml) found in current directory or its parents"))]
5051
ProjectNotFound,
5152

52-
#[snafu(display("failed to load project manifest: {source}"))]
53-
ProjectLoad { source: ReadFileError },
54-
55-
#[snafu(display("failed to parse project manifest: {source}"))]
53+
#[snafu(transparent)]
5654
ProjectParse { source: ProjectManifestError },
5755

5856
#[snafu(display("canister manifest not found: {path}"))]
5957
CanisterNotFound { path: String },
6058

61-
#[snafu(display("failed to load canister manifest: {source}"))]
62-
CanisterLoad { source: ReadFileError },
63-
64-
#[snafu(display("failed to parse canister manifest: {source}"))]
59+
#[snafu(transparent)]
6560
CanisterParse { source: CanisterManifestError },
61+
62+
#[snafu(transparent)]
63+
ReadFile { source: ReadFileError },
6664
}

lib/icp-canister/src/lib.rs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
use serde::Deserialize;
22
use snafu::{ResultExt, Snafu};
33

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.
65
#[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+
}
1110

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+
}
1419

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+
}
1826

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,
2232
}
2333

2434
/// 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+
/// ```
2644
#[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),
3058
}
3159

3260
/// Describes how the canister should be built into WebAssembly,
@@ -59,7 +87,4 @@ impl CanisterManifest {
5987
pub enum CanisterManifestError {
6088
#[snafu(display("failed to parse canister manifest: {}", source))]
6189
Parse { source: serde_yaml::Error },
62-
63-
#[snafu(display("invalid UTF-8 in canister path"))]
64-
InvalidPathUtf8,
6590
}

0 commit comments

Comments
 (0)