Skip to content

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

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

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

Conversation

@Kamirus

@KamirusKamirus 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
importICRC"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.
  • .didimports 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.

Kamirusand 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-actionsBot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Cursor AI review

👍 APPROVE — looks safe to merge

CategoryAssessmentDetails
SummaryAdds 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 QualityMirrors generate candid / is-candid-compatible patterns; thin wasm helper; no speculative scope.
ConsistencySibling of generate candid (flags, .mops/ refusal, no-arg = all); docs, changelog, and skills updated together.
SecurityRejects writes under .mops/ and rejects .did imports rather than resolving them from the filesystem.
TestsSnapshots for main success paths; targeted assertions for errors, ad-hoc-without-toml, and invalid/import inputs.
MaintainabilityClear 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

Kamirusand 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>
@Kamirus

Copy link
Copy Markdown
CollaboratorAuthor

I'd rather avoid this for now if we can implement direct .did file imports in motoko then this PR and the didc binding generator would get obsolete.

@KamirusKamirus closed this Jul 30, 2026
Sign up for freeto 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

@Kamirus