8

I have .cargo/config.toml with following:

[unstable]
unstable-options = true
build-std = ["core", "alloc"]

But I need build-std only for one target (e.g. thumbv7em-none-eabihf).

Is there any way to declare it specifically for a target?

It could be something like this:

# wrong example, doesn't work apparently
[target.thumbv7em-none-eabihf.unstable]
build-std = ["core", "alloc"]

Note, I’m talking about configs only, I know how to configure it with cargo execution arguments. That’s needed to automatically ignore build-std for targets other then mentioned, e.g. default host target.

Alex Koz.
  • 490
  • 8
  • 26

1 Answers1

3

As of 2023-07-04 this is not possible to achieve using only the built-in cargo configuration. See the Background section for details.

Workaround

You will need to build with an external invocation of cargo for that target e.g. for "core" and "alloc"

cargo build --target thumbv7em-none-eabihf -Z build-std="core,alloc"

Tested with the relevant toolchain installed and this test program:

#![feature(restricted_std)]

fn main() {
    loop {}
}

with cargo invocation

cargo build --target thumbv7em-none-eabihf -Z build-std="std,panic_abort"

Background

After some experimentation and searching, there is an open issue for cargo to add this feature here but progress appears to be slow as multiple different approaches have been explored. As build-std is still an unstable interface, available only in nightly versions of cargo, there are still conflicts with other features and some open as well as closed PRs related to changing the semantics. The tracking issue for this kind of feature is here.

  • Unfortunately, sims to that isn’t a solution, because Im talking about configs only, I know how to configure it with cargo execution arguments. It needed to automatically ignore `build-std` for targets other Then mentioned, e.g. default host target. – Alex Koz. Jul 05 '23 at 09:52
  • 1
    I have updated the headings. – Jade Bilkey Jul 07 '23 at 14:02