Skip to content

feat(cli): mops generate bindings for .did → Motoko - #641

Open
Kamirus wants to merge 4 commits into
mainfrom
feat/generate-bindings
Open

feat(cli): mops generate bindings for .did → Motoko#641
Kamirus wants to merge 4 commits into
mainfrom
feat/generate-bindings

Conversation

@Kamirus

@Kamirus Kamirus commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Motoko projects that call many principals sharing one interface (ICRC ledgers, routers, wallets) need typed actor(id) : Foo.Self without hand-writing service modules or installing didc.

mops generate bindings embeds candid_parser's Motoko bindgen (same codegen as didc bind -t mo) in the existing CLI wasm and regenerates .mo from committed .did files.

Before

# separate didc install required
didc bind -t mo candid/icrc.did > bindings/ICRC.mo

After

[bindings.ICRC]
did = "candid/icrc.did"
# out = "bindings/ICRC.mo"  # optional; default <dir(did)>/<name>.mo
mops generate bindings
# or ad-hoc (mops.toml optional):
mops generate bindings candid/icrc.did -o bindings/ICRC.mo
import ICRC "mo:…/ICRC";
let ledger = actor (id) : ICRC.Self;

What is unchanged

  • mops generate candid (Motoko → .did) is untouched.
  • Single fixed-target inter-canister calls should still use canister: + --actor-env-alias (examples#1452 / #1453).
  • No auto-run on build/check in v1 — explicit only.
  • .did imports are rejected (flatten first). Unlike didc, we do not resolve imports via the filesystem.
  • Snake_case Candid type aliases stay snake_case in Motoko until candid#729 ships; PascalCase DIDs (e.g. ICRC) already look idiomatic.

Context: dfinity/examples#1454.

Kamirus and others added 2 commits July 29, 2026 11:46
Embed candid_parser's Motoko bindgen in the CLI wasm so projects can
regenerate service types for runtime-chosen principals without installing didc.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Cursor AI review

👍 APPROVE — looks safe to merge

Category Assessment Details
Summary Adds mops generate bindings to emit Motoko modules from committed .did files via embedded candid_parser Motoko bindgen, with [bindings.*] config and ad-hoc -o mode.
Code Quality Mirrors generate candid / is-candid-compatible patterns; thin wasm helper; no speculative scope.
Consistency Sibling of generate candid (flags, .mops/ refusal, no-arg = all); docs, changelog, and skills updated together.
Security Rejects writes under .mops/ and rejects .did imports rather than resolving them from the filesystem.
Tests Snapshots for main success paths; targeted assertions for errors, ad-hoc-without-toml, and invalid/import inputs.
Maintainability Clear command/helper/wasm split; config typed in types.ts; intentional v1 limits documented.

Verdict

Decision: APPROVE
Risk: Low
Reason: Additive, well-tested CLI feature that follows existing mops generate candid patterns with matching docs/changelog/skills; no backend, API version, or breaking surface changes.


Generated for commit 1df8e29

Kamirus and others added 2 commits July 29, 2026 11:54
Reject .did imports, allow ad-hoc without mops.toml, tighten path
detection and errors, and cover those paths in tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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

Successfully merging this pull request may close these issues.

1 participant