Search code examples
erlangzig

What is the workflow for implementing ERTS NIFs in Zig?


What is the workflow for implementing ERTS NIFs in Zig?

Is there something comparable to Rustler for NIFs authored in Rust?


Solution

  • The Zigler package can be used: https://github.com/ityonemo/zigler, https://hex.pm/packages/zigler

    defmodule ExampleZig do
      use Zig
      ~Z"""
      /// nif: example_fun/2
      fn example_fun(value1: f64, value2: f64) bool {
        return value1 > value2;
      }
      """
    end
    
    test "example nifs" do
      assert ExampleZig.example_fun(0.8, -0.8)
      refute ExampleZig.example_fun(0.1, 0.4)
    end