Skip to content

Instantly share code, notes, and snippets.

@davidkellis
Last active Dec 10, 2018
Embed
What would you like to do?
foo project in rust (to be called from a crystal project called bar - https://gist.github.com/davidkellis/f40588787a354aa7d44c4dec4c52ad50)

How to build:

$ cargo build
   Compiling foo v0.1.0 (file:///Users/david/Projects/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 1.57s
$ ll target/debug/
total 592
drwxr-xr-x@ 11 davidellis  staff     374 Dec 10 16:02 .
drwxr-xr-x@  4 davidellis  staff     136 Dec 10 16:02 ..
-rw-r--r--@  1 davidellis  staff       0 Dec 10 16:02 .cargo-lock
drwxr-xr-x@  3 davidellis  staff     102 Dec 10 16:02 .fingerprint
drwxr-xr-x@  2 davidellis  staff      68 Dec 10 16:02 build
drwxr-xr-x@  5 davidellis  staff     170 Dec 10 16:02 deps
drwxr-xr-x@  2 davidellis  staff      68 Dec 10 16:02 examples
drwxr-xr-x@  3 davidellis  staff     102 Dec 10 16:02 incremental
-rw-r--r--@  1 davidellis  staff      98 Dec 10 16:02 libfoo.d
-rwxr-xr-x@  2 davidellis  staff  297120 Dec 10 16:02 libfoo.dylib
drwxr-xr-x@  2 davidellis  staff      68 Dec 10 16:02 native
[package]
name = "foo"
version = "0.1.0"
authors = ["davidkellis <davidkellis@gmail.com>"]
[dependencies]
[lib]
crate-type = ["cdylib"]
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
#[no_mangle]
pub extern "C" fn call_from_c() {
println!("Just called a Rust function from C!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment