Skip to content

When running msbuild with /Zf it breaks the compile with incorrect message "multiple input files detected" (even when using /Z7) #2662

Closed

Description

@DillonSadofsky

I had a special .props file I passed in for just CI/CD builds that would attempt to suppress PCH building, set MultiProcessorCompilation to false, and set <DebugInformationFormat>OldStyle</DebugInformationFormat> (/Z7). However, I couldn't shake that it would say everything was uncacheable due to multiple input files detected. I did verbose output and could see this was not true.

I had a hunch this was due to argument parsing since looking at historical issues this has happened a couple of times. I ended up narrowing it down to /Zf. According to https://learn.microsoft.com/en-us/cpp/build/reference/zf?view=msvc-170 its auto-enabled when /Zi or /ZI are on (seems to be done in Microsoft.CppBuild.targets). Sadly, I had it manually specified in some AdditionalOptions in a high level inherited .props file. The sccache docs mention /Z7 should be used, and my setup should have been set that way, but I think because my CI/CD style builds overrode to /Z7 but left in /Zf each .cpp was being built with both passed in. MSBuild should have been ignoring /Zf in this scenario, but I guess it must trigger something internally in sccache making it think there is a second file being passed in.

I think at a minimum, the error message should be clearer, but optimally, that argument would just be ignored and build capability would be based on just /Z7 vs ZI/Zi. I assume the user gets a clear error when they do /Zi or /ZI, so maybe it could reuse that one.

A similar annoyance is overriding <PrecompiledHeader>NotUsing</PrecompiledHeader> (I'd think) should remove the non-cacheable due to "/Yc x" where x is the number of StdAfx.h files I was compiling. However, I narrowed it down to each stdafx.cpp was being built without /Yc in that mode, but it still had /Fp for specifying the output file ( https://learn.microsoft.com/en-us/cpp/build/reference/fp-name-dot-pch-file?view=msvc-170 ). I figured this would be a harmless argument to remain since /Yc was being suppressed (sadly MSBuild doesn't seem to turn off /Fp even though we're set to NotUsing). This seems to be triggering sccache uncacheable errors even though we're not really using pchs.

Minimal Reproduction
version: latest (0.14)
wrote a powershell script to reproduce, but can't attach it, output from a run as follows:

sccache : sccache 0.14.0
cl.exe  : C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe

Source  : C:\Users\Dillo\AppData\Local\Temp\sccache_zf_repro\hello.cpp
Content : int main() { return 0; }

--- Baseline: no /Zf (expected: cache miss) ---
Command: sccache C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe /c /nologo /TP C:\Users\Dillo\AppData\Local\Temp\sccache_zf_repro\hello.cpp
  Compile requests                       1
  Cache hits                             0
  Cache misses                           1
  Non-cacheable calls                    0

--- Baseline again: no /Zf (expected: cache hit) ---
Command: sccache C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe /c /nologo /TP C:\Users\Dillo\AppData\Local\Temp\sccache_zf_repro\hello.cpp
  Compile requests                       1
  Cache hits                             1
  Cache misses                           0
  Non-cacheable calls                    0

--- With /Zf before source (BUG: expect cache miss, got 'multiple input files') ---
Command: sccache C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe /c /nologo /TP /Zf C:\Users\Dillo\AppData\Local\Temp\sccache_zf_repro\hello.cpp
  Compile requests                      1
  Cache hits                            0
  Cache misses                          0
  Non-cacheable calls                   1

--- With /Zf after source  (BUG: same result regardless of position) ---
Command: sccache C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe /c /nologo /TP C:\Users\Dillo\AppData\Local\Temp\sccache_zf_repro\hello.cpp /Zf
  Compile requests                      1
  Cache hits                            0
  Cache misses                          0
  Non-cacheable calls                   1

=========================================================
Expected behaviour for /Zf cases:
  Cache miss / cache hit (PassThrough), or at worst:
  non-cacheable: unknown argument /Zf

Actual behaviour (sccache 0.14.0):
  non-cacheable: multiple input files
  (incorrect -- exactly one .cpp was passed)

Root cause:
  /Zf is absent from the ARGS table in src/compiler/msvc.rs.
  The parser misidentifies it in a way that inflates the input
  file count, triggering the 'multiple input files' guard.

Suggested one-line fix in src/compiler/msvc.rs
(between the Zi and Zm entries):
  msvc_flag!("Zf", PassThrough), // faster parallel PDB generation
=========================================================

Activity

  1. added a commit that references this issue on Apr 2, 2026
    abb7ed5
  2. AJIOB commented on Apr 2, 2026

    @AJIOB
    Contributor

    Hi @DillonSadofsky ,

    I understand your pain. I've added as much flags I can from PCH (/Y...) and /Zf.

    More flags support or better support of /Y- flag requires more redesigning, that I have no time to do, sorry.

    Is my changes OK to you?

  3. DillonSadofsky commented on Apr 6, 2026

    @DillonSadofsky
    Author

    @AJIOB
    Your changes look good. I know I wrote a lot above, but really what my second point boils down to is I would posit that:

        msvc_take_arg!("Fp", PathBuf, Concatenated, TooHardPath), // allows users to specify the name for a PCH (when using /Yu or /Yc), PCHs are not supported in sccache.
    

    should be flipped to PassThrough. Why when it is specific to PCHs which are not supported? Well, because it (on its own) does not cause PCHs to be built, /Yu and /Yc control that entirely so far as I can tell.

    I was able to work around this with targeted magic in a .props file that is forced in during an MSBuild.

    All that said, I was bringing this into our tool stack in order to make automated CI/CD take less minutes. In the end, I had to abandon the sccache integration.

    A local build with PCHs on takes me 17:23, but with no PCHes and cold sccache its 55m. For faster testing, I made a reduced .sln to test a reduced project set. Local clean build was 2:32 on the CLI and 1:46 in VS code 2022 (not sure why the difference), but sccache cold/no PCH was 25:55 (actually it was an 8% hitrate because I forgot to totally clear out) and 7:52 with a fully warmed cached (100% hitrate).

    The fact that sccache can't support precompiled headers means that even in the best case, the builds are several times slower on a project of my size, and when its cold, its several times slower still. Since I was trying to speed up GitHub actions CI/CD wherein the VMs are several times slower than a local machine, these times become so slow I never got a full project build with sccache to complete. I'd always kill it after 2 and a half hours (windows VM minutes are expensive).

    Is there any plan to add PCH support? If you ever do, I'd flip my automation back on.

  4. AJIOB commented on Apr 6, 2026

    @AJIOB
    Contributor

    Hi @DillonSadofsky,

    In general, I'm not using PCH at all for historical reasons.

    If you have time, you can implement the PCH support: IMO, it's a nice way to speed up compiling before the C++20 modules

  5. DillonSadofsky commented on Apr 6, 2026

    @DillonSadofsky
    Author

    I'll consider it. For now I guess this ticket should be done (unless you want to make /Fp passthrough. I'm interested in what it'd take to switch to the C++20 PCH system, but the readme says its not available supported via MSVC yet so I may have to wait for it to cook. It was just a curiosity to see if I could make things better

  6. added a commit that references this issue on Apr 7, 2026
    619c72c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions