rust-lang/cargo · error
' ' is not a valid artifact specifier
Error message
'{}' is not a valid artifact specifier What it means
ArtifactKind::parse accepts exactly: `bin` (all binaries), `cdylib`, `staticlib`, or `bin:<name>` (a specific binary). Any other artifact kind string yields this error. This parses the `artifact = "..."` / `artifact = [...]` field of a dependency declaration.
Solutions
- Use one of the supported kinds: bin, cdylib, staticlib, or bin:<name>.
- If you need a different library type, build it as a normal dependency without the artifact field.
- Re-read the dependency.artifact docs to confirm supported values.
Example fix
# before (Cargo.toml)
# [dependencies]
# foo = { version = "1", artifact = "dylib" }
# after
# [dependencies]
# foo = { version = "1", artifact = "cdylib" } Defensive patterns
Strategy: validation
Validate before calling
fn parse_artifact_kind(kind: &str) -> Result<(), String> {
let ok = matches!(kind, "bin" | "cdylib" | "staticlib") || kind.starts_with("bin:");
if ok { Ok(()) } else { Err(format!("'{kind}' is not a valid artifact specifier")) }
} Type guard
fn is_valid_artifact_kind(kind: &str) -> bool {
matches!(kind, "bin" | "cdylib" | "staticlib") || kind.starts_with("bin:")
} Prevention
- Restrict artifact kinds to bin, cdylib, staticlib, or bin:<name>.
- Add a manifest lint that rejects unknown artifact values before publish.
- Do not confuse target crate-types (lib, rlib, dylib, proc-macro) with dependency artifact kinds.
When it happens
Trigger: Declaring a dependency with an unsupported artifact kind in Cargo.toml, e.g. `artifact = "lib"`, `artifact = "dylib"`, `artifact = "proc-macro"`.
Common situations: Assuming any crate-type is a valid artifact; typo in the kind; confusing target crate-types with dependency artifact kinds.
Related errors
- Cannot specify both 'bin' and 'bin
- Found duplicate binary artifact
- dependency ( ) specified without providing a local path…
- dependency ( ) specified without providing a local path…
- found build scripts with duplicate file stems, but all…
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/d828e9b48c94aa58.
Report an issue: GitHub.
Appendix: source
Thrown at src/workspace/dependency.rs:648
pub fn as_str(&self) -> Cow<'static, str> {
match *self {
ArtifactKind::SelectedBinary(name) => format!("bin:{}", name.as_str()).into(),
_ => self.crate_type().into(),
}
}
pub fn parse(kind: &str) -> CargoResult<Self> {
Ok(match kind {
"bin" => ArtifactKind::AllBinaries,
"cdylib" => ArtifactKind::Cdylib,
"staticlib" => ArtifactKind::Staticlib,
_ => {
return kind
.strip_prefix("bin:")
.map(|bin_name| ArtifactKind::SelectedBinary(bin_name.into()))
.ok_or_else(|| {
anyhow::anyhow!("'{}' is not a valid artifact specifier", kind)
});
}
})
}
fn validate(kinds: Vec<ArtifactKind>) -> CargoResult<Vec<ArtifactKind>> {
if kinds.iter().any(|k| matches!(k, ArtifactKind::AllBinaries))
&& kinds
.iter()
.any(|k| matches!(k, ArtifactKind::SelectedBinary(_)))
{
anyhow::bail!(
"Cannot specify both 'bin' and 'bin:<name>' binary artifacts, as 'bin' selects all available binaries."
);
}
let mut kinds_without_dupes = kinds.clone();
kinds_without_dupes.sort();
kinds_without_dupes.dedup();View on GitHub (pinned to 98a09e7e7d)