rust-lang/cargo · error
dependency `{}` in package `{}` requires a `{}` artifact to
Error message
dependency `{}` in package `{}` requires a `{}` artifact to be present. What it means
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.
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 0e07a15537)
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.
Example fix
// before (parent Cargo.toml)
[dependencies]
foo = { version = "1", artifact = ["cdylib"] }
// foo has no cdylib target -> error
// after
[dependencies]
foo = { version = "1", artifact = ["staticlib"] } // foo provides staticlib Defensive patterns
Strategy: validation
Validate before calling
// Before publishing/consuming, verify dep ships requested artifact kind
let needed: &[&str] = artifact_kinds_for(dep);
let provided: Vec<&str> = dep_targets.iter()
.filter_map(|t| match t.kind {
TargetKind::Cdylib => Some("cdylib"),
TargetKind::Staticlib => Some("staticlib"),
TargetKind::Bin => Some("bin"),
_ => None,
}).collect();
for k in needed {
if !provided.iter().any(|p| p == k) {
return Err(format!("dep `{}` does not provide `{k}` artifact", dep.name));
}
} Type guard
fn artifact_available(kind: &str, dep_targets: &[TargetKind]) -> bool {
dep_targets.iter().any(|t| match (kind, t) {
("cdylib", TargetKind::Cdylib) => true,
("staticlib", TargetKind::Staticlib) => true,
("bin", TargetKind::Bin) => true,
_ => false,
})
}
Prevention
- 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.
When it happens
Trigger: 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"]`).
Common situations: 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.
Related errors
- '{}' is not a valid artifact specifier
- Cannot specify both 'bin' and 'bin:<name>' binary artifacts,
- patch `{}` version mismatch note: patch location contains {}
- single file packages cannot be used as dependencies
- failed to parse the version requirement `{}` for dependency
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/ecb2c1b2ffd4aec5.json.
Report an issue: GitHub.