rust-lang / rust-lang/cargo

Cargo fails to run when an *optional* dependency is missing

Open
#4,544 24 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-dependency-resolution A-optional-dependencies C-feature-request S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

#!/usr/bin/env bash

set -e

cd /tmp
[ -d cargo-optional-deps ] && rm -rf cargo-optional-deps
cargo new cargo-optional-deps
cd cargo-optional-deps

cargo build
cat >> Cargo.toml <<EOF
optional_dep_does_not_exist = { version = "1.0", optional = true }
EOF
cargo build

Fails with

error: no matching package named optional_dep_does_not_exist found (required by cargo-optional-deps)

I did not expect this because the dependency is not required as per http://doc.crates.io/manifest.html#the-features-section:

optional dependencies, which enhance a package, but are not required; and

I'm running into this behavior while integrating Cargo into a private build system that wants control over dependencies. As such, I need to elide optional dependencies by default in this system's dependency list.

I'm opening this issue to get some input on:

  1. Would ignoring missing optional dependencies for inactive features be a problem for Cargo?
  2. I tried to look through existing issues - has something like this been discussed before?
  3. An idea about resourcing/priority of the feature and how it fits into the roadmap for Cargo's integration with existing systems.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the shell reproduction from the issue to confirm Cargo's behavior when an inactive optional dependency cannot be found. Investigate Cargo's dependency resolution and feature handling, then determine whether missing optional dependencies should be ignored and what the resulting dependency list should contain.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.