#cargo #platformio

app cargo-pio

Cargo<->PlatformIO integration: a cargo subcommand

20 releases (5 breaking)

0.25.2 Jan 13, 2022
0.25.0 Dec 4, 2021
0.24.3 Oct 24, 2021
0.20.4 Jul 29, 2021

#54 in Cargo plugins

Download history 61/week @ 2021-10-02 32/week @ 2021-10-09 24/week @ 2021-10-16 118/week @ 2021-10-23 62/week @ 2021-10-30 58/week @ 2021-11-06 77/week @ 2021-11-13 80/week @ 2021-11-20 35/week @ 2021-11-27 80/week @ 2021-12-04 13/week @ 2021-12-11 14/week @ 2021-12-18 17/week @ 2021-12-25 10/week @ 2022-01-01 31/week @ 2022-01-08 13/week @ 2022-01-15

73 downloads per month

MIT/Apache

765KB
5.5K SLoC

cargo-pio = Cargo + PlatformIO

Build Rust embedded projects with PlatformIO!

cargo-pio is a Cargo subcommand cargo pio, as well as a library crate.

Why?

If you are building a mixed Rust/C project, or a pure Rust project that needs to call into the Vendor SDKs for your board, cargo-pio might help you.

PlatformIO-first build

In this mode of operation, your embedded project would be a PlatformIO project and a Rust static library crate:

  • The project build is triggered with PlatformIO (e.g. pio run -t debug or cargo pio build), and PlatformIO calls into Cargo to build the Rust library crate;
  • cargo-pio is used as a Cargo subcommand to create the layout of the project;
  • Such projects are called 'PIO->Cargo projects' in the cargo-pio help

Example:

  • cargo install cargo-pio (or cargo install --git https://github.com/ivmarkov/cargo-pio.git cargo-pio)
  • cargo pio installpio
  • Create a new Cargo/PIO project:
    • cargo pio new --board <your-board> <path-to-your-new-project>
  • Enter your newly-generated project:
    • cd <path-to-your-new-project>
  • Build in debug:
    • pio run -t debug or cargo pio build
  • Build in release:
    • pio run -t release or cargo pio build --release
  • Note that once PlatformIO is installed and the PIO->Cargo project is created, you don't really need cargo-pio!

Call cargo pio --help to learn more about the various commands supported by cargo-pio.

Cargo-first build

  • In this mode of operation, your embedded project is a pure Cargo project and PlatformIO does not get in the way!
  • cargo-pio is used as a library crate and driven programmatically from build.rs scripts.

Cargo-first builds however are less flexible. They are only suitable for building and (linking with) the "SYS" crate that represents the Vendor SDK for your board. If you depend on other C libraries, you should be using a PlatformIO-first a.k.a. 'PIO->Cargo' project.

Example:

  • Check the esp-idf-sys SYS crate (used by the rust-esp32-std-hello binary crate). It demonstrates:
    • Automatic download and installation the SDK (ESP-IDF in that case), by programmatically driving PlatformIO;
    • Automatic generation of unsafe bindings with Bindgen for the ESP-IDF SDK. Crates like esp-idf-hal and esp-idf-svc depend on these bindings to implement higher level type-safe Rust abstractions;
    • Automatic generation of Rust link flags for the Rust Linker so that the ESP-IDF SDK is transparently linked into your binary Rust crate that you'll flash.

Dependencies

~13MB
~286K SLoC

a