Skip to content

Conversation

@avikivity
Copy link
Contributor

On Linux, ccache is typically installed in $PATH as /usr/lib64/ccache/g++ or similar. If we keep it there, all compilations will be cached by both ccache and sccache.

While the user could easily disable ccache with CCACHE_DISABLE, it's reasonable to assume many will forget and will have their disk space doubly consumed by both caches. Better to recognize this and disable ccache under sccache.

This patch does this by removing the ccache binary paths from $PATH.

Fixes #2519

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.14%. Comparing base (2b92721) to head (ce9f95b).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2524      +/-   ##
==========================================
- Coverage   71.24%   71.14%   -0.10%     
==========================================
  Files          64       65       +1     
  Lines       35593    35833     +240     
==========================================
+ Hits        25357    25495     +138     
- Misses      10236    10338     +102     

☔ View full report in Codecov by Sentry.
📢 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.

@avikivity
Copy link
Contributor Author

update: fix rustfmt error

@avikivity
Copy link
Contributor Author

@sylvestre please review

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 10, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 5.29%

Comparing avikivity:disable-ccache (ce9f95b) with main (82bfa28)

Summary

❌ 1 regressed benchmark
✅ 53 untouched benchmarks
⏩ 2 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation time_macro_finder_chunked 971.9 µs 1,026.1 µs -5.29%

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sylvestre sylvestre force-pushed the disable-ccache branch 2 times, most recently from 1fe7bb9 to 4bb5579 Compare January 13, 2026 15:33
@avikivity
Copy link
Contributor Author

@sylvestre can I help in any way to push this along?

src/util.rs Outdated
use std::env;
use std::path::Path;

const CCACHE_DIRS: &[&str] = &["/usr/lib/ccache", "/usr/lib64/ccache"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CCACHE_DIRS list only contains Linux paths. Consider adding macOS Homebrew paths (/usr/local/opt/ccache/libexec, /opt/homebrew/opt/ccache/libexec) or adding a comment explaining why they're omitted

Copy link
Collaborator

Choose a reason for hiding this comment

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

also, it would be nice to be able to configure things somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can generalize it to any path that contains a component ccache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About configuration, is it still needed if we just filter out directories with ccache components?

/// This prevents double-caching when ccache is installed and has
/// /usr/lib/ccache or /usr/lib64/ccache in PATH, since those directories
/// contain wrapper scripts that would call ccache.
pub fn filter_ccache_from_path(env_vars: Vec<(OsString, OsString)>) -> Vec<(OsString, OsString)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function allocates a new Vec even when no ccache dirs are present in PATH. Consider short-circuiting to return the input Vec unchanged when filtering is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

} = self;
// Filter out ccache directories from PATH to avoid double-caching
// when ccache is also installed on the system.
let env_vars = filter_ccache_from_path(env_vars.to_vec());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Filter is only applied to SingleCompileCommand but NvccCompileCommand (in nvcc.rs) also implements CompileCommandImpl and may need the same treatment it is intentional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not intentional, I'll take a look.

@sylvestre
Copy link
Collaborator

sorry for the latency

@avikivity
Copy link
Contributor Author

v2:

  • filter out any directory with a ccache component, so it also works on MacOS
  • avoid allocations if no ccache directories are present
  • apply to detect_c_compiler
  • apply to nvcc

@avikivity
Copy link
Contributor Author

v3:

  • apply rustfmt

On Linux, ccache is typically installed in $PATH as /usr/lib64/ccache/g++
or similar. If we keep it there, all compilations will be cached by both
ccache and sccache.

While the user could easily disable ccache with CCACHE_DISABLE, it's
reasonable to assume many will forget and will have their disk space
doubly consumed by both caches. Better to recognize this and disable
ccache under sccache.

This patch does this by removing the ccache binary paths from $PATH.
The check is fuzzy - any directory that has a `ccache` component is
removed. It's assumed that people won't have directories with such
names in $PATH that are not ccache masquarade directories.

Fixes mozilla#2519
@avikivity
Copy link
Contributor Author

v4:

  • use slice instead of Vec

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.

Unwanted double-caching when ccache is also installed

3 participants