/elixir-rust-nif-starter

Basic NIF implementation with Elixir and Rust

Primary LanguageElixir

Elixir Rust NIF Starter

Example application for implementing Rust NIFs in Elixir using the Elixir Rustler library with tweaks for Apple Silicon.

Installation

These are installation instructions for Mac OS, including some tweaks to get this to work on Apple Silicon using Homebrew.

Install Elixir

brew install rustup

Install Rust

brew install rustup

rustup-init

Create a new Elixir project

mix new nif_starter

add {:rustler, "~> 0.22.2"}

mix deps.get

Create a new Rust package

mix rustler new

Module Name > NifStarter

Library name > nif_starter

Update native/nif_starter/.cargo/config

If you are using Apple Silicon you will need to update the .cargo/config file to build the Rust package

[target.'cfg(target_os = "macos")']
rustflags = [
    "-C", "link-arg=-undefined",
    "-C", "link-arg=dynamic_lookup",
]

Install crates and build Rust package

cargo build

Open IEx and call the NIF

iex -S mix

NifStarter.add(1, 2)

Resources