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