{"record":{"id":"a0b3facfc28564d1","repo":"slint-ui/slint","slug":"failed-to-locate-root-directory-relative-to","errorCode":null,"errorMessage":"Failed to locate root directory, relative to {}","messagePattern":"Failed to locate root directory, relative to (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/cpp/build.rs","lineNumber":13,"sourceCode":"// Copyright © SixtyFPS GmbH <info@slint.dev>\n// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0\n\nuse crate::cbindgen::EnabledFeatures;\nuse std::path::Path;\nmod cbindgen;\n\nfn main() -> Result<(), anyhow::Error> {\n    let manifest_dir = std::env::var_os(\"CARGO_MANIFEST_DIR\").unwrap();\n\n    // Go from $root/api/cpp down to $root\n    let root_dir = Path::new(&manifest_dir).ancestors().nth(2).unwrap_or_else(|| {\n        panic!(\"Failed to locate root directory, relative to {}\", manifest_dir.to_string_lossy())\n    });\n\n    println!(\"cargo:rerun-if-env-changed=SLINT_GENERATED_INCLUDE_DIR\");\n    let output_dir = std::env::var_os(\"SLINT_GENERATED_INCLUDE_DIR\").unwrap_or_else(|| {\n        Path::new(&std::env::var_os(\"OUT_DIR\").unwrap()).join(\"generated_include\").into()\n    });\n    let output_dir = Path::new(&output_dir);\n\n    println!(\"cargo:GENERATED_INCLUDE_DIR={}\", output_dir.display());\n\n    let enabled_features = EnabledFeatures::from_env();\n\n    let dependencies = cbindgen::gen_all(root_dir, output_dir, enabled_features)?;\n    for path in dependencies {\n        println!(\"cargo:rerun-if-changed={}\", path.display());\n    }\n    Ok(())\n}","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/cpp/build.rs#L1-L31","documentation":"api/cpp/build.rs derives the repository root by walking two ancestors up from CARGO_MANIFEST_DIR (api/cpp -> api -> root). The panic fires when that ancestor does not exist, meaning the crate was built from an unexpected directory depth — e.g. the api/cpp sources were vendored or copied somewhere that breaks the assumed layout. It is a build-time sanity guard on directory structure, not a user-facing error.","triggerScenarios":"Thrown at api/cpp/build.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify that CARGO_MANIFEST_DIR points at <root>/api/cpp; if the crate was moved, adjust the ancestors().nth(2) depth to match the new nesting level","Run the build from a normal cargo invocation; overriding CARGO_MANIFEST_DIR to a non-standard path breaks the ancestor walk","Replace the panic with an explicit Path::ancestors search for a directory containing workspace Cargo.toml to make the script location-independent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}