clockworklabs/SpacetimeDB · error

Failed to canonicalize manifest_dir path {}: {err:#?}

Error message

Failed to canonicalize manifest_dir path {}: {err:#?}

What it means

Build-time panic in crates/cli/build.rs during the Nix-build path (`list_all_files`): `manifest_dir.canonicalize()` failed, i.e. the crates/cli directory recorded in CARGO_MANIFEST_DIR could not be resolved to a real absolute path. Canonicalization fails when the path does not exist, a path component is a dangling symlink, or permissions forbid traversal — an abnormal state for the crate cargo is currently building.

Source

Thrown at crates/cli/build.rs:322

    code.push_str(&format!("        templates.insert(\"{}\", files);\n", source));
    code.push_str("    }\n\n");
}

/// Get a list of files tracked by git from a given directory
fn get_git_tracked_files(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
    if is_nix_build() {
        // When building in Nix, we already know that there are no untracked files in our source tree,
        // so we just list all of the files.
        list_all_files(path, manifest_dir)
    } else {
        // When building outside of Nix, we invoke `git` to list all the tracked files.
        get_git_tracked_files_via_cli(path, manifest_dir)
    }
}

fn list_all_files(path: &Path, manifest_dir: &Path) -> (Vec<PathBuf>, PathBuf) {
    let manifest_dir = manifest_dir.canonicalize().unwrap_or_else(|err| {
        panic!(
            "Failed to canonicalize manifest_dir path {}: {err:#?}",
            manifest_dir.display()
        )
    });

    let template_root_absolute = get_full_path_within_manifest_dir(path, &manifest_dir);

    let repo_root = get_repo_root();

    let mut files = Vec::new();
    ls_recursively(&template_root_absolute, &repo_root, &mut files);

    (files, make_repo_root_relative(&template_root_absolute, &repo_root))
}

/// Get all the paths of files within `root_dir`,
/// transform them into paths relative to `repo_root`,
/// and insert them into `out`.

View on GitHub (pinned to 6dee26c6ef)

Solutions

  1. Verify the path exists from the failing environment: `ls "$CARGO_MANIFEST_DIR"` and `readlink -f` each component to find the dangling symlink.
  2. Do a clean build (`cargo clean` or a fresh Nix store source) to eliminate a half-deleted target/checkout.
  3. If a wrapper sets CARGO_MANIFEST_DIR manually, remove that override and let cargo provide it.
  4. Check permissions on every path component (execute bit) for the build user.
Defensive patterns

Strategy: validation

Validate before calling

# Before building: every component of the manifest dir must resolve.
path="$CARGO_MANIFEST_DIR"
while [ "$path" != "/" ]; do
  [ -e "$path" ] || { echo "missing component: $path"; exit 1; }
  path=$(dirname "$path")
done

Prevention

When it happens

Trigger: Running a Nix build where the source was garbage-collected or moved mid-build; a sandboxed builder that replaces directories with symlinks pointing outside the sandbox; stale CARGO_MANIFEST_DIR inherited from a previous build in a deleted target dir.

Common situations: Incremental builds after the checkout was relocated; Nix sandboxing oddities with bind-mounted paths; concurrently running two cargo invocations where one cleans the tree.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/29ecdc84a3835ee5. Report an issue: GitHub.