Custom target-like config for crates

I want to parameterize a crate of mine to be compiled for different hardware targets.
I don't want to use a feature for that, because the configuration targets should be mutually exclusive.
Within the code base the chosen target only affects a constant which is used throughout the code.

I want the user to choose the target device in their dependency config, analogous to features.
Does cargo support something like this?

I.e.

[dependencies]
my_crate = { version = "0.1.0", target_device = "this_specific_one" }

The target in this context is not a cargo target as available, but a set of different network co-processor (NCP) models from the same series of a hardware vendor.

Maybe this can be represented by a (still nightly) artifact dependency?

The target has to be supported by your toolchain though, not sure what is meant by:

1 Like

I thought about this a bit more and decided, that a cargo config is not really suitable for my use case due to transient dependencies. I ended up using const_env to allow users to override the value at compile-time.

I suspect the design proposal for mutually exclusive features would fit which solves the problems with that concept by effectively creating package parameters (Pre-RFC: Mutually-excusive, global features - cargo - Rust Internals)

1 Like