Skip to content

Commit

Permalink
add custom target for didc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed May 16, 2024
1 parent a21d1b8 commit 577da30
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions rust/candid_parser/src/bindings/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use candid::types::{Field, Function, Label, SharedLabel, Type, TypeEnv, TypeInne
use convert_case::{Case, Casing};
use pretty::RcDoc;
use serde::Serialize;
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet};

#[derive(Default, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -572,16 +573,23 @@ pub fn compile(
external: ExternalConfig,
) -> String {
let source = match external.0.get("target").map(|s| s.as_str()) {
Some("canister_call") | None => include_str!("rust_call.hbs"),
Some("agent") => include_str!("rust_agent.hbs"),
Some("stub") => include_str!("rust_stub.hbs"),
Some("canister_call") | None => Cow::Borrowed(include_str!("rust_call.hbs")),
Some("agent") => Cow::Borrowed(include_str!("rust_agent.hbs")),
Some("stub") => Cow::Borrowed(include_str!("rust_stub.hbs")),
Some("custom") => {
let template = external
.0
.get("template")
.expect("template field expected for custom target");
Cow::Owned(std::fs::read_to_string(template).unwrap())
}
_ => unimplemented!(),
};
let (output, unused) = emit_bindgen(tree, env, actor);
for e in unused {
eprintln!("WARNING: path {e} is unused");
}
output_handlebar(output, external, source)
output_handlebar(output, external, &source)
}

pub enum TypePath {
Expand Down

0 comments on commit 577da30

Please sign in to comment.