# Can Cargo profiles affect dependency features?

**URL:** <https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444>\
**Category:** help\
**Created:** [February 6, 2022, 6:57pm UTC](https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444 "2022-02-06T18:57:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Nagle](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/john_nagle/32/17844_2.png) [@John\_Nagle](https://users.rust-lang.org/u/John_Nagle)\
**Post date:** [February 6, 2022, 6:57pm UTC](https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444/1 "2022-02-06T18:57:07Z")

</div>

I want to have a custom Cargo profile that enables Tracy profiling. Is there syntax for [dependencies] that allows this.

I want to be able to build with

```
cargo --profiles tracy

```

and have

```rust
[dependencies]
profiling = { version = "1", default-features = false }
tracy-client = {version = "0.12" }

```

change to

```rust
[dependencies]
profiling = { version = "1", default-features = false, features = ["profile-with-tracy"] }
tracy-client = {version = "0.12", optional = true }

```

in both the top-level workspace and lower-level workspaces.

The Cargo book shows [dev-dependencies], which is the right idea but apparently not usable for custom profiles. There's [build-dependencies], but that doesn't seem suitable either. [features] can almost do this, but not quite, I think.

This must be possible somehow. Building with and without profiling is a common need.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kornel/32/4823_2.png) [@kornel](https://users.rust-lang.org/u/kornel)\
**Post date:** [February 6, 2022, 9:08pm UTC](https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444/2 "2022-02-06T21:08:38Z")

</div>

That sounds like it should be `cargo --features tracy`.

---

<div class="post-metadata">

**Author:** ![John\_Nagle](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/john_nagle/32/17844_2.png) [@John\_Nagle](https://users.rust-lang.org/u/John_Nagle)\
**Post date:** [February 6, 2022, 9:51pm UTC](https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444/3 "2022-02-06T21:51:57Z")

</div>

That makes sense. Found the "/" syntax that makes this work. I wasn't clear on how to get a feature flag from the command line down to a crate.

```rust
[features]
# Feature "tracy" enables the network client tracy-client and turns on the profiling macros in "tracy"
tracy = ["tracy-client", "profiling/profile-with-tracy"]

[dependencies]
# The features flag "tracy" will add "profiling-with-tracy" to this.
profiling = { version = "1", default-features = false] }
# This should work, including tracy-client only if tracy is on.
tracy-client = {version = "0.12", optional = true }

```

---

<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 7, 2022, 9:52pm UTC](https://users.rust-lang.org/t/can-cargo-profiles-affect-dependency-features/71444/4 "2022-05-07T21:52:07Z")

</div>

Closed on May 7, 2022, 9:52pm UTC

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.
