{"id":"ecb2c1b2ffd4aec5","repo":"rust-lang/cargo","slug":"dependency-in-package-requires-a-ar","errorCode":null,"errorMessage":"dependency `{}` in package `{}` requires a `{}` artifact to be present.","messagePattern":"dependency `(.+?)` in package `(.+?)` requires a `(.+?)` artifact to be present\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/artifact.rs","lineNumber":124,"sourceCode":"    let mut out = HashSet::default();\n    let artifact_requirements = artifact_dep.artifact().expect(\"artifact present\");\n    for artifact_kind in artifact_requirements.kinds() {\n        let mut extend = |kind, filter: &dyn Fn(&&Target) -> bool| {\n            let mut iter = targets.iter().filter(filter).peekable();\n            let found = iter.peek().is_some();\n            out.extend(std::iter::repeat(kind).zip(iter));\n            found\n        };\n        let found = match artifact_kind {\n            ArtifactKind::Cdylib => extend(artifact_kind, &|t| t.is_cdylib()),\n            ArtifactKind::Staticlib => extend(artifact_kind, &|t| t.is_staticlib()),\n            ArtifactKind::AllBinaries => extend(artifact_kind, &|t| t.is_bin()),\n            ArtifactKind::SelectedBinary(bin_name) => extend(artifact_kind, &|t| {\n                t.is_bin() && t.name() == bin_name.as_str()\n            }),\n        };\n        if !found {\n            anyhow::bail!(\n                \"dependency `{}` in package `{}` requires a `{}` artifact to be present.\",\n                artifact_dep.name_in_toml(),\n                parent_package,\n                artifact_kind\n            );\n        }\n    }\n    Ok(out)\n}\n","sourceCodeStart":106,"sourceCodeEnd":134,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/artifact.rs#L106-L134","documentation":"In match_artifacts_kind_with_targets (artifact.rs:101-132), an artifact dependency declares it needs a kind (cdylib, staticlib, a specific bin, or all bins), but none of the dependency package's targets match that kind. Cargo cannot satisfy the artifact requirement, so it bails naming the dependency, the parent package, and the missing artifact kind.","triggerScenarios":"A package declares `dep = { version = \"...\", artifact = [\"cdylib\"] }` (or `bin`, `staticlib`) but the referenced dependency crate does not define a target of that kind (e.g. the dependency only has a `lib` target with `crate-type = [\"rlib\"]`).","commonSituations":" depending on a crate expecting it to ship a cdylib/staticlib when it does not; wrong artifact kind in the manifest; depending on a version of the crate whose targets changed; using `artifact = \"bin\"` when the dep has no binary target.","solutions":["Confirm the dependency actually builds the requested artifact by checking its `Cargo.toml` `[lib] crate-type` or `[[bin]]` targets.","Change the `artifact = [...]` list to a kind the dependency actually provides.","Bump/switch the dependency version to one that includes the needed target.","If the dependency should provide it, add the target to the dependency's manifest."],"exampleFix":"// before (parent Cargo.toml)\n[dependencies]\nfoo = { version = \"1\", artifact = [\"cdylib\"] }\n// foo has no cdylib target -> error\n\n// after\n[dependencies]\nfoo = { version = \"1\", artifact = [\"staticlib\"] } // foo provides staticlib","handlingStrategy":"validation","validationCode":"// Before publishing/consuming, verify dep ships requested artifact kind\nlet needed: &[&str] = artifact_kinds_for(dep);\nlet provided: Vec<&str> = dep_targets.iter()\n    .filter_map(|t| match t.kind {\n        TargetKind::Cdylib => Some(\"cdylib\"),\n        TargetKind::Staticlib => Some(\"staticlib\"),\n        TargetKind::Bin => Some(\"bin\"),\n        _ => None,\n    }).collect();\nfor k in needed {\n    if !provided.iter().any(|p| p == k) {\n        return Err(format!(\"dep `{}` does not provide `{k}` artifact\", dep.name));\n    }\n}","typeGuard":"fn artifact_available(kind: &str, dep_targets: &[TargetKind]) -> bool {\n    dep_targets.iter().any(|t| match (kind, t) {\n        (\"cdylib\", TargetKind::Cdylib) => true,\n        (\"staticlib\", TargetKind::Staticlib) => true,\n        (\"bin\", TargetKind::Bin) => true,\n        _ => false,\n    })\n}\n","tryCatchPattern":null,"preventionTips":["Document which artifact kinds each consumed crate exports.","Pin dependency versions whose targets you rely on.","Add a manifest-lint step in CI that checks artifact declarations."],"tags":["cargo","artifact","dependency","manifest","target"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}