Skip to content

Spurious rebuilds due to filesystem rounding file modification timestamps #12060

@kornelski

Description

@kornelski

Problem

The issue #2874 was not completely fixed by #2880. I'm still seeing the exact same problem in latest Cargo:

Dirty libc v0.2.142: the dependency build_script_build was rebuilt (1682215868.647155753s, 647155753ns after last build at 1682215868.000000000s)
Dirty openssl-sys v0.9.86: the dependency build_script_main was rebuilt (1682214777.891768399s, 891768399ns after last build at 1682214777.000000000s)

Steps

I'm using Docker and mounting target/ dir as a Docker volume (in order to cache it). I think the docker volume rounds the timestamps to 1-second precision. However, this doesn't always cause spurious rebuilds, only maybe 25% of the time, and it's always build_script_build or build_script_main, not other files.

Possible Solution(s)

I assume Cargo wouldn't want to introduce imprecision in comparison, such as always comparing the integer number of seconds or allowing 1-second difference between timestamps. Therefore, I propose detecting this problem explicitly: there's only one in a billion chance that the nanosecond part will be exactly 0. So if either of the timestamps being compared has exactly 0 nanosecond part, compare only the integer number of seconds. Otherwise compare in full precision. I can make a PR with that.

Notes

No response

Version

cargo 1.71.0-nightly (d0a4cbcee 2023-04-16)
release: 1.71.0-nightly
commit-hash: d0a4cbcee614fdb7ba66e860e603a00a644d71f8
commit-date: 2023-04-16
host: aarch64-apple-darwin
libgit2: 1.6.3 (sys:0.17.0 vendored)
libcurl: 7.88.1 (sys:0.4.61+curl-8.0.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1t  7 Feb 2023
os: Mac OS 13.4.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesystemArea: issues with filesystemsA-rebuild-detectionArea: rebuild detection and fingerprintingC-bugCategory: bugS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions