This repo contains a MWE for creating a Rust library that can be successfully loaded and run as part of a matlab script on blanca. This mostly follows this blog post, with some additional jiggery-pokery to allow us to build the rust library on our local machine in such a way that it runs properly on blanca.
- After writing your desired functions in pure rust (ie
src/lib.rs
), wrap them in a foreign function interface wrapper (src/wrapper.rs
) that accepts and returns C-compatible types that matlab can cope with. - Will also need a header file (
bindings.h
) for matlab to ingest; this can be autogenerated as part of the regular build process viabuild.rs
. - The library needs to be built against the glibc version available on blanca, currently 2.28. Managing glibc versions is a nuisance, so we'll build our library in a containerized environment that has the correct glibc installed in it by default; this container is described in
Dockerfile
. - Build this image, run it as a container with your rust source directory mounted, and build with
cargo build --target=x86_64-unknown-linux-gnu
(maybe throw a--release
flag in there for production builds). - Zip up the whole thing (or just the .so and .h files if you're feeling stingy), and send them to blanca.
- After making a project directory (probably under
/scratch/alpine/<user>
), unzip the rust tarball there, and create a matlab function that loads the library and calls the function (iematlab/addWithRust.m
). Probably the library load / unload should be done not inside every function call in production.- Check that the
libname
andlibpath
make sense for your example.
- Check that the
matlab/demo.m
trivially calls this function, andmatlab/demo.slurm
submits it to the high priority queue.