Skip to content

Instantly share code, notes, and snippets.

@tsloughter
Last active March 9, 2024 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsloughter/858030465602b524b6ac to your computer and use it in GitHub Desktop.
Save tsloughter/858030465602b524b6ac to your computer and use it in GitHub Desktop.
#[no_mangle]
pub fn foo(env: *mut ErlNifEnv, argc: int, argv: *ERL_NIF_TERM) -> ERL_NIF_TERM {
print!("Hello World from Rust\n");
unsafe {
let a = enif_make_atom(env, ("foo".to_c_str()).unwrap());
return a;
}
}
#include "erl_nif.h"
extern void foo(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
static ErlNifFunc nif_funcs[] = {
{"foo", 0, foo}
};
ERL_NIF_INIT(erl_nif, nif_funcs, NULL, NULL, NULL, NULL)
$ rustc --crate-type staticlib --emit obj erl_nif.rs
$ gcc -o erl_nif.so -fpic -shared erl_nif.c erl_nif.o /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-59beb4f7-0.11.0-pre.so -I/usr/lib/erlang/erts-6.0/include
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment