How to specify a canister`s did file name when using dfx deploy command generated files in .dfx folder?

image

the auto generated did file name is service.did.
which i want to set as backend.did
but i didnt find where to config this .
Of course i cant write a script to rename it .
but i dont know if there is some hidden bug may cause.

here is my dfx.json

{
  "canisters": {
    "assets": {
      "dependencies": [],
      "frontend": {
        "entrypoint": "dist/index.html"
      },
      "source": ["dist/"],
      "type": "assets"
    },
    "backend": {
      "candid": "backend/backend.did",
      "package": "backend",
      "type": "rust"
    }
  },
  "defaults": {
    "build": {
      "args": "",
      "packtool": ""
    }
  },
  "output_env_file": ".env",
  "version": 1

}

do anyone know about it ?

This file is not autogenerated for Rust canisters. It is copied from the one you specify in dfx.json. I recommend you don’t mess with that file

what should i do with dfx.json . any keyword ?

I don’t think you need to do anything. Is there something you’d like to accomplish?

Yes~ we wish to generate name as backend.did inside the .dfx/ic/canisters/backend/ folder.
My frontend friend needs to use it as backend.did file name.

So dfx.json is set to

 "canisters": {
  "backend": {
    "candid": "backend/backend.did",
    "package": "backend",
    "type": "rust"
  }
}

But what was actually generated was service.did inside .dfx/ic/canisters/backend/ folder.
So we want to somehow change it. instead of manually rename in case of any bug.

I think there may be a misunderstanding about what the field canisters.<canister name>.candid does. IIUC you think it means that candid is generated at that location. But for Rust canisters there is no automatic candid generation. The field is where dfx expects you to place the candid file. For internal file transformations dfx then copies that file to .dfx/local/backend/service.did, but this is not something you should or can mess with.

If you want to autogenerate candid files from Rust, please have a look over here: Automatic Candid Generation in Rust: Exploring the ic_cdk v0.10.0 Update

OK. thanks alot ,dear Severin,
I will not manually do anything to .dfx folder content then .

About generating did file :
I use this two things to generate did file:

cargo build --target wasm32-unknown-unknown --release --package "backend" --features "ic-cdk/wasi" 
wasmtime "./target/wasm32-unknown-unknown/release/backend.wasm"  > ./backend/backend.did  --allow-precompiled 

//in end of  lib.rs
use ic_cdk::export_candid;
export_candid!();

It can works for me .

1 Like