Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to make builds with one job deterministic #5009

Open
gnzlbg opened this issue Feb 4, 2018 · 4 comments
Open

Add a way to make builds with one job deterministic #5009

gnzlbg opened this issue Feb 4, 2018 · 4 comments
Labels
A-build-execution Area: anything dealing with executing the compiler C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 4, 2018

Currently cargo build -j 1 builds crates, that can be built in parallel, in random order:

This is very painful when trying write a cargotest for a complex situation involving multiple crates:

#[cargo_test]
fn deterministic_builds() {
    let p = project()
        .file(
            "a/Cargo.toml",
            r#"
            [package]
            name = "a"
            version = "0.0.1"
            authors = []
        "#,
        )
        .file(
            "a/src/lib.rs",
            r#"
            pub fn a() {}
        "#,
        )
        .file(
            "b/Cargo.toml",
            r#"
            [package]
            name = "b"
            version = "0.0.1"
            authors = []
        "#,
        )
        .file(
            "b/src/lib.rs",
            r#"
            pub fn b() {}
        "#,
        )
        .file(
            "c/Cargo.toml",
            r#"
            [package]
            name = "c"
            version = "0.0.1"
            authors = []
        "#,
        )
        .file(
            "c/src/lib.rs",
            r#"
            pub fn c() {}
        "#,
        )
        .file(
            "d/Cargo.toml",
            r#"
            [package]
            name = "d"
            version = "0.0.1"
            authors = []
        "#,
        )
        .file(
            "d/src/lib.rs",
            r#"
            pub fn d() {}
        "#,
        )
        .file(
            "Cargo.toml",
            r#"
            [package]
            name = "foo"
            version = "0.0.1"
            authors = []

            [dependencies]
            a = { path = "a" }
            b = { path = "b" }
            c = { path = "c" }
            d = { path = "d" }
        "#,
        )
        .file(
            "src/lib.rs",
            r#"
            extern crate a;
            extern crate b;
            extern crate c;
            extern crate d;
            pub use a::a;
            pub use b::b;
            pub use c::c;
            pub use d::d;
        "#,
        )
        .build();

    p.cargo("build")
        .arg("--verbose")
        .arg("-j")
        .arg("1")
        .with_stderr(
            "\
[COMPILING] a v0.0.1 ([CWD]/a)
[RUNNING] `rustc --crate-name a [..]
[COMPILING] b v0.0.1 ([CWD]/b)
[RUNNING] `rustc --crate-name b [..]
[COMPILING] c v0.0.1 ([CWD]/c)
[RUNNING] `rustc --crate-name c [..]
[COMPILING] d v0.0.1 ([CWD]/d)
[RUNNING] `rustc --crate-name d [..]
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
        )
        .run();
}

(this test will pass, 1 every 24 times!).

Maybe... we should even make -j 1 being deterministic be the default... Issues about this have been filled in the past #2607 .

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Feb 5, 2018
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Feb 5, 2018

@alexcrichton could you point me to the places in the code where the jobs are passed to the executor ?

@alexcrichton
Copy link
Member

Most of it's related to this file I believe

@epage
Copy link
Contributor

epage commented Oct 17, 2023

I suspect #11032 fixed this. Can someone confirm?

@epage epage added A-build-execution Area: anything dealing with executing the compiler S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Oct 17, 2023
@weihanglo
Copy link
Member

No. I've updated the test case in the PR description and verified against. It is still not deterministic. DependencyQueue is backed by HashMap so I guess it doesn't really change.

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

4 participants