Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-dependencies are built even when unused #5385

Closed
kpcyrd opened this issue Apr 18, 2018 · 3 comments
Closed

dev-dependencies are built even when unused #5385

kpcyrd opened this issue Apr 18, 2018 · 3 comments
Labels
A-features Area: features — conditional compilation C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@kpcyrd
Copy link

kpcyrd commented Apr 18, 2018

I ran into a weird combination of problems:

  • I have a library crate that uses the example/ folder for tooling related to that library
  • the library does not depend on openssl
  • one of my examples (lets call it bar) has a dependency to openssl (in dev-dependencies)
  • a different example (lets call it foo) needs to build with cargo build --example foo --release --target x86_64-unknown-linux-musl (without workarounds)
  • cross compiling is non-trivial with openssl-sys (Can't build for musl on Linux sfackler/rust-openssl#603)

Since foo has no direct or indirect dependency to openssl-sys, cargo build --example foo --release --target x86_64-unknown-linux-musl should work just fine. This is currently not the case since cargo builds all dev-dependencies as well when doing a build, even if those are unused.

I currently have a weird workaround in place where I moved the openssl related dev-dependency to the normal dependencies so I can control it with feature flags. This means I have to start bar with that feature flag. This makes CI more complicated. Also, since the crate is a library, moving a dev dependency to the normal dependencies is problematic.

I think cargo could determine that openssl-sys is not needed for the build I've started and therefore skip it. What do you think?

@matklad
Copy link
Member

matklad commented Apr 18, 2018

Cargo at this moment can not determine if a dependency is used by one example, but not the other. We'll need target-specific dependencies for this I think. That is, we need an ability to say, in Cargo.toml, that bar depends on openssl, but foo does not.

@matklad matklad added the A-features Area: features — conditional compilation label Apr 18, 2018
@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 18, 2018
@kpcyrd
Copy link
Author

kpcyrd commented Apr 18, 2018

This might cross the rustc-cargo boundary, but in theory it should be possible to tell if an example depends on a crate based on its extern crate imports?

@ehuss
Copy link
Contributor

ehuss commented Mar 18, 2020

extern crate is usually no longer used in the 2018 edition, and rustc would require dependencies to be built to run expansion anyways.

Considering the solution here is cargo target-specific dependencies, I'm going to close this as a duplicate of #1982.

@ehuss ehuss closed this as completed Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

4 participants