A quick update on this. We wrote a couple patches the other day with Andrew after he contacted me because I'd had just gotten into the swing of things and basically wrote more or less the same binding crate (= rust package) he did, asking me whether I'd like to collaborate.
We ended up finishing his
bela-rs crate, which exposes a safe interface for all features of the Bela API (setup, render, teardown, auxillary tasks, all the various ports, cape things, etc.), and I think it's ready for people to use.
Everything is on github:
bela-sys, which is an unsafe (in the rust meaning, i.e., it can segfault and things) crate exists in two, compatible, flavours:
- My bela-sys: the binding header is vendored, has a setup script, potentially easier to setup.
- Andrew's bela-sys: the binding header is generated on the fly during build, better when using a pre-release Bela image
- bela-rs, exposes a safe (can't segfault or do anything nasty to memory, etc.) Rust API for all of the Bela native API, and a few utility functions.
There are a few examples in each crate (
cargo run --example hello for example). Cross-compilation is preferred, but not mandatory, Rust being rather slow to compile (especially on ARM it seems), but fast to run, this is the fastest setup, I find. Simply copying the executable to the board and running it there works, Rust produces a monolithic executable, finding the right
.so on the board.
Performance is, of course, as good as C++, but you have access to a massive amount of rust packages already written (a bunch of state of the art lock free stuff in particular). I've been running moderately complex interactive applications written in it without any issue, be it performance, compatibility, crashes or anything.
A few examples:
- https://github.com/padenot/monome-bela-seq, a sequencer that outputs eurorack triggers using the analog outputs, controlled by a Monome grid (depending on the modules you use, there might be a need for a few bits of electronics to bring the voltage up from the 0V-5V the board can output)
- https://github.com/padenot/monome-rs, a crate to use a Monome grid (no code change between desktop and bela), used in
monome-bela-seq but available on its own
- https://github.com/padenot/mlr-rs a port of the classic mlr in rust (I think I've only pushed the desktop code, will push the bela code soon hopefully), a classic live sample-cutting application, also using
Let us know in the github issues or here if you have any question or face any issues or anything !