PlatformIO Community

How would I implement a Rust compiler that links with "any" framework

I successfully compiled & linked Rust code against the Arduino framework compiled by pio (yay!). I did this in a very “hacky” way - at least that’s what it feels like - with a build middleware that hooks the main.cpp compilation (which is almost empty) and compiles with cargo instead.

My question is, what is the “correct” way to do this? I want to sit on top of any framework or platform that pio has by default - I don’t care if it’s mbed on an nrf52 or Arduino on an ESP32. I want the underlying framework to compile and then I generate bindings on the fly (bindgen) and give the appropriate RUSTFLAGS to cargo for the linking process - Rust supports almost all of the targets that pio supports (apart from the AVR).

Keep in mind that Rust is not a framework on its own - at least not the way I use it (I want to blink a light with digitalWrite).

Also keep in mind (if it changes anything) that my target(s) are not .rs files but the whole project directory (that’s how cargo works - it’s like make, rustc on the other side is like gcc. Using the internal SCons instead of cargo currently sounds to me like a terrible idea and a TON of work)

Current progress: https://github.com/dzervas/platformio-arduino-rust - pio run does produce an ELF yet - getting there though

1 Like

Hey :slight_smile:

Great progress! Could you fix a link to a project?

Forgot to make it public!

Thank you! :slight_smile:

1 Like

Thanks! :blush: I added references to the main feature request:

1 Like

In case anyone is interested, I went the extra_script way. I created an empty main.cpp, hooked on it using Middleware, executed cargo build and added the resulting .o to PIOBUILDFILES. Take a look at the repo linked on the post.