AlexsJones/llmfit · info

CARGO_MANIFEST_DIR

Error message

CARGO_MANIFEST_DIR

What it means

llmfit-tui/build.rs reads CARGO_MANIFEST_DIR to locate ../llmfit-web/dist and emit rerun-if-changed directives. Cargo always defines this variable when it compiles a build script, so the .expect can only fail when build.rs is executed outside Cargo (e.g. directly with rustc, or by a tool that mimics cargo poorly). It is an environment-contract assertion, not a normal failure mode.

Source

Thrown at llmfit-tui/build.rs:8

use std::env;
use std::fs;
use std::path::{Path, PathBuf};

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
    let dist_dir = manifest_dir.join("..").join("llmfit-web").join("dist");
    println!("cargo:rerun-if-changed={}", dist_dir.display());

    let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR"));
    let out_file = out_dir.join("web_assets.rs");

    let generated = if dist_dir.exists() {
        let mut files = Vec::new();
        collect_files(&dist_dir, &mut files);
        files.sort();
        for file in &files {
            println!("cargo:rerun-if-changed={}", file.display());
        }
        generate_assets_from_dist(&dist_dir, &files)
    } else {
        println!(
            "cargo:warning=llmfit-web/dist not found. Falling back to placeholder embedded dashboard. Run `npm ci && npm run build` in llmfit-web."
        );

View on GitHub (pinned to acc7e40c3a)

Solutions

  1. Run the build through cargo: `cargo build -p llmfit` (or `cargo check`) so CARGO_MANIFEST_DIR, OUT_DIR, and friends are set
  2. If you must execute build.rs standalone, export CARGO_MANIFEST_DIR=/path/to/llmfit-tui and OUT_DIR to a temp dir first
  3. Prefer `cargo build -vv` to debug build-script behavior rather than running it outside cargo

Example fix

# before
rustc llmfit-tui/build.rs && ./a.out  # panics: CARGO_MANIFEST_DIR

# after
cargo check -p llmfit  # cargo sets CARGO_MANIFEST_DIR/OUT_DIR
Defensive patterns

Strategy: validation

Validate before calling

// Only relevant if executing build.rs outside cargo:
std::env::var("CARGO_MANIFEST_DIR")
    .expect("run me via `cargo build`, or export CARGO_MANIFEST_DIR manually");

Prevention

When it happens

Trigger: Running `rustc build.rs` manually to debug the build script; invoking build.rs from an IDE task or script that does not set the cargo-provided environment; a nonstandard build wrapper that strips env.

Common situations: Developers experimenting with the build script in isolation; external tooling (Bazel-ish wrappers, codegen scripts) executing build.rs without the cargo contract.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of AlexsJones/llmfit@acc7e40c3a (2026-08-17). Data as JSON: /api/errors/8d75507f591a1a87. Report an issue: GitHub.