Skip to content

Cache hit still triggers “No such file or directory” on dep-info writes #2462

@knylbyte

Description

@knylbyte

My Docker-based CI (cargo chef + sccache 0.11.0) still fails on cache hits with

error writing dependencies to `/src/target/<rust-target>/release/deps/<crate>.d`: No such file or directory (os error 2)

or

error writing dependencies to `/src/target/release/deps/<crate>.d`: No such file or directory (os error 2)

even though #2076 is closed. The published crate from crates.io still lacks a parent-directory guard before writing the dep-info file.

Environment:

  • sccache 0.11.0 (cargo install --locked sccache --version 0.11.0)
  • cargo-chef 0.1.73
  • rustc 1.90.0 (from rust:1.90.0-trixie docker image)
  • BuildKit (Docker) on ubuntu-24.04 runner
  • sccache cache mounts provided via buildkit-cache-dance (binds /usr/local/cargo/registry, /usr/local/cargo/git, /var/cache/sccache)

Failing step:
cargo chef cook --release --locked --target x86_64-unknown-linux-musl --recipe-path backend-recipe.json

Expected:
Cache hits should succeed without manual directory preparation.

Suggested fix (from: codex-5-high:
Add a directory guard in rewrite() before recreating the dep-info file (src/compiler/rust.rs#L2285-L2289):

if let Some(parent) = dep_info.parent() {
    fs::create_dir_all(parent).with_context(|| {
        format!("Failed to create dep-info directory {}", parent.display())
    })?;
}
let mut file = fs::File::create(&dep_info)
    .context("Failed to recreate dep info file")?;
file.write_all(deps.as_bytes())?;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions