Nikita Fedyashev
Nikita Fedyashev

Reputation: 18993

How to set Cargo configurable-env setting for specific profile?

I'm trying to find out if it is possible to use configurable-env Cargo feature to set environment variables specific to a certain profile.

# Instead of global version:
# [env]
# FOO_QTY = "10"

# Something similar to the following(pseudocode):
[profile.test.env]
FOO_QTY = "2"

[profile.release.env]
FOO_QTY = "1000"

Upvotes: 3

Views: 950

Answers (1)

kelloti
kelloti

Reputation: 8951

Not exactly your question, but you can create a static or const that's set based on the profile.

pub const FOO_QTY: usize = if cfg!(build = "release") {
    1000
} else {
    2
};

Presumably you're trying to conditionally configure some value or behavior (at least that's how I found this question). The cfg! macro is a more flexible way to do that.

Upvotes: 1

Related Questions