Last active
March 9, 2024 00:32
-
-
Save tsloughter/858030465602b524b6ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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