espressif/rust-esp32-example

Invoke cargo from CMake automatically

igrr opened this issue · 1 comments

igrr commented

Currently the instructions require Cargo to be executed separately before running CMake / idf.py. It would probably be less error prone to invoke Cargo from CMake, to make sure the library is updated if anything changes.

(We could consider an alternative, invoking CMake from Cargo; however I think this would be harder to implement, especially when bindings come into play.)

Regarding:

(We could consider an alternative, invoking CMake from Cargo; however I think this would be harder to implement, especially when bindings come into play.)

JFYI: I have a working proof of concept now, in my https://github.com/ivmarkov/rust-esp32-std-hello demo.
It is a Cargo-first build where the intricacies of building ESP-IDF, or even downloading the Xtensa ESP32 GCC toolchain are completely hidden. The POC is implemented via a (hidden) delegation to PlatformIO, but I think something similar (modulo automatic download of the Xtensa toolchain) might be doable with a delegation to a pure CMake build too. The ideas could be reused almost 1:1.

Regarding a Cargo-first build being difficult when bindings come into play: caling C from Rust is not a problem, at least in regards to calling from Rust any unsafe C API which is part of the ESP-IDF SDK. The other way around (using cbindgen to generate C bindings so that Rust APIs are exposed and callable from C) is probably more difficult with a Cargo-first build. Yet, for people who want to write all of their code in Rust, and just consume the ESP-IDF SDK via safe (or unsafe) APIs, Cargo-first might be the (much) easier option.