1

I'd like to pass a custom --cfg flag to rustc via Cargo. Normally, I can do this by putting this in .cargo/config for a given crate:

[build]
rustflags = "--cfg procmacro2_semver_exempt"

However, in one of my crates, I am using a custom compilation target, and that seems to break rustflags;

[build]
target = "avr-atmega32u4.json"
rustflags = "--cfg procmacro2_semver_exempt"

[unstable]
build-std = ["core"]

[env]
AVR_CPU_FREQUENCY_HZ = "16_000_000"

In this case, the config flag is not passed to rustc. I've tried moving rustflags into a target-specific section:

[target.avr-atmega32u4.json]
rustflags = "--cfg procmacro2_semver_exempt"

but this doesn't seem to have any effect either.

Cactus
  • 27,075
  • 9
  • 69
  • 149
  • 1
    this work however "avr-atmega32u4.json" is not a valid triple target. https://doc.rust-lang.org/cargo/reference/config.html#configuration-format – Stargateur Jan 02 '23 at 12:31
  • @Stargateur so how do I refer to a target that is specified in a `.json` file? – Cactus Jan 02 '23 at 13:43
  • that far belong my knowledge of cargo, I got no idea, notice the doc say to use an array so maybe try `rustflags = ["--cfg", "procmacro2_semver_exempt"]` – Stargateur Jan 02 '23 at 13:45
  • @Stargateur I found in [the docs](https://doc.rust-lang.org/cargo/reference/config.html#target) that it should be `[target.avr-atmega32u4]` (without the `.json` filename extension), *but* even using that it still doesn't work. – Cactus Jan 02 '23 at 13:48
  • @Stargateur can you show a complete example that sets the `target` to a "stock" target triple, and successfully sets `rustflags`? – Cactus Jan 02 '23 at 13:49

0 Answers0