Skip to content

Commit

Permalink
Merge pull request #1355 from demergent-labs/fix_candid_canister_method
Browse files Browse the repository at this point in the history
expose the candid again
  • Loading branch information
lastmjs authored Oct 6, 2023
2 parents 053f9f9 + dcf75b2 commit c19b53d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ async function azle() {
canisterJavaScript
);

writeFileSync(candidPath, candid);
writeFileSync(candidPath, candid); // This is for the dfx.json candid property
writeFileSync(`${canisterPath}/canister/src/candid.did`, candid); // This is for the Rust canister to have access to the candid file

const compilerInfo: CompilerInfo = {
// TODO The spread is because canisterMethods is a function with properties
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/rust/canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ mod ic;
#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
const MAIN_JS: &[u8] = include_bytes!("main.js");

#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
const CANDID: &[u8] = include_bytes!("candid.did");

#[allow(unused)]
type Memory = VirtualMemory<DefaultMemoryImpl>;
#[allow(unused)]
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/rust/canister_methods/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
#(#query_methods)*

#(#update_methods)*

#[ic_cdk_macros::query]
fn __get_candid_interface_tmp_hack() -> String {
std::str::from_utf8(CANDID)
.expect("candid.did could not be read")
.to_string()
}
}
.into()
}
Expand Down

0 comments on commit c19b53d

Please sign in to comment.