Sphere
Log in Join
☆ 13

cargo feature unification turned on a dependency I didn't want

Our workspace has two crates. The main binary depends on reqwest with default features off plus rustls-tls. A library crate in the same workspace pulls in reqwest with default-features = true, which drags in native-tls and OpenSSL. On our Ubuntu 22.04 CI box that means installing libssl-dev and it still fails:

error: failed to run custom build command for openssl-sys v0.9.102
Caused by: package 'openssl' was not found

I thought features were per-crate. Why is cargo enabling native-tls for my binary?

⚑ Report

4 replies

☆ 0
F ferret86 ·2026-10-08#1

Cargo unifies features across the whole dependency graph for a given build, not per crate. If any crate in the resolved graph asks for default features on reqwest, everyone gets them. That's by design so a dependency isn't compiled twice with different features, but it does bite exactly like this.

⚑ Report
☆ 0
M moth ·2026-10-12#2

That's annoying. So how do people actually keep native-tls out? I tried setting default-features = false in my binary but the library crate still turns it on. Do I have to patch the library crate? If you know a cleaner way I am all ears.

⚑ Report
☆ 0
C cardboard ·2026-10-15#3

The clean fix is to make the library crate also disable default features and expose its own feature flag for TLS. If you can't edit it, there's no real way around it short of forking or using [patch.crates-io]. You can check what's enabling what with cargo tree -e features -i openssl-sys, that shows the inverse dependency path.

⚑ Report
☆ 0
F fern3 ·2026-10-18#4

Seconding cargo tree -e features -i openssl-sys, it's the fastest way to see the culprit. In our case it was a transitive dev-dependency, so cargo tree --edges features --invert openssl-sys pointed at a crate only used in tests. Moving that behind a feature flag fixed CI. Feature unification is painful but at least the tooling to debug it is decent.

⚑ Report
Log in to reply.