Repository navigation
msvc: handle /Tc and /Tp as input file arguments - #2904
Merged
Merged
Conversation
/Tc and /Tp take the source file as their operand, either joined (/Tpfoo.cc) or as the next argument (-Tp foo.cc). sccache treated the joined form as an input path and the separated form as an unknown flag followed by the input, so the rebuilt preprocessor command ended up as `-Tp /WX- foo.cc` and cl.exe failed. Parse them as the input file, take the language from the flag, and put the flag back in front of the input when building the preprocess, compile and dist commands. Fixes mozilla#2062
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2904 +/- ##
==========================================
+ Coverage 78.24% 78.32% +0.08%
==========================================
Files 72 72
Lines 42123 42241 +118
==========================================
+ Hits 32959 33087 +128
+ Misses 9164 9154 -10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sylvestre
reviewed
Oct 13, 2026
| multiple_input_files.push(path.clone().into_os_string()); | ||
| } | ||
| input_arg = Some(path.clone().into_os_string()); | ||
| explicit_language = Some(match arg.get_data() { |
Collaborator
There was a problem hiding this comment.
matching arg.get_data() again inside the arm is a bit odd
could you please use two arms, or set the language in a separate match?
sylvestre
reviewed
Oct 13, 2026
|
|
||
| // An input given with /Tc or /Tp has to keep the flag attached, otherwise | ||
| // cl.exe falls back to guessing the language from the extension. | ||
| fn input_arg(parsed_args: &ParsedArguments, input: &OsStr) -> OsString { |
Collaborator
There was a problem hiding this comment.
input_arg is also the name of a local variable in parse_arguments, a bit confusing
maybe msvc_input_arg?
Review follow-up: the input arm no longer re-matches arg.get_data(); the language is set alongside the other per-argument handling. The helper that rebuilds the input argument is now msvc_input_arg, so it no longer shares a name with the input_arg local in parse_arguments.
Collaborator
|
Thanks for your PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2062.
/Tc and /Tp take the source file as their operand, either joined (/Tpfoo.cc,
which is what setuptools/distutils passes) or separated (-Tp foo.cc). sccache
didn't know about them: the joined form was taken as an input path that doesn't
exist, and the separated form became an unknown flag plus the input. In the
separated case the preprocessor command came out as
-Tp /WX- foo.cc, so cltried to open /WX- and failed with C1083. Since cc 1.5 (rust-lang/cc-rs#1930)
passes
-Tp <file>for .cc sources, this now breaks Rust builds that usesccache on Windows, and some projects pin cc to 1.4 to work around it.
I now parse /Tc and /Tp as the input file, set the language from the flag
(C or C++), and emit the flag attached to the input (
-Tpfoo.cc) in thepreprocess, compile and dist commands. That needed one new
msvc_explicit_languagefield on ParsedArguments; the other compilers justset it to false.
Added unit tests for the joined and separated forms of both flags, plus the
rebuilt preprocess/compile/dist command lines. I haven't run it against a
real cl.exe, only the unit tests.