Skip to content

checksum-freshness: does not work with binary embedded files #151090

@osiewicz

Description

@osiewicz

I tried this code with -Zchecksum-freshness enabled on cargo side:

// random_bytes have to be binary. include_bytes!(".gitignore") does not allow one to repro, for instance.
pub static CONTENTS: &[u8] = include_bytes!("../random_bytes.bin");

I expected to see this happen: subsequent builds of the crate with such static to not trigger a rebuild.

Instead, this happened: crate gets rebuilt over and over

Extra bits:
Cargo's rebuild reason states that file length does not match up:

Dirty inner v0.1.0 (/Users/hiro/Projects/build_playground/checksum-freshness/inner): file size changed (0 != 40) for random_bytes.bin

This means that rustc reports such files as having a length of 0, whereas on a subsequent build Cargo compares that 0 with correct length, triggering a rebuild in a process. I believe that this is a rustc bug (and not a cargo bug), as it incorrectly reports the checksum/file length of binary files.

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (2f1bd3f37 2026-01-12)
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions