Skip to content

tests: stop relying on Cargo's target layout to find binaries - #3076

Merged
sylvestre merged 2 commits into
mozilla:mainfrom
loganrosen:loganrosen-tests-cargo-bin-macro
Nov 29, 2026
Merged

sylvestre merged 2 commits into
mozilla:mainfrom
loganrosen:loganrosen-tests-cargo-bin-macro

Conversation

@loganrosen

Copy link
Copy Markdown
Contributor

Fixes #2520.

sccache_rustc used Command::cargo_bin, which can fall back to guessing where the binary is from the test executable's path. That guess breaks once Cargo's build-dir is moved out of target/. It now uses cargo_bin_cmd!, which reads CARGO_BIN_EXE_sccache at compile time, so assert_cmd needs to be at least 2.1.

Running the whole suite with build-dir set turned up a second problem. Tests that run a nested cargo build inherited the outer build-dir, so their intermediates landed in one shared directory outside each test's tempdir, and cache_hit_rate and sccache_cargo failed. The test helpers now pin build-dir to each test's own target dir. sccache doesn't hash CARGO_BUILD_* directly, so these tests' cache keys don't change.

To keep this from regressing, the 1.91 Linux job (ubuntu-24.04 cuda12.8) gets one extra step that runs sccache_rustc, sccache_cargo and cache_hit_rate with CARGO_BUILD_BUILD_DIR="{cargo-cache-home}/build/{workspace-path-hash}". Without these fixes, 1.91 reproduces all of the failures. Newer cargo sets CARGO_BIN_EXE_* at runtime, which hides the cargo_bin part. I tested locally on 1.91 and 1.99.

Command::cargo_bin falls back to walking up from current_exe(), which
breaks when build-dir is moved out of target/. Use cargo_bin_cmd!, which
reads the compile-time CARGO_BIN_EXE_sccache, and require assert_cmd 2.1.

The nested cargo builds in sccache_cargo and cache_hit_rate also inherited
the outer build-dir, so their intermediates landed in one shared directory
outside each test's tempdir. Pin build-dir to each test's target dir.

Fixes mozilla#2520

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.69%. Comparing base (01bf270) to head (f992aab).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/helpers/mod.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3076   +/-   ##
=======================================
  Coverage   80.68%   80.69%           
=======================================
  Files          78       78           
  Lines       48610    48609    -1     
=======================================
+ Hits        39223    39225    +2     
+ Misses       9387     9384    -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/sccache_rustc.rs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@loganrosen
loganrosen requested a review from sylvestre November 28, 2026 22:51
@sylvestre
sylvestre merged commit b49981f into mozilla:main Nov 29, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

@loganrosen
loganrosen deleted the loganrosen-tests-cargo-bin-macro branch November 29, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests rely on deprecated assert_cmd::cargo_bin which will break on future Cargo versions

3 participants