Kinda

Kinda is an Elixir package using Zig to bind a C library to BEAM the Erlang virtual machine. The core idea here is using comptime features in Zig to create a "resource kind" which is higher-kinded type abstracts the NIF resource object, C type and Elixir module.

The general source code generating and building approach here is highly inspired by the TableGen/.inc in LLVM. Kinda will generate NIFs exported by resource kinds and and provide Elixir macros to generate higher level API to call them and create resource. With Kinda, NIFs generated and hand-rolled co-exist and complement each other.

What Kinda does

Core concepts

Cool features in Kinda enabled by Zig

Differences from Zigler

Kinda borrows a lot of good ideas and code from Zigler (Zigler is awesome~) but there are some differences:

Differences from Rustler

Kinda is also inspired by Rustler. Rustler really define what a ergonomic NIF lib should be like.

Differences from TableGen

Usage

defmodule Foo.Native do
use Kinda.Forwarder, root_module: CAPI
end
defmodule Foo.BarKind do
use Kinda.ResourceKind,
forward_module: Foo.Native
end
defmodule Foo.CAPI do
use Kinda.Library, kinds: [Foo.BarKind]
end

Installation

If available in Hex, the package can be installed by adding Kinda to your list of dependencies in mix.exs:

def deps do
[
{:kinda, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/Kinda.