Skip to content

msvc: do not expect a program database next to a -Fd directory - #2933

Merged
sylvestre merged 1 commit into
mozilla:mainfrom
451891358:pr/msvc-fd-fix
Oct 24, 2026
Merged

sylvestre merged 1 commit into
mozilla:mainfrom
451891358:pr/msvc-fd-fix

Conversation

@451891358

Copy link
Copy Markdown

A -Fd value with a trailing separator makes cl.exe write a shared
vc<NNN>.pdb inside that directory, but sccache recorded the artifact as
<dir>.pdb, a file cl.exe never creates. Writing the cache entry then failed
to open it, and that failure is fatal:

$ sccache cl /c /Zi /Fdpdb\ a.cpp
sccache: encountered fatal error
sccache: error: failed to zip up compiler outputs
sccache: caused by: failed to open file `...\pdb.pdb`
# exit code -2, although cl.exe succeeded and wrote a.obj and pdb\vc140.pdb

Because CacheWrite::from_objects treats a missing artifact with
optional: false as an error, and that error propagates out of
get_cached_or_compile, any build that passes a -Fd directory (for example
cl /c /Zi /Fd"$(IntDir)\") could not complete at all.

Report such compilations as not cacheable instead, with the shared pdb
reason already used when -Zi/-ZI is given without -Fd: the PDB cl.exe
writes into that directory is shared by every translation unit compiled into
it, so it cannot be tracked as a per-compilation artifact. The object file is
still produced, the build succeeds, and --show-stats names the reason.

Note that this also stops the previous silent Cacheable::No path for
directory names that happen to contain a dot (CMake's
CMakeFiles/<target>.dir/), which used to be classified as "the PDB already
exists, so it might be shared". The existing heuristic is unchanged for real
-Fd <file>.pdb paths.

Testing

New unit test test_parse_arguments_pdb_directory covers:

  • -Fdpdb\ and -Fdpdb/ with -Zi → CannotCache("shared pdb")
  • -Fdpdb\ without debug information → cacheable, no pdb artifact
    (cl.exe ignores -Fd in that case)
  • -Fdpdb\foo.pdb → cacheable, pdb artifact is pdb\foo.pdb

End to end on Windows with MSVC 19.51:

command before after
sccache cl /c /Zi /Fd"pdb\" /Foa.obj a.cpp exit -2, cache error exit 0, a.obj written, Non-cacheable reasons: shared pdb 1
sccache cl /c /Zi /Fd"pdb2\a.pdb" /Foa2.obj a.cpp (twice) — miss → hit, both a2.obj and pdb2\a.pdb restored

cargo test --lib: 583 passed, 0 failed (default features; 530 with
--no-default-features). cargo fmt --check is clean.

A -Fd value with a trailing separator makes cl.exe write a shared
vc<NNN>.pdb inside that directory, but the artifact was recorded as
"<dir>.pdb", which cl.exe never creates. Storing the compilation then failed
to open the missing file, and that turned into a fatal error ("failed to zip
up compiler outputs", exit code -2) even though the compiler had succeeded:

    cl /c /Zi /Fdpdb\ foo.cpp   ->  sccache: error: failed to open ...\pdb.pdb

Compilations like that can no longer complete. Report them as not cacheable
with the existing "shared pdb" reason, matching the -Fd-less case, so the
object file is still produced.
@codecov-commenter

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.21%. Comparing base (2eeea91) to head (ed71929).

Files with missing lines Patch % Lines
src/compiler/msvc.rs 90.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2933   +/-   ##
=======================================
  Coverage   78.20%   78.21%           
=======================================
  Files          74       74           
  Lines       43708    43728   +20     
=======================================
+ Hits        34184    34202   +18     
- Misses       9524     9526    +2     

☔ 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.

@sylvestre
sylvestre merged commit 5109a2b into mozilla:main Oct 24, 2026
51 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.

3 participants