rust-lang / rust-lang/cargo

Switching a build script from new style to old style does not fingerprint correctly.

Open
#6,779 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-build-scripts A-rebuild-detection C-bug S-triage
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

If a build script switches from new-style (with rerun-if statements) to old-style (no rerun-if statements), then the fingerprint does not get updated correctly. This means that running cargo build a second time will re-run the script when it should be fresh.

Fixing this is somewhat difficult. The closure in prepare_build_cmd would need to recompute the old-style FingerprintLocal values, but those require access to a Context which is not available.

Below is a demonstration.

#[test]
fn build_script_to_old_style_rebuild() {
    // Changing from new-style to old-style should track freshness properly.
    let p = project()
        .file("src/lib.rs", "")
        .file("build.rs",
            r#"
            fn main() {
                println!("cargo:rerun-if-changed=build.rs");
            }
            "#)
        .build();

    p.cargo("build").run();
    p.cargo("build -v").with_stderr("\
[FRESH] foo [..]
[FINISHED] [..]
").run();
    p.change_file("build.rs", "fn main() {}");
    p.cargo("build -v").with_stderr("\
[COMPILING] foo [..]
[RUNNING] [..]build.rs[..]
[RUNNING] [..]build-script-build[..]
[RUNNING] [..]lib.rs[..]
[FINISHED] [..]
").run();
    // This line is currently bugged and doesn't appear fresh.
    p.cargo("build -v").with_stderr("\
[FRESH] foo [..]
[FINISHED] [..]
").run();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the build_script_to_old_style_rebuild test and reproduce the transition from a build script with rerun-if statements to one without them. Read prepare_build_cmd, FingerprintLocal, and the Context requirement described in the issue. Done means the final cargo build reports [FRESH] rather than rerunning the script and dependent targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.