Skip to content

msvc: handle /Tc and /Tp as input file arguments - #2904

Merged
sylvestre merged 2 commits into
mozilla:mainfrom
bhaskargurram-ai:msvc-tp-tc-input
Oct 13, 2026
Merged

sylvestre merged 2 commits into
mozilla:mainfrom
bhaskargurram-ai:msvc-tp-tc-input

Conversation

@bhaskargurram-ai

Copy link
Copy Markdown
Contributor

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 cl
tried 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 use
sccache 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 the
preprocess, compile and dist commands. That needed one new
msvc_explicit_language field on ParsedArguments; the other compilers just
set 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.

/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-commenter

codecov-commenter commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.08197% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.32%. Comparing base (027e5ea) to head (5133db5).

Files with missing lines Patch % Lines
src/compiler/msvc.rs 94.59% 6 Missing ⚠️
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.
📢 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 src/compiler/msvc.rs Outdated
multiple_input_files.push(path.clone().into_os_string());
}
input_arg = Some(path.clone().into_os_string());
explicit_language = Some(match arg.get_data() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Comment thread src/compiler/msvc.rs Outdated

// 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
@sylvestre
sylvestre merged commit c879c0d into mozilla:main Oct 13, 2026
48 of 50 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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.

0.7.6 doesn't handle MSVC /Tp option correctly

3 participants