AlexsJones/llmfit · info
OUT_DIR
Error message
OUT_DIR
What it means
The same build.rs reads OUT_DIR (the scratch directory cargo creates per compiled crate) to know where to write the generated web_assets.rs that embeds the dashboard. Cargo guarantees OUT_DIR for build script execution, so this .expect, like the CARGO_MANIFEST_DIR one, only fires when build.rs runs outside the cargo build environment.
Source
Thrown at llmfit-tui/build.rs:12
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."
);
generate_fallback_assets()
};
fs::write(&out_file, generated).expect("failed to write generated web_assets.rs");View on GitHub (pinned to acc7e40c3a)
Solutions
- Build via cargo: `cargo build -p llmfit` — OUT_DIR is provided automatically
- For manual runs, set both CARGO_MANIFEST_DIR and OUT_DIR to writable directories (e.g. under /tmp) before executing the script
- If you need the generated file for inspection, look under target/debug/build/llmfit-*/out/web_assets.rs after a cargo build instead
Example fix
# before ./target/debug/build/llmfit-*/build-script-main # panics: OUT_DIR # after cargo build -p llmfit cat target/debug/build/llmfit-*/out/web_assets.rs
Defensive patterns
Strategy: validation
Validate before calling
// Only relevant if executing build.rs outside cargo:
let out_dir = std::env::var("OUT_DIR")
.expect("run me via `cargo build`, or export OUT_DIR to a writable dir");
assert!(std::path::Path::new(&out_dir).is_dir(), "OUT_DIR must exist and be writable"); Prevention
- Never execute the compiled build script manually without the cargo environment
- Inspect generated assets under target/debug/build/llmfit-*/out/ after a normal cargo build
- Keep wrappers that invoke build.rs from re-implementing cargo's env half-way
When it happens
Trigger: Directly invoking the compiled build script (`./libllmfit_build-script.out`) without env; a debugging harness that runs build.rs with a partially copied environment; cargo-external integration that forgets OUT_DIR.
Common situations: Build-script debugging sessions; custom build pipelines that try to pre-generate web_assets.rs by hand.
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
- CARGO_MANIFEST_DIR
- failed to write generated web_assets.rs
- invalid dir entry
- valid MLX suffix regex
- Binary not found at {bin_path}. Expected it to be built for
AI-assisted analysis of AlexsJones/llmfit@acc7e40c3a (2026-08-17).
Data as JSON: /api/errors/9af5f4b7657587de.
Report an issue: GitHub.