rust-lang/cargo · error · anyhow::Error
'{}' is not a valid artifact specifier
Error message
'{}' is not a valid artifact specifier What it means
ArtifactKind::parse accepts exactly `bin`, `cdylib`, `staticlib`, or `bin:<name>`. Anything else falls through; it tries to strip a `bin:` prefix and, on failure, returns this error. Artifact specifiers appear in a dependency's `artifact = [...]` list (RFC 3452 DEP-cargo-artifacts), selecting which build artifacts to depend on.
Source
Thrown at src/workspace/dependency.rs:654
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 0e07a15537)
Solutions
- Use one of the valid kinds: `bin`, `cdylib`, `staticlib`, or `bin:<binary-name>`.
- For a named binary use the `bin:` prefix: `artifact = ["bin:mybin"]`.
- Remove typos/whitespace and check spelling against the RFC 3452 artifact list.
Example fix
# Cargo.toml before [dependencies.mycrate] artifact = ["dylib"] # after [dependencies.mycrate] artifact = ["cdylib"]
Defensive patterns
Strategy: validation
Validate before calling
fn validate_artifact_kind(kind: &str) -> Result<(), String> {
match kind {
"bin" | "cdylib" | "staticlib" => Ok(()),
k if k.starts_with("bin:") && k.len() > 4 => Ok(()),
other => Err(format!("'{other}' is not a valid artifact specifier; use bin | cdylib | staticlib | bin:<name>")),
}
} Type guard
fn is_valid_artifact_kind(s: &str) -> bool {
matches!(s, "bin" | "cdylib" | "staticlib")
|| (s.starts_with("bin:") && s.len() > 4)
} Try / catch
match ArtifactKind::parse(kind) {
Err(e) if e.to_string().contains("not a valid artifact specifier") => {
eprintln!("use one of: bin, cdylib, staticlib, bin:<name>");
return Err(e);
}
r => r,
} Prevention
- Remember `cdylib`/`staticlib` (not `dylib`/`lib`) and `bin` (not `exe`/`binary`).
- Always prefix named binaries with `bin:`.
- Add a manifest linter (toml schema check) for the `artifact` array.
When it happens
Trigger: Writing a Cargo.toml dependency with an artifact string that is not one of the recognized forms, e.g. `artifact = ['dylib']` (should be `cdylib`), `artifact = ['exe']`, `artifact = ['bin:']` (empty name), or a typo like `artifact = ['bins']`.
Common situations: Typing the artifact kind from memory (e.g. `dylib` instead of `cdylib`, `exe`/`binary` instead of `bin`); forgetting the `bin:` prefix when selecting a named binary (`artifact = ['mybin']`); trailing characters or whitespace.
Related errors
- Cannot specify both 'bin' and 'bin:<name>' binary artifacts,
- dependency `{}` in package `{}` requires a `{}` artifact to
- Deprecated dependency sections are unsupported: {}
- could not compile due to {error_count} previous target resol
- {manifest_key_name} `{}` does not appear to exist{}.
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/d828e9b48c94aa58.json.
Report an issue: GitHub.