With the recent runtime removal,
utilizing Rust libraries from other languages has gotten even better. In
this post I am going to take the Rust library that wycats used in
and use it from both Perl 5, and Julia.
Fix cargo to create a .so instead of a .rlib:
Also, cargo appends a fingerprint to the lib name, so let’s
use a Makefile that will fix it so we have an unchanging lib name:
Ok, let’s get started writing the points library:
First, we bring some traits into scope from the stdlib that we will
need. Then we define our data structures.
Next, we need to define the functions that we will export for use from
the other languages.
Finally, add a quick test so we can make sure we get the same result
Now just compile, and we are done writing our Rust library.
Using libpoints from perl
We will be using FFI::Raw instead of XS. FFI::Raw is a perl module that
wraps libffi, and makes this very easy:
Now, let’s run it and see what we get:
Using libpoints from Julia
Julia is even easier to use with our Rust
library, as it has a C FFI builtin to the language: