BoundaryML/baml · error

cargo build failed for pack

Error message

cargo build failed for pack ({} + {})

What it means

build_pack builds both the pack's CLI binary and host binary with a single `cargo build -p <cli_package> --bin <cli_bin> -p <host_package> --bin <host_bin>` invocation. If cargo exits non-zero, it bails naming both packages. Cargo's own diagnostics are already on stderr.

Solutions

  1. Read cargo's error output above the message to see which of the two targets failed
  2. Build each target manually: cargo build -p <cli_package> --bin <cli_bin>, then the host
  3. Verify package/bin names in the pack config match Cargo.toml
  4. Fix the compile errors or test on a clean checkout

Example fix

// before: bin renamed in Cargo.toml but not in config
cli_bin = "baml-old"
// after
cli_bin = "baml"
Defensive patterns

Strategy: try-catch

Validate before calling

let status = std::process::Command::new("cargo")
    .args(["build", "-p", cli_pkg, "--bin", cli_bin, "-p", host_pkg, "--bin", host_bin])
    .status()?;
if !status.success() { eprintln!("pack targets do not build; check bin/package names"); std::process::exit(1); }

Try / catch

if let Err(e) = measure() {
    if e.to_string().contains("cargo build failed for pack") {
        eprintln!("build the two pack targets manually to see which failed");
    }
    return Err(e);
}

Prevention

When it happens

Trigger: Failure building either the CLI or host package/bin pair defined in the PackConfig during size-gate measure: compile errors in either crate, missing bins, or broken build scripts.

Common situations: Renamed bin or package targets in Cargo.toml without updating the pack config; compile errors introduced on the branch under test; host crate requiring a feature only available on certain platforms.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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

Appendix: source

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

/// Build the CLI + pack host, then run `baml pack` on the fixture and
/// return the path to the produced standalone executable.
fn build_pack(workspace_root: &Path, name: &str, config: &ArtifactConfig) -> Result<PathBuf> {
    let pack = config.require_pack()?;

    // Build the CLI and the pack host in one release invocation. The host
    // binary must land next to the CLI in target/release so `baml pack`
    // resolves it locally (no GitHub download).
    eprintln!("  building {} + {}", pack.cli_package, pack.host_package);
    let status = Command::new("cargo")
        .arg("build")
        .arg("--release")
        .args(["-p", &pack.cli_package, "--bin", &pack.cli_bin])
        .args(["-p", &pack.host_package, "--bin", &pack.host_bin])
        .current_dir(workspace_root)
        .status()
        .context("failed to run cargo build for pack")?;
    if !status.success() {
        bail!(
            "cargo build failed for pack ({} + {})",
            pack.cli_package,
            pack.host_package
        );
    }

    run_baml_pack(workspace_root, name, pack)
}

/// Run the freshly built CLI's `baml pack` on the fixture, writing the
/// output to a deterministic path under `target/size-gate/`.
fn run_baml_pack(workspace_root: &Path, name: &str, pack: &PackConfig) -> Result<PathBuf> {
    let cli_path = workspace_root
        .join("target/release")
        .join(exe_filename(&pack.cli_bin));
    if !cli_path.exists() {
        bail!("pack CLI not found at {}", cli_path.display());
    }

View on GitHub (pinned to bd85ce9dee)