BoundaryML/baml · error
cargo build failed for {package}
Error message
cargo build failed for {package} What it means
run_cargo_build runs `cargo build` for a package (e.g. the CLI) and checks the exit status; a non-zero status aborts with this message. The underlying compiler errors are printed by cargo itself to stderr before this bail.
Source
Thrown at baml_language/crates/tools_size_gate/src/measure.rs:81
cmd.arg("--features").arg(feat);
}
cmd.args(extra);
cmd.current_dir(workspace_root);
eprintln!(
" building {} ({})",
package,
if config.no_default_features {
"no-default-features"
} else {
"default features"
}
);
let status = cmd.status().context("failed to run cargo build")?;
if !status.success() {
bail!("cargo build failed for {package}");
}
Ok(())
}
/// 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])View on GitHub (pinned to bd85ce9dee)
Solutions
- Read the cargo compiler output printed above this message
- Run `cargo build -p <package>` manually in the workspace root to reproduce
- Fix the compile errors or restore a working tree (git stash/checkout)
- Confirm the package and features configured for the artifact exist
Example fix
// before: broken package name in artifact config packages = ["baml-cl”] // after cargo build -p baml-cli # verify name via workspace Cargo.toml members
Defensive patterns
Strategy: try-catch
Validate before calling
let status = std::process::Command::new("cargo")
.args(["build", "-p", "baml-cli"])
.status()?;
if !status.success() { eprintln!("preflight build failed; fix compile errors before measuring"); std::process::exit(1); } Try / catch
match size_gate_result {
Err(e) if e.to_string().starts_with("cargo build failed") => {
eprintln!("workspace does not compile; run `cargo build` and fix errors first");
}
other => other?,
} Prevention
- Run `cargo build --workspace` locally before invoking size-gate
- Only measure on a clean, compiling tree (CI on green commits)
- Keep package names/features in the size-gate config in sync with Cargo.toml
- Avoid vendored/offline cargo config surprises in CI
When it happens
Trigger: Any `cargo build -p <package>` failure during size-gate measure: compile errors, missing feature flags, failing build scripts, or dependency resolution errors for that package.
Common situations: Workspace code broken mid-refactor; package name typo in the size-gate config; required feature set unavailable for the target; vendored/offline dependency issues.
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
- cargo metadata failed
- cargo build failed for pack ({} + {})
- cargo metadata failed
- packed artifact not found (expected at {})
- artifact not found: {} (expected at {})
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/b27a99052da8f77d.
Report an issue: GitHub.