# Another question about cfg

**URL:** <https://users.rust-lang.org/t/another-question-about-cfg/55737>\
**Category:** uncategorized\
**Created:** [February 17, 2021, 8:38am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737 "2021-02-17T08:38:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![piter76](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@piter76](https://users.rust-lang.org/u/piter76)\
**Post date:** [February 17, 2021, 8:38am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/1 "2021-02-17T08:38:33Z")

</div>

Is it possible to have something like this in code and then in Cargo.toml set ETA to true or false?

```rust
#[cfg(ETA)]

```

Basically I don't know what to put in Cargo.toml in order to make it either "active";

Thank you

---

<div class="post-metadata">

**Author:** ![alice](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alice/32/9777_2.png) [@alice](https://users.rust-lang.org/u/alice)\
**Post date:** [February 17, 2021, 8:39am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/2 "2021-02-17T08:39:57Z")

</div>

You are most likely looking for Cargo features.

[https://doc.rust-lang.org/cargo/reference/features.html](https://doc.rust-lang.org/cargo/reference/features.html)

---

<div class="post-metadata">

**Author:** ![piter76](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@piter76](https://users.rust-lang.org/u/piter76)\
**Post date:** [February 17, 2021, 8:42am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/3 "2021-02-17T08:42:18Z")

</div>

But wouldn't that mean that I'd have to write?:

```rust
#[cfg(feature=ETA)]

```

---

<div class="post-metadata">

**Author:** ![Kestrer](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kestrer/32/22688_2.png) [@Kestrer](https://users.rust-lang.org/u/Kestrer)\
**Post date:** [February 17, 2021, 8:44am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/4 "2021-02-17T08:44:40Z")

</div>

You'd have to write `#[cfg(feature = "ETA")]` - if it's an optional part of your library, that is what you should be doing. Top-level `cfg` flags are usually reserved for specifying _how_ the library is built rather than what parts of it are built.

---

<div class="post-metadata">

**Author:** ![piter76](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@piter76](https://users.rust-lang.org/u/piter76)\
**Post date:** [February 17, 2021, 8:48am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/5 "2021-02-17T08:48:33Z")

</div>

Yes, but the ETA is basically a flag that I want to set true or false.  
Something similar to C++ #ifdef SOME\_FLAG

---

<div class="post-metadata">

**Author:** ![alice](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alice/32/9777_2.png) [@alice](https://users.rust-lang.org/u/alice)\
**Post date:** [February 17, 2021, 8:51am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/6 "2021-02-17T08:51:07Z")

</div>

It is possible to set such flags with the `--cfg` argument, i.e.

```rust
RUSTFLAGS="--cfg ETA" cargo build

```

will enable code marked with `#[cfg(ETA)]`. Additionally, such a flag can also be set by a build script.

---

<div class="post-metadata">

**Author:** ![piter76](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@piter76](https://users.rust-lang.org/u/piter76)\
**Post date:** [February 17, 2021, 8:55am UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/7 "2021-02-17T08:55:16Z")

</div>

Sounds like an overkill tbh.  
Thanks for the help.

---

<div class="post-metadata">

**Author:** ![notriddle](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/notriddle/32/51307_2.png) [@notriddle](https://users.rust-lang.org/u/notriddle)\
**Post date:** [February 17, 2021, 6:56pm UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/8 "2021-02-17T18:56:55Z")

</div>

You can also [do it in `build.rs`](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cfg).

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [May 18, 2021, 6:57pm UTC](https://users.rust-lang.org/t/another-question-about-cfg/55737/9 "2021-05-18T18:57:32Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
