Repository navigation
Use response files when spawning rustc commands when needed - #2789
ranger-ross wants to merge 1 commit into
Conversation
| // On Windows there is a hard limit of ~32KB, so we cut off at 30KB to | ||
| // give some buffer just incase. | ||
| #[cfg(windows)] | ||
| let threshold: usize = 30 * 1024; | ||
| // On unix the limit is defined by ARG_MAX. If its not explicitly set we set it to 1MB | ||
| // which is fairly large but lower than the ~2MB that it defaults to on most systems. | ||
| #[cfg(unix)] | ||
| let threshold: usize = std::env::var("ARG_MAX") | ||
| .ok() | ||
| .and_then(|v| v.parse().ok()) | ||
| .unwrap_or(1024 * 1024); |
There was a problem hiding this comment.
There was a problem hiding this comment.
Besides ARG_MAX, this might fail if a single argument in the list exceeds MAX_ARG_STRLEN, which is 32 page sizes (128kb on most systems). This is a real issue (#2815) and I can confirm that lowering this threshold to 128kb solves it.
Even though setting a defensive limit solves the problem (32kb would cover both Windows and a single arg problem), it needs at least a comment explanation or a separate single-argument threshold to make it more transparent and less fragile to future changes.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2789 +/- ##
==========================================
- Coverage 78.81% 78.80% -0.01%
==========================================
Files 75 75
Lines 45354 45399 +45
==========================================
+ Hits 35745 35777 +32
- Misses 9609 9622 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CI failures should be unrelated to this change. |
c24a906 to
e02a9e9
Compare
|
@sylvestre friendly bump on this PR :) I'd be nice to get this PR merged before we stabilize the new Cargo build-dir layout. (which we are planning to do in the next beta branch) |
|
this PR also fixes #2815 |
|
+1 for getting this merged. It most likely fixes a regression for us on Windows CI: #2397 (comment) |
e02a9e9 to
0d7d7e1
Compare
|
sorry but it needs to be rebased |
| } | ||
| } | ||
|
|
||
| fn maybe_write_response_file( |
There was a problem hiding this comment.
please add a unit test for maybe_write_response_file: below and above the threshold, and check the content of the written file
| // On unix the limit is defined by ARG_MAX. If its not explicitly set we set it to 1MB | ||
| // which is fairly large but lower than the ~2MB that it defaults to on most systems. | ||
| #[cfg(unix)] | ||
| let threshold: usize = std::env::var("ARG_MAX") |
There was a problem hiding this comment.
ARG_MAX isn't normally an env var, it's a sysconf value.
could it be SCCACHE_ARG_MAX (and documented), or read from sysconf?
| let line = arg | ||
| .to_str() | ||
| .ok_or_else(|| anyhow!("rustc argument not valid UTF-8: {:?}", arg))?; | ||
| writeln!(rsp_file, "{}", line).context("Failed to write response file")?; |
There was a problem hiding this comment.
rustc takes one arg per line, so an arg containing a newline would be split in two.
should we error out (or skip the rsp file) in that case?
|
thanks for tackling this! |
|
as far as I can tell, #3026 makes this PR unneeded. Gonna close this |
This is a follow up on #2782.
Unfortunately, I overlooked the fact that sccache modifies the args and does not pass the exact args to rustc that it receives.
This leads to the expanded args getting passed to rustc which blows up on windows when the command is large enough.
The solution is to have sccache create its own arg file (when needed) to pass the args to rustc.
fixes #2787
(I tested the repo in question and it fails without these changes and builds successfully with them)