'Workspace optional dependencies (std & no_std)

I am developing a code for my school's rocketry team and I have two programs, one meant to flash the on-board computer and another to run some data analysis on the flight data. The chip code uses no_std while the data analysis program uses std. The data-analysis code will run on my PC, and the chip code will run on the chip. Here is my workspace root Cargo.toml and my project graph:

[workspace]

members = [
    "chip",
    "data-analysis",
]
.
├── Cargo.lock
├── Cargo.toml
├── chip
│   ├── Cargo.toml
│   ├── memory.x
│   ├── openocd.cfg
│   ├── openocd.gdb
│   └── src
│       └── main.rs
├── data-analysis
│   ├── Cargo.toml
│   └── src
│       └── main.rs
├── README.md
└── resources
    ├── 3m.mkd
    ├── data-stm32f103c8t6.pdf
    ├── links.txt
    ├── reference-stm32f103xx.pdf
    ├── schematic-stm32f103c8t6.png
    └── todo.txt

I have decided to use a workspace to organize my code. When I attempt to build the workspace, I get the error:

error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7m-none-eabi` target may not support the standard library
  = note: `std` is required by `data_analysis` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

When I compile with cargo build -Zbuild-std I get the error:

error[E0463]: can't find crate for `panic_abort`

error[E0658]: use of unstable library feature 'restricted_std'
  |
  = help: add `#![feature(restricted_std)]` to the crate attributes to enable

However I need no_std and not restricted_std.

I understand that dependencies for all files are stored in Cargo.lock and presumably that's why it is producing this error. My question is, how do I express to the compiler that I need std for data_analysis but not for chip code? Should I even be using workspaces over just using one package with multiple binaries and using [features] in the Cargo.toml?



Solution 1:[1]

It seems like you're trying to complile data_analysis with the same target as chip. I recommend just getting rid of the root Cargo.toml and compiling the respective ones in the folders. You could make a Makefile to automate this easily

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AltF2