Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Rust CLI for mops #237

Open
chenyan-dfinity opened this issue Jul 29, 2024 · 5 comments
Open

A Rust CLI for mops #237

chenyan-dfinity opened this issue Jul 29, 2024 · 5 comments

Comments

@chenyan-dfinity
Copy link

Hi, great work on mops!

I'm writing a Rust implementation of the mops CLI: https://github.com/chenyan2002/mops-cli

The main focus at the moment is mops build. There are some different design choices, which I documented in the README. It's perfectly fine for the node CLI to stay as it is, but I'm happy to discuss if some of the changes can be ported here for better DX.

I consider this Rust CLI as a contribution to the mops ecosystem. It's in no way to replace the node CLI. I'm also planning to add mops in Motoko playground, so there will be another client soon :)

@ZenVoich
Copy link
Owner

Hi, @chenyan-dfinity !

I wonder what the use case for mops build command?
Looks like an alternative to dfx build with canisters listed in mops.toml as in dfx.json

I'm also planning to add mops in Motoko playground, so there will be another client soon :)

Nice 👍 Perhaps this will be helpful - #165 (comment)

@chenyan-dfinity
Copy link
Author

Some motivations for this project:

  • We are trying to reduce the amount of work to build a Motoko canister. With dfx build, you always need to provide dfx.json, and perhaps mops.toml. And you need to get a canister id before you can build. With the new mops build, you can get started with just main.mo. In most cases, mops.toml can be auto-generated, even moc can be downloaded automatically.
  • This also separates out the moc release from dfx release. When there is a new moc release, users don't need to wait for the dfx release.
  • We also want to simplify the dfx build command. With the this mops cli, dfx build will simply call mops build for Motoko canisters, and cargo build for Rust canisters.
  • During this development, we noticed that version resolving in mops is not great. Even our base library is not following semantic versioning. And we need compiler support to allow compiling different versions of the same package in a project.
  • Another minor point is that we want to have a build tool without the node runtime. Requiring npm to build Motoko canisters is another barrier for some developers.

@ZenVoich
Copy link
Owner

  • This also separates out the moc release from dfx release. When there is a new moc release, users don't need to wait for the dfx release.

BTW it is possible to choose moc version with mops https://docs.mops.one/cli/toolchain

  • We also want to simplify the dfx build command. With the this mops cli, dfx build will simply call mops build for Motoko canisters, and cargo build for Rust canisters.

Interesting. Does Rust CDK allow to define the canister ids somewhere else than dfx.json? What if to use dfx.json (with specified_id) to store canister name/ids?

  • During this development, we noticed that version resolving in mops is not great. Even our base library is not following semantic versioning. And we need compiler support to allow compiling different versions of the same package in a project.

Agree. Linking my 1y old issue in motoko repo dfinity/motoko#3971

The latest update to Mops introduced a dependency version pinning feature. So now it is possible to have 2 or more version of the same package in a project.

@chenyan-dfinity
Copy link
Author

BTW it is possible to choose moc version with mops https://docs.mops.one/cli/toolchain

Yeah, I should do that. Not implemented yet. One question is how strict we should follow the toolchain version. A library may be written years ago and pinned to an old release. But it may run just fine with the latest moc.

Interesting. Does Rust CDK allow to define the canister ids somewhere else than dfx.json? What if to use dfx.json (with specified_id) to store canister name/ids?

The [[canister]] section in mops.toml only refers to the imported canisters. I think it's different from what dfx.json specifies. There is also an internal discussion about how we can refactor dfx.json. The main problem is that build and deploy are two very different actions. Sharing the same config for both actions are problematic, e.g., You can build a Wasm module and deploy the Wasm many times. This is not possible to specify in dfx.json at moment (You can hack it by duplicating the canister entries, but it's a hack)

The latest update to Mops introduced a dependency version pinning feature. So now it is possible to have 2 or more version of the same package in a project.

Interesting! I wonder how you implemented use case 2. For package with "base@0.11.0" = "0.11.0", does the author has to use import Int "mo:base@0.11.0/Int" in their code?

@ZenVoich
Copy link
Owner

ZenVoich commented Aug 1, 2024

Interesting! I wonder how you implemented use case 2. For package with "base@0.11.0" = "0.11.0", does the author has to use import Int "mo:base@0.11.0/Int" in their code?

Yes, the package name is base@0.11.0

One question is how strict we should follow the toolchain version. A library may be written years ago and pinned to an old release. But it may run just fine with the latest moc.

[toolchain] section of dependencies is ignored. So it has effect only in project's mops.toml.

There is a [requirements] section for dependencies to define minimum required moc as a hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants