Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OTP 26 by supporting NIF v2.17 #526

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rustler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::env;
use std::process::Command;

// keep this sorted by version number
const NIF_VERSION: &[&str] = &["2.14", "2.15", "2.16"];
const NIF_VERSION: &[&str] = &["2.14", "2.15", "2.16", "2.17"];

fn main() {
let latest_version = NIF_VERSION.last().unwrap().to_string();
Expand Down
16 changes: 15 additions & 1 deletion rustler_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::process::Command;
use std::{env, fs};

const SNIPPET_NAME: &str = "nif_api.snippet";
const SUPPORTED_VERSIONS: [(u32, u32); 3] = [(2, 14), (2, 15), (2, 16)];
const SUPPORTED_VERSIONS: [(u32, u32); 4] = [(2, 14), (2, 15), (2, 16), (2, 17)];
philss marked this conversation as resolved.
Show resolved Hide resolved

trait ApiBuilder {
fn func(&mut self, ret: &str, name: &str, args: &str);
Expand Down Expand Up @@ -846,6 +846,7 @@ fn build_api(b: &mut dyn ApiBuilder, opts: &GenerateOptions) {
b.func("c_int", "enif_make_map_from_arrays", "env: *mut ErlNifEnv, keys: *const ERL_NIF_TERM, values: *const ERL_NIF_TERM, cnt: usize, map_out: *mut ERL_NIF_TERM");
}

// 2.15 was introduced in OTP 22
if opts.nif_version >= (2, 15) {
b.func(
"ErlNifTermType",
Expand All @@ -862,10 +863,23 @@ fn build_api(b: &mut dyn ApiBuilder, opts: &GenerateOptions) {
);
}

// 2.16 was introduced in OTP 24
if opts.nif_version >= (2, 16) {
b.func("*const ErlNifResourceType", "enif_init_resource_type", "env: *mut ErlNifEnv, name_str: *const c_uchar, init: *const ErlNifResourceTypeInit, flags: ErlNifResourceFlags, tried: *mut ErlNifResourceFlags");
b.func("c_int", "enif_dynamic_resource_call", "env: *mut ErlNifEnv, module: ERL_NIF_TERM, name: ERL_NIF_TERM, rsrc: ERL_NIF_TERM, call_data: *const c_void");
}

// 2.17 was introduced in OTP 26
if opts.nif_version >= (2, 17) {
b.func(
"c_int",
"enif_set_option",
"env: *mut ErlNifEnv, opt: ErlNifOption",
);
b.func("c_int", "enif_get_string_length", "env: *mut ErlNifEnv, list: ERL_NIF_TERM, len: *mut c_uint, encoding: ErlNifCharEncoding");
b.func("c_int", "enif_make_new_atom", "env: *mut ErlNifEnv, name: *const c_uchar, atom: *mut ERL_NIF_TERM, encoding: ErlNifCharEncoding");
b.func("c_int", "enif_make_new_atom_len", "env: *mut ErlNifEnv, name: *const c_uchar, len: size_t, atom: *mut ERL_NIF_TERM, encoding: ErlNifCharEncoding");
}
}

fn parse_nif_version(version: &str) -> (u32, u32) {
Expand Down
10 changes: 10 additions & 0 deletions rustler_sys/src/rustler_sys_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub enum ErlNifResourceFlags {
#[repr(C)]
pub enum ErlNifCharEncoding {
ERL_NIF_LATIN1 = 1,
ERL_NIF_UTF8 = 2,
}

/// See [ErlNifPid](http://www.erlang.org/doc/man/erl_nif.html#ErlNifPid) in the Erlang docs.
Expand Down Expand Up @@ -328,6 +329,15 @@ pub enum ErlNifTermType {
ERL_NIF_TERM_TYPE__MISSING_DEFAULT_CASE__READ_THE_MANUAL = -1,
}

/// See [ErlNifOption](http://www.erlang.org/doc/man/erl_nif.html#ErlNifOption) in the Erlang docs.
#[derive(Copy, Clone)]
#[repr(C)]
pub enum ErlNifOption {
// from https://github.com/erlang/otp/blob/1b3c6214d4bf359f7e5c143bef5c5ad9c90c5536/erts/emulator/beam/erl_nif.h#L333
ERL_NIF_OPT_DELAY_HALT = 1,
ERL_NIF_OPT_ON_HALT = 2,
}

// Include the file generated by `build.rs`.
include!(concat!(env!("OUT_DIR"), "/nif_api.snippet"));
// example of included content:
Expand Down