rust-lang/cargo · error

dependency ` ` in package ` ` requires a ` ` artifact to be…

Error message

dependency `{}` in package `{}` requires a `{}` artifact to be present.

What it means

During dependency artifact resolution, Cargo matches a dependency's required artifact kind (cdylib/staticlib/bin) against the targets produced by the dependency. If none of the dependency's targets satisfy the required artifact kind, it bails naming the dependency, the parent package, and the missing artifact kind.

Solutions

  1. Ensure the dependency crate actually produces the required artifact (add `crate-type = ["cdylib"]` / `[[bin]]` to the dependency's Cargo.toml).
  2. Change the dependency declaration's artifact kind to match what the dependency produces.
  3. For SelectedBinary, verify the bin name matches a `[[bin]] name = ...` in the dependency.

Example fix

// before
# parent Cargo.toml
[dependencies]
foo = { version = "1", artifact = "cdylib" }
# foo only has crate-type = ["rlib"]
// after
# foo's Cargo.toml
[lib]
crate-type = ["rlib", "cdylib"]
Defensive patterns

Strategy: validation

Validate before calling

// Cross-check artifact kind against the dependency's declared targets
let dep_manifest = fetch_dep_manifest(&dep)?;
let produces = dep_manifest.lib_crate_types();
if !produces.contains(&required_artifact) {
    eprintln!("dep {dep} does not produce {required_artifact}");
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: A package declares a dependency with `artifact = ...` requiring a cdylib/staticlib/specific bin, but the dependency crate does not produce that artifact kind (e.g. requires a cdylib but the dep only builds an rlib; requires a named bin that doesn't exist). Encountered with cargo's bin/cdylib artifact dependencies feature.

Common situations: Misconfigured `artifact = "cdylib"` on a dependency that is a pure Rust library (rlib only); requiring a `bin` artifact with a `lib`-only crate; typo in the bin name for SelectedBinary; cross-compilation where the target lacks the artifact.

Related errors


AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11). Data as JSON: /api/errors/ecb2c1b2ffd4aec5. Report an issue: GitHub.

Appendix: source

Thrown at src/compiler/artifact.rs:124

    let mut out = HashSet::default();
    let artifact_requirements = artifact_dep.artifact().expect("artifact present");
    for artifact_kind in artifact_requirements.kinds() {
        let mut extend = |kind, filter: &dyn Fn(&&Target) -> bool| {
            let mut iter = targets.iter().filter(filter).peekable();
            let found = iter.peek().is_some();
            out.extend(std::iter::repeat(kind).zip(iter));
            found
        };
        let found = match artifact_kind {
            ArtifactKind::Cdylib => extend(artifact_kind, &|t| t.is_cdylib()),
            ArtifactKind::Staticlib => extend(artifact_kind, &|t| t.is_staticlib()),
            ArtifactKind::AllBinaries => extend(artifact_kind, &|t| t.is_bin()),
            ArtifactKind::SelectedBinary(bin_name) => extend(artifact_kind, &|t| {
                t.is_bin() && t.name() == bin_name.as_str()
            }),
        };
        if !found {
            anyhow::bail!(
                "dependency `{}` in package `{}` requires a `{}` artifact to be present.",
                artifact_dep.name_in_toml(),
                parent_package,
                artifact_kind
            );
        }
    }
    Ok(out)
}

View on GitHub (pinned to eb98b54bc9)