ivmarkov/cargo-pio

cargo-pio = Cargo + PlatformIO

Build Rust embedded projects with PlatformIO!

cargo-pio = Cargo + 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.
Issues

Collection of the latest Issues

svenstaro

svenstaro

Comment Icon3

Currently as a user coming into this project, I have 0 idea what embuild is meant to do for me as a whole. Could you add an overall README?

N3xed

N3xed

Comment Icon0

In the esp-idf installer when it tries to create a python virtual env with

if the venv package is not installed the idf_tools.py script fails.

Note that the error message is also misleading:

Desired state: Check for this case and output a specific error (with instructions) early.

ivmarkov

ivmarkov

Comment Icon1

When using the native build, the linking phase fails with the following errors:

Preliminary analysis:

I am half there in figuring out the linkage problems with the native build and the C3 chip:

  • Rust is spitting out a -nodefaultlibs option on the command line, which seems to be kind of like "the default behavior" (but it seems you can control this on a Rust target level, when you define the target)
  • This is somehow preventing the linker from finding the missing intrinsic (__trunctfdf2); if I remove the -nodefaultlibs, it works OK
  • Short term solution: we have a simple workaround in adding a rustflags = ["-C", "default-linker-libraries"] to the [target.riscv32imc-esp-espidf] section in .cargo/config.toml in the relevant binary crate (rust-esp32-std-hello etcetera)
  • Long term solution: we should probably allow the "default libs" behavior on the Rust target level (as in riscv32imc-esp-espidf as well as in all xtensa targets, if it is not allowed there). Reason why I believe this is a correct behavior: I don't see the -nodefaultlibs argument amongst the "native" (cmake) args, which means the native ESP-IDF build is assuming it is NOT set

Unresolved questions/issues:

Versions

Find the latest versions by id

Information - Updated Jun 20, 2022

Stars: 46
Forks: 14
Issues: 6
IDE

3.5K

Rust Language Server (RLS)

The RLS provides a server that runs in the background, providing IDEs,

Rust Language Server (RLS)

Rust lang bookmarking tool

Rust and Rocket used bookmarking tool for search bar

Rust lang bookmarking tool

Rust Language Security

execrices: RUSTSEC-2021-0001

Rust Language Security

False Positive for rust-lang/rust#83583

The deprecation lint proc_macro_derive_resolution_fallback is intended to catch proc macro generated code that refers to items from parent modules that should not be in scope:

False Positive for rust-lang/rust#83583

rust_icu: low-level rust language bindings for the ICU library

See: The latest version of this file is available at

rust_icu: low-level rust language bindings for the ICU library

Rust lang exercises

Personal tips and drills in my journey as a beginner rustacean

Rust lang exercises

😍 Rust Language

👍 Download and execute rustup

😍 Rust Language

TensorFlow Rust provides idiomatic Rust language

bindings for Documentation

TensorFlow Rust provides idiomatic Rust language

Rust Language Learning material

Rust is blazingly fast systems programming language that prevents segfaults and guarantees thread safety

Rust Language Learning material
Facebook Instagram Twitter GitHub Dribbble
Privacy