{"record":{"id":"7306e5a6a3d458ae","repo":"tracel-ai/burn","slug":"failed-to-get-out-dir","errorCode":null,"errorMessage":"Failed to get out dir","messagePattern":"Failed to get out dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tch/build.rs","lineNumber":212,"sourceCode":"                    .pic(true)\n                    .warnings(false)\n                    .flag(\"-std=c++17\")\n                    .files(&[cuda_dependency])\n                    .compile(\"tch\");\n            }\n        };\n    }\n}\n\nfn check_out_dir() -> Option<PathBuf> {\n    let out_dir = env_var_rerun(\"OUT_DIR\").ok()?;\n    let libtorch_dir = PathBuf::from(out_dir).join(\"libtorch\");\n    libtorch_dir.exists().then_some(libtorch_dir)\n}\n\nfn main() {\n    let system_info = SystemInfo::new();\n    let out_dir = env_var_rerun(\"OUT_DIR\").expect(\"Failed to get out dir\");\n\n    let mut gpu_found = false;\n    let found_dir = system_info.is_some();\n    if let Some(system_info) = &system_info {\n        let si_lib = &system_info.libtorch_lib_dir;\n        let use_cuda =\n            si_lib.join(\"libtorch_cuda.so\").exists() || si_lib.join(\"torch_cuda.dll\").exists();\n        let use_hip =\n            si_lib.join(\"libtorch_hip.so\").exists() || si_lib.join(\"torch_hip.dll\").exists();\n\n        system_info.make(use_cuda, use_hip);\n        gpu_found = use_cuda || use_hip;\n    } else {\n        SystemInfo::make_cpu();\n    }\n    let check_file = PathBuf::from(out_dir).join(\"tch_gpu_check.rs\");\n    if gpu_found {\n        fs::write(check_file, \"#[allow(clippy::no_effect)]\\n()\").unwrap();","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tch/build.rs#L194-L230","documentation":"The build script of burn-tch panics when the OUT_DIR environment variable is missing or empty. OUT_DIR is normally set by Cargo for all build scripts, so this failure indicates an abnormal build invocation (e.g. running build.rs manually or with a stripped environment). The directory is needed to place the libtorch wrapper artifacts.","triggerScenarios":"Running `cargo build` for burn-tch with OUT_DIR unset in the environment; invoking the build script directly (e.g. `rustc build.rs`) outside of Cargo; using a build harness that clears env vars.","commonSituations":"Custom CI pipelines that sanitize the environment; sandboxed or restricted build environments; calling build.rs directly to debug; exotic build systems wrapping Cargo without propagating CARGO_* variables.","solutions":["Build through Cargo (`cargo build -p burn-tch`) so OUT_DIR is set automatically","Check that no wrapper or CI script is deleting environment variables before invoking rustc/cargo","If using a custom build runner, set OUT_DIR to a writable directory path before invoking the build script","Verify the CARGO_TARGET_DIR/TARGET layout is writable; recreate with `cargo clean` if corrupted"],"exampleFix":"// before (manual invocation)\nrustc build.rs && ./build\n// after\nenv OUT_DIR=./out cargo build -p burn-tch","handlingStrategy":"validation","validationCode":"if std::env::var(\"OUT_DIR\").is_err() {\n    panic!(\"OUT_DIR not set; build burn-tch via cargo, not directly\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build burn-tch through cargo build/cargo make","Avoid env-sanitizing wrappers (env -i, docker --env-file with missing vars) around builds","Pin a standard CI template that preserves CARGO_* environment variables"],"tags":["build-script","cargo","env-var","burn-tch"],"backgroundTag":"missing-env-var","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}