Sunday, 10 April 2016

Rust

A few weeks ago, some enforced time off gave me time to do some research into a topic that some of my colleagues have been getting quite excited about. Rust.

Rust is a new language from Mozilla. Unlike Java and C#, it compiles down to machine code. Unlike Swift and Go it doesn't require an OS - a subset of the standard library (known as core) can be used on any platform. Unlike C++, it's been designed with good ideas from the start, including strong borrow semantics and pattern matching, and unlike C it contains good ideas, period. No more writing your own linked-list implementation on every platform you develop for. It's the first language I've seen where there's no "I'll just have to do this bit in C". Pure Rust, even on a Cortex M4, is the promise. But is it the reality?

First impressions weren't good. Rust's stable/beta/nightly model means that you can experiment with new features considered unstable. Unfortunately these features can and do change, and many of them are required to do bare metal Rust. So github is littered with projects which probably used to work for some platform or another, but don't any more. Zinc.rs is probably the biggest, but when I checked a change in compiler internals meant that their clever Rust compiler plugin for auto building platform setup code no longer compiled. It was too much to unpick, especially for a newbie. I saw some good projects for bare metal on x86, but I really wanted to use my M4F Stellaris  Launchpad.

Eventually I found https://github.com/mdaffin/teensy-3-rust which did at least compile out of the box on Rust 1.9 nightly. Some time later, I've got https://github.com/thejpster/bare-metal-arm-rust running on the Stellaris.

Top tip - don't leave unimplemented!() in your code as it calls panic!().

Top tip 2 - Don't forget to keep generating a bin from the ELF, otherwise you're running one version of the code while debugging the other, and that's just baffling.

No comments:

Post a Comment