Home

Awesome

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.

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.7.1"}
  ]
end

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

Usage

A full example could be found in kinda_example

More examples

What Kinda does

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

Core concepts

Internals

Source code generation

  1. calling Zig's translation-c to generate Zig source code from wrapper header
  2. parse Zig source into ast and then:
  1. generate NIF source for every C function in the wrapper header
  2. generate kind source for every C type used in C functions

Pre-built mode

Release

cd kinda_example
mix deps.get
mix test --force
mix compile --force