Skip to content

dependencies foo?/bar that are disabled should not need to be available during dependency resolution #11698

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

Closed
decathorpe opened this issue Feb 10, 2023 · 3 comments
Labels
A-features Area: features — conditional compilation C-bug Category: bug

Comments

@decathorpe
Copy link
Contributor

decathorpe commented Feb 10, 2023

Problem

I'm trying to adapt the tooling that is used in Fedora Linux (and some other related distributions) to work with dep:foo and foo?/bar feature dependency syntax, but I have now hit a rather annoying roadblock:

It appears that conditionally enabled dependency features (accidentally?) are still required to be available during dependency resolution, even if they end up being completely unused (because they are not enabled). This might be an oversight from when this feature was implemented (for Rust 1.60.0), since other optional dependencies that are disabled aren't required to be available during dependency resolution either.

Needing to pull in additional dependencies (that end up being completely unused during the build) would be a real pain for Rust builds in Linux distributions, since it will increase the "breadth" of the dependency tree greatly for any crate that uses weak dependency features like this.

Steps

For example, in time v0.3.17, the "default" feature pulls in the following features as dependencies: {"default", "std", "alloc", "serde?/alloc"}. In this case, the dep:serde dependency isn't even included, and so the the serde?/alloc feature should be ignored. However, cargo still fails to build the crate if serde is not available: error: no matching package named serde found

Possible Solution(s)

Cargo should ignore optional dependencies that are only mentioned in disabled "weak dependency features" during dependency resolution (they are already ignored when building the crate), similar to other disabled optional dependencies.

Notes

Version

I have tested this with the cargo binary provided by Fedora Linux (because that's the only cargo that is available for our package builds):

cargo 1.67.0
release: 1.67.0
host: x86_64-unknown-linux-gnu
libgit2: 1.5.1 (sys:0.16.0 system)
libcurl: 7.87.0 (sys:0.4.59+curl-7.86.0 system ssl:OpenSSL/3.0.7)
os: Fedora 39.0.0 [64-bit]

However, no downstream patches are applied to cargo in Fedora Linux as far as I can tell, so this should be very close to cargo from an official Rust toolchain installed with rustup.

@decathorpe decathorpe added the C-bug Category: bug label Feb 10, 2023
@epage
Copy link
Contributor

epage commented Feb 10, 2023

I think the related issues to this are #11352 and #10801

@epage epage added the A-features Area: features — conditional compilation label Feb 10, 2023
@ehuss
Copy link
Contributor

ehuss commented Feb 10, 2023

I'm going to close as a duplicate of #10801. For now, the resolver must assume that the dependency is used, since that information isn't available until after dependency resolution.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2023
@c410-f3r
Copy link

Also dup of #11426

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-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants