rust-lang/cargo · error · anyhow::Error

metabuild package `{}` must be specified in `build-dependenc

Error message

metabuild package `{}` must be specified in `build-dependencies`

What it means

Error "metabuild package `{}` must be specified in `build-dependencies`" thrown in rust-lang/cargo.

Source

Thrown at src/workspace/parser/targets.rs:129

                "build-script-{}",
                script_path
                    .file_stem()
                    .and_then(|s| s.to_str())
                    .expect("previously normalized")
            );
            targets.push(Target::custom_build_target(
                &name,
                package_root.join(script_path),
                edition,
            ));
        }
    }
    if let Some(metabuild) = metabuild {
        // Verify names match available build deps.
        let bdeps = normalized_toml.build_dependencies.as_ref();
        for name in &metabuild.0 {
            if !bdeps.map_or(false, |bd| bd.contains_key(name.as_str())) {
                anyhow::bail!(
                    "metabuild package `{}` must be specified in `build-dependencies`",
                    name
                );
            }
        }

        targets.push(Target::metabuild_target(&format!(
            "metabuild-{}",
            package.normalized_name().expect("previously normalized")
        )));
    }

    Ok(targets)
}

#[tracing::instrument(skip_all)]
pub fn normalize_lib(
    original_lib: Option<&TomlLibTarget>,

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Add the metabuild package to `[build-dependencies]` in Cargo.toml so it is available at build time.
  2. Remove the `metabuild` key if the package is not meant to be a metabuild dependency.

When it happens

Trigger: Thrown at src/workspace/parser/targets.rs:129 when the library encounters an invalid state.

Common situations: Occurs when `metabuild` names a package that is not listed in `[build-dependencies]`. Add the metabuild package to `[build-dependencies]` in Cargo.toml.


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/3f1ac8f5f36d8bb2.json. Report an issue: GitHub.