sdk icon indicating copy to clipboard operation
sdk copied to clipboard

chore: update Azle templates to `0.31.0`

Open lastmjs opened this issue 1 year ago • 6 comments

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

The dfx new command for Azle has been out-of-date for a while now. This PR updates Azle's templates to the latest version and simplifies the templates with new changes possible because of the latest version.

How Has This Been Tested?

I built the sdk locally and manually used the dfx new command to create a new example project. I then deployed the project and checked that it worked in the Candid UI.

Checklist:

  • [x] The title of this PR complies with Conventional Commits
  • [x] I have edited the CHANGELOG accordingly
  • [x] I have made corresponding changes to the documentation

lastmjs avatar Dec 14 '24 18:12 lastmjs

Dear @lastmjs,

In order to potentially merge your code in this open-source repository and therefore proceed with your contribution, we need to have your approval on DFINITY's CLA.

If you decide to agree with it, please visit this issue and read the instructions there. Once you have signed it, re-trigger the workflow on this PR to see if your code can be merged.

— The DFINITY Foundation

cla-idx-bot[bot] avatar Dec 14 '24 18:12 cla-idx-bot[bot]

It might be enough for this specific case to move the npm install post_create setup in templates.js to the dfx_js_base template.

I assume you meant templates.rs. I have attempted to do what you've described here, as well as updating Azle to its latest 0.25.0.

lastmjs avatar Jan 10 '25 16:01 lastmjs

The following fails, because with this setup the backend canister (type=azle) is relying on a frontend canister to run npm install to install the azle extension.

It might be enough for this specific case to move the npm install post_create setup in templates.js to the dfx_js_base template.

Even then, if npm install fails (and notice that dfx new is specifically set up to treat this as a warning), all dfx commands run in the project will report an error like the one below until npm install is run and succeeds.

$ dfx cache delete
$ dfx new azt --type azle --frontend none
Fetching manifest https://sdk.dfinity.org/manifest.json
  Installed dfx 0.24.3-azletest to cache.
Creating new project "azt"...
Initializing git repository...
===============================================================================
        Welcome to the internet computer developer community!

To learn more before you start coding, check out the developer docs and samples:

- Documentation: https://internetcomputer.org/docs/current/developer-docs
- Samples: https://internetcomputer.org/samples
===============================================================================
$ cd azt
$ dfx deploy
Error: Failed to create AgentEnvironment.
Caused by: canister 'azt_backend' has unknown type 'azle' and there is no installed extension by that name which could define it

I've updated the Azle template to 0.31.0. I am requesting another review from @ericswanson-dfinity and @krpeacock.

I'm struggling to reproduce this exact error condition locally. Are you sure that you have set all of your dfx commands to the same exact dfx version? I have attempted to do this with export PATH="/home/lastmjs/development/sdk/target/debug:$PATH" after building the dfx binary. Everything works after I set that PATH in each terminal that I use. Keep in mind that Azle will use a raw dfx command, without any path in front of it. That was throwing me off a bit.

I've checked in the .local/dfinity/versions directory that indeed the azle extension is created when running the command dfx new --type azle --frontend none test_dfx_azle_new.

Can you confirm that I am correct?

lastmjs avatar May 30 '25 22:05 lastmjs

@lastmjs I'll double check but I would expect that you would see this error if you're starting from scratch and you don't have the azle extension installed already (ie you've never run npm install in a project that included azle, so azle never had a chance to post install the dfx extension).

raymondk avatar Jun 17 '25 18:06 raymondk

@raymondk Yes my testing in response to the problem reported is for that exact situation, at least with this command: dfx new --type azle --frontend none test_dfx_azle_new. dfx will run npm install automatically and appropriately.

I do not see this problem presenting locally, and I've tried to invoke it. My explanation above explains some caveats that may lead you to believe there is an issue when there is not.

When you say starting from scratch, you're talking about using dfx new right? Otherwise using npx azle new or creating a repo from scratch, you would run npm install on your own. But I believe that's outside the scope of this PR, which is to get dfx new to work with Azle.

lastmjs avatar Jul 02 '25 13:07 lastmjs

It would be great to get this merged ASAP. It would also be great if DFINITY could somehow take over maintenance of dfx new with Azle. I would really like to avoid having to come here to make a PR every time Azle's version changes. Demergent Labs doesn't even recommend people use dfx new to create Azle projects, we prefer npx azle new. So if you would like this functionality to work properly, I feel like it could be appropriate for you to take it on.

That being said, if there is some way for the Azle extension itself to define these templates, that would be even more ideal, since we own the extension and can keep it up to date easily.

lastmjs avatar Jul 02 '25 13:07 lastmjs