Nim C Bindings logo

Nim C Bindings

Community
planetis-m
nim-c-bindings

Bind C libraries to Nim and make them build reliably across Linux, macOS, and Windows, including headers, types, linking, shared-library loading, and CI/release workflows. Use when wrapping a C dependency, fixing Nim FFI build issues, or setting up cross-platform GitHub Actions for a Nim native library project.

Overview

Publisherplanetis-m
Repositoryskills
Skill namenim-c-bindings
Stars
66
Forks
7
Bundled files
3
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by planetis-m on GitHub. Read the source before you install it.

Installation

Install the Nim C Bindings AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/planetis-m/skills/tree/master/nim-c-bindings
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/planetis-m/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/nim-c-bindings .claude/skills/nim-c-bindings
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Nim C Bindings in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Nim C Bindings on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Nim C Bindings is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Nim C Bindings & CI

Rules

Binding Fundamentals

  • Use importc with cdecl for C APIs unless the library explicitly requires a different calling convention (e.g., stdcall).
  • Represent opaque C handles as type Name = ptr object types. Use incompleteStruct for partial/opaque structs to avoid size/layout mismatches.
  • Use {.bycopy.} on structs that Nim must pass by value to C.
  • Declare the C header in the binding when the compiler needs the C definitions for compilation, for example header: "foo.h".
  • Use {.push callconv: cdecl, importc.} blocks when many declarations share the same convention.
  • Match C storage with Nim's C-compatible types such as cint, cuint, clong, culong, clonglong, csize_t, cfloat, cdouble, cstring, and pointer types.
  • Preserve the complete field order for concrete structs passed or returned by value.
  • When the requested deliverable is a raw binding, import C symbols directly. Put ergonomic aliases and conversions in a separate wrapper layer.

Linking

  • System libraries: link with -l<name> only. Do not hardcode -L paths — the OS toolchain already knows where system libs live.
  • Local/third-party libraries: add both -L<dir> and -l<name> (or .lib/.dll.lib paths on Windows MSVC).
  • Use repository-relative paths for vendored dependencies, for example third_party/libfoo, to keep builds hermetic.
  • Distinguish linker-resolved imports from Nim runtime dynlib imports. header supplies declarations for generated C; a runtime-only dynlib proc should not also use header.

Runtime Library Resolution

  • Vendored/local shared libs: colocate the .so/.dylib/.dll next to the executable. Do not rely on environment variables for discovery.
  • System-installed libs: do not copy DLLs/shared libs next to the executable. Rely on the platform's normal system loader configuration. Use environment variables only as temporary overrides.
  • On Linux, add rpath $ORIGIN only when loading colocated shared libs. From the shell, pass --passL:"-Wl,-rpath,\$ORIGIN". In Nim source, use {.passL: "-Wl,-rpath,\\$ORIGIN".}.
  • Do not use build-tree-only rpaths or absolute paths to non-system shared libraries.

Platform Rules

PlatformToolchainDepsLink flagsRuntime
LinuxSystem GCC/Clangapt-l<name> or -L<dir> -l<name>Colocate local .so; rpath $ORIGIN if needed
macOSApple ClangHomebrewstaticExec("brew --prefix") for -I/-LColocate local .dylib
WindowsMSVC (--cc:vcc)vcpkg only.lib/.dll.lib full pathsColocate .dll next to .exe
  • On macOS, resolve include/link paths via staticExec("brew --prefix <formula>").
  • On Windows, use MSVC via --cc:vcc. Use vcpkg only — avoid Chocolatey and MSYS2. Never mix toolchains.
  • On Windows, do not rely on implicit -l<name> for MSVC. Use explicit .lib or .dll.lib paths.
  • On Windows CI, export VCPKG_ROOT to the installed triplet root and prepend its bin to PATH.

CI & Release

  • CI is the authoritative spec for supported platforms, toolchains, and flags. Local workflows must be compatible with CI.
  • Keep test builds simple: compile, then run, with minimal environment mutation.
  • Align the local toolchain with CI (e.g., MSVC + vcpkg x64-windows-release with --cc:vcc).
  • Use the reference workflows as starting points — references/ci.yml for validation, references/release.yml for tagged releases.

Verification

  • Compile against the real header and call the real C implementation.
  • Exercise concrete structs passed and returned by value. Compare Nim layout with C sizeof and offsetof probes when layout is in doubt.
  • Test bundled shared libraries after copying the executable and library into a clean directory.
  • For dynlib, verify runtime loading without also linking that library.

Workflow

  1. Identify the C API. Determine calling convention, opaque vs value types, and ownership.
  2. Write bindings. Use importc, correct calling convention, incompleteStruct for opaque types, bycopy for value types. Add header pragma.
  3. Set up linking. System libs: -l only. Local libs: -L + -l with repo-relative paths. Windows: explicit .lib paths.
  4. Handle runtime. Colocate local shared libs. For system-installed libs, rely on the normal loader search path. Add rpath $ORIGIN on Linux only for colocated local libs.
  5. Verify the ABI. Run a real C round trip for the types and calls used by the binding.
  6. Add CI. Copy references/ci.yml, adapt placeholders (<package>, <src/main.nim>, dependency lists).
  7. Add release. Copy references/release.yml, adapt placeholders, configure draft releases.
  8. Test locally, then push. Verify the build works locally with the same flags CI uses.

Common Mistakes

MistakeWhy it's wrong
Hardcoding -L paths for system librariesOS toolchain already knows where they are; breaks portability
Mixing MSVC + MSYS2/MinGW on WindowsIncompatible ABIs, linker errors, runtime crashes
Using implicit -l<name> with MSVCMSVC doesn't resolve libs the same way GCC does; use explicit .lib paths
Relying on env vars for vendored shared libsFragile across machines; colocate instead
Build-tree-only rpathsBreaks when the binary moves; use $ORIGIN for colocated libs
Guessing Windows dependency pathsNon-deterministic; use vcpkg with known install roots
Compiling C sources into the executable when the task requires an existing shared libraryBypasses shared-library link and relocation behavior
Adding Nim-bodied wrappers to a requested raw binding surfaceHides whether the C API was imported directly and changes the requested layer

References

  • references/raw_binding.md — Mapping an opaque handle and by-value C struct.
  • references/ci.yml — Building a C-dependent project on Linux, macOS, and Windows with Nim, Atlas, and vcpkg.
  • references/release.yml — Publishing tagged cross-platform archives in a draft release.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Nim C Bindings AI skill do?

Bind C libraries to Nim and make them build reliably across Linux, macOS, and Windows, including headers, types, linking, shared-library loading, and CI/release workflows. Use when wrapping a C dependency, fixing Nim FFI build issues, or setting up cross-platform GitHub Actions for a Nim native library project.

Why use Nim C Bindings on TypingMind?

Because you install it once and use it with any model. Nim C Bindings is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Nim C Bindings in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/planetis-m/skills/tree/master/nim-c-bindings. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Nim C Bindings?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Nim C Bindings?

As many as you like. As long as a model supports skills, you can use Nim C Bindings with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Nim C Bindings AI skill free?

It is published on GitHub by planetis-m. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇