From dcf75b2a3d24007eec3cead127f13bc93001d1ce Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Thu, 5 Oct 2023 21:36:11 -0700 Subject: [PATCH] expose the candid again --- src/compiler/index.ts | 3 ++- src/compiler/rust/canister/src/lib.rs | 3 +++ src/compiler/rust/canister_methods/src/lib.rs | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 8d79083015..c499a47f25 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -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 diff --git a/src/compiler/rust/canister/src/lib.rs b/src/compiler/rust/canister/src/lib.rs index 6d8f6fdb92..5fa687debd 100644 --- a/src/compiler/rust/canister/src/lib.rs +++ b/src/compiler/rust/canister/src/lib.rs @@ -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; #[allow(unused)] diff --git a/src/compiler/rust/canister_methods/src/lib.rs b/src/compiler/rust/canister_methods/src/lib.rs index 8418d016df..df6d22b60c 100644 --- a/src/compiler/rust/canister_methods/src/lib.rs +++ b/src/compiler/rust/canister_methods/src/lib.rs @@ -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() }