Using Rustler with Elixir 1.12/OTP 24
Read this if you want to get rustler
running on the new, shiny Elixir 1.12/OTP 24.
The problem is that, as I’m writing this, rustler
had a bunch of fixes, which did not yet make it to an official Hex release. So if you try to just add the following to your mix.exs
(as hex tells you to), your project will not build on the new version of Elixir/OTP:
# this does not work with Elixir 1.12
{:rustler, "~> 0.21.1"}
You might think that specifying "~> 0.22.0-rc.0"
as the version might save you, since there’s an unreleased Release Candidate with some changes (the rustler
API got much nicer!). However, you need to get even more cutting edge than that and use the master
branch from the git repository, anything after commit 4786f2.
There are a couple more gotchas: firstly, the rustler
repo contains code for both the Rust and the Elixir packages. The Elixir package is in the rustler_mix
directory so you need to do a sparse
git checkout to tell Elixir where to find the package. In the end, this is the line to add to your deps
:
{:rustler, git: "git://github.com/rusterlium/rustler.git", branch: "master", sparse: "rustler_mix"},
Finally, and this took me way too long to figure out, you also need to update your Cargo.toml
to use the master
branch. When you create a new rustler
project, Cargo.toml
is synced with mix.exs
, but when updating you need to remember both places. Add this:
rustler = {git = "git://github.com/rusterlium/rustler.git", branch="master"}
Note than you don’t need the sparse
checkout here, because the root of the repo is valid Rust package.