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

rustPlatform: cargo test is now called with the same environment variables as cargo build #298108

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

lolbinarycat
Copy link
Contributor

@lolbinarycat lolbinarycat commented Mar 22, 2024

this means that cargo dependancies will no longer be built twice.

fixes #291222

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@SuperSandro2000
Copy link
Member

@ofborg build lsd ripgrep

@SuperSandro2000
Copy link
Member

This PR rebuilds a lot of packages which means we must target staging. Please follow the contributing guide to not potentially ping a lot of people.

@lolbinarycat lolbinarycat changed the base branch from master to staging March 23, 2024 17:07
@lolbinarycat
Copy link
Contributor Author

@SuperSandro2000 done.

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with my limited knowledge about the rust ecosystem

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Apr 5, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 10, 2024
Copy link
Member

@bryango bryango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! It may significantly shorten build time of many rust packages... Can this be revived? It seems there are some merge conflicts now, but that probably won't be too difficult to resolve. Friendly ping @alyssais in case you are interested 😆

@bryango bryango requested a review from alyssais October 7, 2024 16:37
…ables as cargo build

this means that cargo dependancies will no longer be built twice.
@SuperSandro2000
Copy link
Member

I've just rebased the PR on staging.

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 8, 2024
@bryango
Copy link
Member

bryango commented Oct 9, 2024

@ofborg build lsd ripgrep

@alyssais alyssais merged commit 683f97e into NixOS:staging Oct 9, 2024
25 of 26 checks passed
@trofi
Copy link
Contributor

trofi commented Oct 10, 2024

Bisect says 683f97e rustPlatform: cargo test is now called with the same environment variables as cargo buil broke rust-cbindgen in staging as:

$ nix build --no-link -f. -L rust-cbindgen
...
rust-cbindgen>      Running tests/profile.rs (target/x86_64-unknown-linux-gnu/release/deps/profile-fec32decafabbade)
rust-cbindgen> running 3 tests
rust-cbindgen> test bin_explicit_release_build ... FAILED
rust-cbindgen> test bin_explicit_debug_build ... FAILED
rust-cbindgen> test bin_default_uses_debug_build ... FAILED
rust-cbindgen> failures:
rust-cbindgen> ---- bin_explicit_release_build stdout ----
rust-cbindgen> thread 'bin_explicit_release_build' panicked at tests/profile.rs:99:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["release", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["release"]
rust-cbindgen> note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
rust-cbindgen> ---- bin_explicit_debug_build stdout ----
rust-cbindgen> thread 'bin_explicit_debug_build' panicked at tests/profile.rs:93:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["debug", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["debug"]
rust-cbindgen> ---- bin_default_uses_debug_build stdout ----
rust-cbindgen> thread 'bin_default_uses_debug_build' panicked at tests/profile.rs:87:5:
rust-cbindgen> assertion `left == right` failed
rust-cbindgen>   left: ["debug", "x86_64-unknown-linux-gnu"]
rust-cbindgen>  right: ["debug"]
rust-cbindgen> failures:
rust-cbindgen>     bin_default_uses_debug_build
rust-cbindgen>     bin_explicit_debug_build
rust-cbindgen>     bin_explicit_release_build
rust-cbindgen> test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 3 filtered out; finished in 0.59s
rust-cbindgen> error: test failed, to rerun pass `--test profile`

@bryango
Copy link
Member

bryango commented Oct 11, 2024

Ah that's not good... I think it's due to the additional CARGO_BUILD_TARGET variable:

nix-repl> :p pkgs.rust.envVars.setEnv
env \
"CC_X86_64_UNKNOWN_LINUX_GNU=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/cc" \
"CXX_X86_64_UNKNOWN_LINUX_GNU=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/c++" \
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/cc" \
"CC_X86_64_UNKNOWN_LINUX_GNU=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/cc" \
"CXX_X86_64_UNKNOWN_LINUX_GNU=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/c++" \
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/cc" \
"CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu" \
"HOST_CC=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/cc" \
"HOST_CXX=/nix/store/zznja5f8v3jafffyah1rk46vpfcn38dv-gcc-wrapper-13.3.0/bin/c++" \

The failing cbindgen/tests/profile.rs is here: https://github.com/mozilla/cbindgen/blob/master/tests/profile.rs. I will try to look into this.

Bisect says 683f97e rustPlatform: cargo test is now called with the same environment variables as cargo buil broke rust-cbindgen in staging

Also, just out of curiosity: how do you know about staging breakages so fast? Is there any hydra instance currently running on it?

@trofi
Copy link
Contributor

trofi commented Oct 11, 2024

Bisect says 683f97e rustPlatform: cargo test is now called with the same environment variables as cargo buil broke rust-cbindgen in staging

Also, just out of curiosity: how do you know about staging breakages so fast? Is there an hydra instance currently running on it?

No hydra I'm aware of. I occasionally try to build my local system against staging to catch early regressions and to test local changes.

@bryango
Copy link
Member

bryango commented Oct 11, 2024

Ok, so indeed the culprit is CARGO_BUILD_TARGET, which changes the layout of the output directory. This is documented here: https://doc.rust-lang.org/cargo/guide/build-cache.html

@SuperSandro2000
Copy link
Member

Can we just filter that one variable out?

@bryango
Copy link
Member

bryango commented Oct 11, 2024

Can we just filter that one variable out?

This would probably diminish the benefits of this PR, namely cargo test might fail to locate the cache from a previous build (which is in the CARGO_BUILD_TARGET subdirectory).

@alyssais
Copy link
Member

We could send upstream a patch to unset that variable in the test. Alternatively we could just skip the test if it's not suitable for our setup.

@lolbinarycat
Copy link
Contributor Author

alternatively, if it's just rustgm-cbindgen, we could unset that variable in that specific package (in a pre-test hook)

this would mean specifically that package would be built twice, but that's a lot better than double building every single package.

still probably better to just skip the check phase for it and notify upstream.

@bryango
Copy link
Member

bryango commented Oct 11, 2024

I have sent a patch upstream:

and they have already responded kindly. A downstream nixpkgs PR #348031 is also created, as shown below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

buildRustPackage has excessive dependency rebuilds in checkPhase for unclear reasons
6 participants