rm-rf-etc

rm-rf-etc

Can't build with rustler

I’m having trouble building with rustler. I reviewed the open issues on the rustler repo and it looks like it hasn’t been updated to support newer OTP versions 22 and 23. I have tried compiling the following two projects:
https://github.com/discord/sorted_set_nif
https://github.com/rusterlium/NifIo

In the first project, I found an open issue where someone indicates that it compiles successfully with OTP 21.1.1, so that’s what I’ve downgraded to. I’m using kerl to manage my erlang version, and my elixir version is on 1.11.1. Here is the error I’m getting when trying to build sorted_set_nif:

RUST_BACKTRACE=full mix compile
Compiling NIF crate :sorted_set (native/sorted_set_nif)...
warning: variable does not need to be mutable
   --> src/supported_term.rs:130:25
    |
130 |                     let mut idx = 0;
    |                         ----^^^
    |                         |
    |                         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
   --> src/supported_term.rs:150:25
    |
150 |                     let mut idx = 0;
    |                         ----^^^
    |                         |
    |                         help: remove this `mut`

warning: 2 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Compiling 3 files (.ex)
thread '<unnamed>' panicked at 'attempted to leave type `erlang_nif_sys::ErlNifResourceFlags` uninitialized, which is invalid', /Users/rob/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:659:9
stack backtrace:
   0:         0x5740b674 - std::backtrace_rs::backtrace::libunwind::trace::h3440e89bdeed3ddf
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:         0x5740b674 - std::backtrace_rs::backtrace::trace_unsynchronized::hfa68bcc7baf06ad7
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:         0x5740b674 - std::sys_common::backtrace::_print_fmt::h483e161a2ffbfba4
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:67:5
   3:         0x5740b674 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h34f76b2ca42fab41
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:46:22
   4:         0x5741e69d - core::fmt::write::h8f13d857463c51c1
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/fmt/mod.rs:1078:17
   5:         0x574095c6 - std::io::Write::write_fmt::h0a6214ccb1a8468b
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/io/mod.rs:1517:15
   6:         0x5740d029 - std::sys_common::backtrace::_print::h7f3525175df798e8
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:49:5
   7:         0x5740d029 - std::sys_common::backtrace::print::hf68eec1a3c535c32
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:36:9
   8:         0x5740d029 - std::panicking::default_hook::{{closure}}::hb14d90e928578cc7
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:208:50
   9:         0x5740cbb0 - std::panicking::default_hook::h460969f1dc8f738d
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:225:9
  10:         0x5740d6ab - std::panicking::rust_panic_with_hook::h28bf9d6c3916221e
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:591:17
  11:         0x5740d1a9 - std::panicking::begin_panic_handler::{{closure}}::h99569328be4adae9
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:495:13
  12:         0x5740bb18 - std::sys_common::backtrace::__rust_end_short_backtrace::h9a7e5cc6475b496b
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:141:18
  13:         0x5740d13a - rust_begin_unwind
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:493:5
  14:         0x574243df - core::panicking::panic_fmt::h65997884a2662b8c
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:92:14
  15:         0x57424337 - core::panicking::panic::h2ca2e9d2b0a1f2bf
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:50:5
  16:         0x573e72f5 - core::mem::uninitialized::hd3f8dde2b112491b
                               at /Users/rob/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:659:9
  17:         0x573e72f5 - rustler::wrapper::resource::open_resource_type::had589574171911d3
                               at /Users/rob/.cargo/registry/src/github.com-1ecc6299db9ec823/rustler-0.18.0/src/wrapper/resource.rs:28:43
  18:         0x573d9fc6 - rustler::resource::open_struct_resource_type::hcfbbf1a0c976f53a
  19:         0x573c6722 - sorted_set_nif::load::hf2bb44c69ec6337e
  20:         0x573e476d - rustler::codegen_runtime::handle_nif_init_call::h2dd8ea321b7ab28a
                               at /Users/rob/.cargo/registry/src/github.com-1ecc6299db9ec823/rustler-0.18.0/src/codegen_runtime.rs:66:12
  21:         0x573cb0c3 - sorted_set_nif::nif_init::nif_load::h9fa949fb4c4a8871
  22:         0x12d83f04 - load_nif_2
                               at /Users/rob/.kerl/builds/21.1.1/otp_src_21.1.1/erts/emulator/beam/erl_nif.c:4205:16
  23:         0x12e1f45d - process_main
                               at /Users/rob/.kerl/builds/21.1.1/otp_src_21.1.1/erts/emulator/x86_64-apple-darwin20.1.0/opt/smp/beam_cold.h:59:24
  24:         0x12e2ea04 - sched_thread_func
                               at /Users/rob/.kerl/builds/21.1.1/otp_src_21.1.1/erts/emulator/beam/erl_process.c:8332:5
  25:         0x12e1879a - thr_wrapper
                               at /Users/rob/.kerl/builds/21.1.1/otp_src_21.1.1/erts/lib_src/pthread/ethread.c:118:25
  26:     0x7fff2038e950 - __pthread_start
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

Regarding the rusterlium example project, it seems to build and run successfully, but logs 17 warnings, and these give me the impression that the example code is not up to date with rustler. One such warning:

warning: use of deprecated macro `::rustler::rustler_export_nifs`: Please use `rustler::init!` instead.
  --> src/lib.rs:51:1
   |
51 | / rustler_export_nifs!(
52 | |     "Elixir.NifIo.Native",
53 | |     [("open", 1, open_file),
54 | |      ("read_until", 2, read_until)],
55 | |     Some(on_load)
56 | | );
   | |__^
   |
   = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

I’m primarily hoping someone will be able to help me understand what this error means and how to resolve it:

attempted to leave type `erlang_nif_sys::ErlNifResourceFlags` uninitialized, which is invalid

Marked As Solved

rm-rf-etc

rm-rf-etc

Okay, build now works. My issue was that I missed a step, I didn’t add :compilers and :rustler_crates to my mix.exs file. I also suspect the name I provided for module and library may have not matched with the config and use directive, in my previous attempts. I’ve pushed a tutorial here to help anyone else who maybe runs into the same issue: GitHub - rm-rf-etc/rustler_tutorial: Shows how to get your new Elixir Rust NIF to build · GitHub

However, I haven’t yet tried building the sorted_set_nif, so I still don’t know why this one doesn’t build, but for my concerns, I don’t think I actually need this to build. I was going to use it for reference, but so long as I can get a blank NIF project to build, that should be fine.

Also Liked

dimitarvp

dimitarvp

Take a look at the partially updated README.md in the GitHub repo after switching to the rustler-0.22.0-rc.0 tag.

I can help you with Rustler; I am still working on a project that relies heavily on it and had to discover some pain points by myself.

zookzook

zookzook

I created a PR 17 to update SortedSet to rustler 0.22, so you can use the SortedSet in Elixir 1.12.x and OTP 24. I leave this comment here, maybe someone wants to use the package in Elixir 1.12.x and OTP 24 and is searching for some hints.

zeroexcuses

zeroexcuses

@rm-rf-etc : Thanks for writing the tutorial. I was running into similar rustler problems.

Last Post!

dimitarvp

dimitarvp

Yes, there are people like that (me). Thanks! :heart:

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement