From moonbit-skills
End-to-end workflow for creating maintainable MoonBit FFI bindings for C/C++ libraries, from upstream survey to vendoring, safe API design, tests, and ASan validation.
How this skill is triggered — by the user, by Claude, or both
Slash command
/moonbit-skills:make-moonbit-c-bindingsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use this skill for end-to-end binding projects. Also read `moonbit-c-binding`
Use this skill for end-to-end binding projects. Also read moonbit-c-binding
before implementation for low-level FFI syntax, ownership annotations, and
moonbit.h details.
templates/prepare.py or link to a system library only
when that is explicitly desired.moon check, native tests, ASan, moon info, and vendoring
script idempotency.Prefer this layout, adapting names to the library. Start from bundled templates instead of rewriting scaffolding from scratch:
scripts/prepare.py # optional: pinned upstream download + generated stubs
moon.mod.json # preferred/supported native targets
src/moon.pkg # native-stub list and file target gates
src/wrapper.c # ABI normalization and ownership boundaries
src/ffi.mbt # private extern "c" declarations
src/<domain>.mbt # safe public MoonBit API
src/<domain>_test.mbt # regression tests
src/README.mbt.md # tested documentation examples
README.md -> src/README.mbt.md
Template mapping:
templates/prepare.py -> scripts/prepare.pytemplates/moon.mod.json -> moon.mod.jsontemplates/moon.pkg -> src/moon.pkgtemplates/wrapper.c -> src/wrapper.ctemplates/ffi.mbt -> src/ffi.mbttemplates/api.mbt -> src/<domain>.mbttemplates/README.mbt.md -> src/README.mbt.mdFor ASan validation, copy or invoke the companion runner from
moonbit-c-binding/scripts/run-asan.py as scripts/run-asan.py; do not invent
a new ASan patching script unless that runner cannot fit the project.
destroy/free calls.native-stub with a pinned
revision and a repeatable script.ffi.mbt should keep externs private and use #borrow / #owned explicitly.Moonbit_array_length in C.Run, at minimum:
moon fmt
moon check --target all --warn-list +73
moon test --target native
python3 scripts/run-asan.py
moon info --target native
python3 scripts/prepare.py
git status --short
For native-only packages, set "preferred-target": "native" and
the smallest true "supported-targets" value in moon.mod.json.
Lifecycle And Ownership; Vendoring And Package Setup; Testing And Documentation.
npx claudepluginhub moonbitlang/skills --plugin moonbit-skillsGuides writing MoonBit FFI bindings to C libraries: extern declarations, C stubs with moonbit.h, ownership annotations, callback trampolines, external objects with finalizers, string conversion, and AddressSanitizer validation.
Guides Zig and C interoperability: importing C headers with @cImport, exporting Zig functions to C, mapping types, using translate-c, and linking C libraries.
Integrates cpp.js into existing JavaScript/TypeScript/React Native projects by detecting framework/bundler (Next.js, Vite, Webpack, etc.) and applying matching playbook for plugins, config, and init.