BoundaryML/baml · error

package '{package_name}' not found in cargo metadata

Error message

package '{package_name}' not found in cargo metadata

What it means

resolve_lib_name searches cargo metadata packages for the given package name to derive the native library filename. When no package with that name exists in the workspace metadata it cannot even apply the hyphen-to-underscore fallback, so it bails with this message.

Source

Thrown at baml_language/crates/tools_size_gate/src/measure.rs:273

            if let Some(targets) = pkg["targets"].as_array() {
                for target in targets {
                    let kinds = target["kind"].as_array();
                    let is_cdylib = kinds
                        .map(|k| k.iter().any(|v| v.as_str() == Some("cdylib")))
                        .unwrap_or(false);
                    if is_cdylib {
                        if let Some(name) = target["name"].as_str() {
                            return Ok(name.to_owned());
                        }
                    }
                }
            }
            // Fallback: use package name with hyphens replaced
            return Ok(package_name.replace('-', "_"));
        }
    }

    bail!("package '{package_name}' not found in cargo metadata");
}

/// Platform-specific dynamic library filename.
fn native_lib_filename(lib_name: &str) -> String {
    if cfg!(target_os = "macos") {
        format!("lib{lib_name}.dylib")
    } else if cfg!(target_os = "windows") {
        format!("{lib_name}.dll")
    } else {
        format!("lib{lib_name}.so")
    }
}

/// Measure a built artifact. When `strip` is false (WASM and `pack`
/// outputs) the file is measured as-is; otherwise it is stripped to a
/// temp copy first and the stripped size is recorded.
pub(crate) fn measure_artifact(artifact_path: &Path, strip: bool) -> Result<ArtifactMeasurement> {
    let file_bytes = std::fs::metadata(artifact_path)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Check `cargo metadata --no-deps | jq '.packages[].name'` for the exact package name and correct the gate config.
  2. If the crate was renamed, update both Cargo.toml references and the size-gate artifact config.
  3. Ensure you run the gate in the workspace that actually contains the package.
  4. Verify the name isn't confused with the lib target name (package name vs [lib] name can differ).

Example fix

// before\nname = "baml-core-wrong"\n// after: must match a [package] name in the workspace\nname = "baml-core"
Defensive patterns

Strategy: validation

Validate before calling

let names: Vec<String> = serde_json::from_slice::<serde_json::Value>(&metadata_stdout)?["packages"]\n    .as_array().unwrap().iter()\n    .filter_map(|p| p["name"].as_str().map(String::from)).collect();\nassert!(names.contains("baml-core"), "package missing from workspace metadata");

Prevention

When it happens

Trigger: locate_artifact is asked for a library artifact whose configured name does not correspond to any [package] name in the workspace's cargo metadata.

Common situations: Renaming a crate in Cargo.toml without updating size-gate config; adding a new crate but forgetting to register it in the artifact config; running the gate from a different workspace that doesn't contain the crate; typo in the package name.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/be35477ef9d08235. Report an issue: GitHub.