Skip to content

sccache generates incorrect dep-info for Rust project #984

Closed

Description

@Kogia-sima

Description

sccache generates cargo dep-info file for old directory, which might cause needless recompilation when old directory does not exist.

Behavior

  1. Delete sccache cache directory
  2. create two projects which has same dependencies (e.g. app1 and app2)
  3. compile app1
  4. compile app2
  5. delete target directory for app1
  6. compile app2

Now app2 will recompiled every time when I run cargo check or cargo build.

Here is the bash script for reproducing the problem.

#!/bin/bash

set -e

CARGO_INCREMENTAL=0
CACHE_DIR="$(sccache --show-stats |awk 'match($0, /Local disk:\s*"(.*)"/, a) { print a[1] }')"

if [ -d $CACHE_DIR ]; then
    echo "Delete sccache cache directory"
    rm -rI $CACHE_DIR
fi

rm -rf app1 app2

echo "creating projects"
cargo new app1
echo "typenum = \"1.13.0\"" >> ./app1/Cargo.toml

cargo new app2
echo "typenum = \"1.13.0\"" >> ./app2/Cargo.toml

echo "compiling app1..."
cargo check --manifest-path app1/Cargo.toml

echo "compiling app2..."
cargo check --manifest-path app2/Cargo.toml

echo "Delete app1/target/ directory"
rm -rf app1/target/

echo "recompiling app2..."
cargo check --manifest-path app2/Cargo.toml

echo "recompiling app2..."
cargo check --manifest-path app2/Cargo.toml

Output:

Delete sccache scache
rm: remove 1 argument recursively? y
creating projects
     Created binary (application) `app1` package
     Created binary (application) `app2` package
compiling app1...
    Updating crates.io index
   Compiling typenum v1.13.0
    Checking app1 v0.1.0 (/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1)
    Finished dev [unoptimized + debuginfo] target(s) in 6.48s
compiling app2...
    Updating crates.io index
   Compiling typenum v1.13.0
    Checking app2 v0.1.0 (/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app2)
    Finished dev [unoptimized + debuginfo] target(s) in 3.00s
Delete app1/target/ directory
recompiling app2...
    Checking typenum v1.13.0
    Checking app2 v0.1.0 (/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.76s
recompiling app2...
    Checking typenum v1.13.0
    Checking app2 v0.1.0 (/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.76s

I see that app2 and its dependencies will be recompiled every time. I checked the dep-info file in app2 and found that it contains incorrect dep-info

$ cat ./app2/target/debug/deps/typenum-e6184ef06b1b5b02.d
/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/deps/typenum-e6184ef06b1b5b02.rmeta: /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/lib.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/bit.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/int.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/marker_traits.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/operator_aliases.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/private.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/type_operators.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/uint.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/array.rs /home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/op.rs /home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/consts.rs

/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/deps/typenum-e6184ef06b1b5b02.d: /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/lib.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/bit.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/int.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/marker_traits.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/operator_aliases.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/private.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/type_operators.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/uint.rs /home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/array.rs /home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/op.rs /home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/consts.rs

/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/lib.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/bit.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/int.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/marker_traits.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/operator_aliases.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/private.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/type_operators.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/uint.rs:
/home/kogia-sima/.cargo/registry/src/github.com-1ecc6299db9ec823/typenum-1.13.0/src/array.rs:
/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/op.rs:
/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/consts.rs:

# env-dep:TYPENUM_BUILD_CONSTS=/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/consts.rs
# env-dep:TYPENUM_BUILD_OP=/home/kogia-sima/PG/Rust/sccache-incorrect-depinfo/app1/target/debug/build/typenum-14627307ffedbf93/out/op.rs

As you can see it contains dep-info for app1 project. However, since these file does not exist anymore, app2 will be recompiled every time.

Possible solution

It seems that this becomes problem only when some dependencies rely on the file inside target directory. sccache might avoid this issue if it skips proc-macro crates or crates with custom build script.

Environment

Software Version
Operating system Lubuntu 20.04.2 LTS x86_64
Linux kernel 5.4.0-29-generic
cargo 1.51.0 (43b129a20 2021-03-16)
sccache 0.2.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions