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

Can skip dependency checking for non-built dependencies via exclude in a workspace. #6042

Closed
emilio opened this issue Sep 17, 2018 · 4 comments
Labels
A-optional-dependencies Area: dependencies with optional=true C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@emilio
Copy link

emilio commented Sep 17, 2018

So I was just looking at how Gecko manages to build without all the dependencies being in the tree.

For example, this dependency is Servo-only and thus not in the Gecko tree, yet it builds fine:

https://searchfox.org/mozilla-central/rev/bdc89dfd7869e418d788b28eb60ab8d94e708a15/servo/components/style/Cargo.toml#62

When I tried to do the same on the Servo for a Gecko-only dependency:

servo/servo@d681d58

It failed with:

error: failed to parse manifest at `/home/emilio/src/moz/servo/support/gecko/nsstring/Cargo.toml`

Which is kind of expected. However I could not understand the difference, and Gecko definitely relies on this. So I chased this down and turns out that gecko excludes the servo directory, and this causes optional dependencies that not get built to not get into the lockfile at all.

For example, that servo patch would also build if I did:

 default-members = [
     "ports/servo",
     "ports/libsimpleservo/",
     "tests/unit/*",
 ]
-exclude = [".cargo"]
+exclude = [".cargo", "components/style"]

(Note that the exclude needs to point at an ancestor of the optional dependency, not to the optional dependency itself).

This also causes other optional features that do exist (from crates.io for example) to get dropped from the lockfile.

I'm not completely sure it's intentional, but the side effect of it is really nice. It'd be really nice if it was the default behavior actually, or if at least it was possible without relying on this exclude bit. cc #4544.

I'm not sure how to proceed from here, we definitely rely on that to avoid having to heavily diverge the lockfiles for the two setups or sync a whole lot more of code.

@emilio
Copy link
Author

emilio commented Sep 17, 2018

@alexcrichton
Copy link
Member

Ah sorry for the delay here, this is currently expected behavior from Cargo. Cargo assumes that all path-local crates in a workspace can have cargo test executed at any time, so it includes all optional dependencies in the lock file. For non-workspace-members though Cargo assumes that optional dependencies aren't needed (as only members in general can be tested).

Are you asking here though to exclude all optional dependencies from a workspace? Or perhaps a different feature?

@emilio
Copy link
Author

emilio commented Sep 25, 2018

Are you asking here though to exclude all optional dependencies from a workspace? Or perhaps a different feature?

Yeah, I think that may be reasonable, or maybe excluding non-present optional dependencies? Making an optional dependency not being present not a hard error would be great.

@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 Sep 26, 2018
@ehuss ehuss added the A-optional-dependencies Area: dependencies with optional=true label Mar 6, 2020
@epage
Copy link
Contributor

epage commented Oct 24, 2023

Closing as a duplicate of #4988 where the stabilization is being tracked in #5133. If there is a reason we should keep this open, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-optional-dependencies Area: dependencies with optional=true 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