Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created December 27, 2013 07:27
Show Gist options
  • Save jc00ke/8143706 to your computer and use it in GitHub Desktop.
Save jc00ke/8143706 to your computer and use it in GitHub Desktop.
Rust/Ruby FFI
require 'ffi'
module Rust
module Uuid
extend FFI::Library
ffi_lib './librust_uuid-2b1863329f7b31d9-0.1.so'
attach_function :asdf, [], :string
attach_function :uuid_str, [], :void
end
end
puts Rust::Uuid.asdf
puts Rust::Uuid.uuid_str
#[link(name="rust_uuid", vers="0.1")];
extern mod extra;
use extra::uuid::Uuid;
#[no_mangle]
fn uuid_rust() -> ~str {
let uuid1 = Uuid::new_v4();
uuid1.to_str()
}
#[no_mangle]
pub extern fn asdf() -> &'static str {
return "asdf"
}
#[no_mangle]
pub extern fn uuid_str() {
uuid_rust();
}
#[fixed_stack_segment]
fn main() {
println(uuid_rust());
println(asdf());
}
@jc00ke
Copy link
Author

jc00ke commented Dec 27, 2013

uuid.rs compiled as a library with

$> rustc --lib uuid.rs

@jc00ke
Copy link
Author

jc00ke commented Dec 27, 2013

$> ruby uuid.rb
asdf

You've met with a terrible fate, haven't you?

fatal runtime error: runtime tls key not initialized
[1]    26242 abort (core dumped)  ruby uuid.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment