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:

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

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.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement