mstorsjo/msvc-wine

Work with ccache: Problem with MSVC /P (Preprocess to a File) option

Closed this issue · 2 comments

Background

ccache has three working modes:

  • The preprocessor mode: Run preprocessor and parse the output file. It is slow.
  • The direct mode: Fallback to preprocessor mode if it is not available. It is fast.
  • The depend mode. Same as direct mode, but never fallback to preprocessor mode, and rely on outputs of /showIncludes.

Problem

touch /tmp/header.h
echo '#include "header.h"' > /tmp/main.c
CCACHE_LOGFILE=ccache.log CCACHE_NODEPEND= CCACHE_DIRECT= ccache /opt/msvc/bin/x64/cl.exe -c /tmp/main.c
cat ccache.log
] Trying direct lookup
] Manifest key: 74199n1cl3ceh887hu1o509m3thr8mql2
] No 74199n1cl3ceh887hu1o509m3thr8mql2 in local storage
] Running preprocessor
] Executing /opt/msvc/bin/x64/cl.exe -P -Fi/run/user/1000/ccache-tmp/cpp_stdout.tmp.yFZLHy.i /tmp/main.c
] Failed to stat z:/tmp/main.c: No such file or directory
] Disabling direct mode

The direct mode is always disabled due to accessing z:/tmp/main.c.

Cause

The output of /opt/msvc/bin/x64/cl.exe -P /tmp/main.c is the file main.i in CWD if option /Fi is not present.

#line 1 "z:/tmp/main.c"
#line 1 "z:\\tmp\\header.h"
#line 2 "z:/tmp/main.c"

The paths in the file are not converted to unix style. ccache will parse this file and hash the files listed, which is of cause failed, and then direct mode is disabled.

Solution

  • Use ccache depend mode. It doesn't run preprocessor but hash files listed in /showIncludes, which we already convert them to unix style paths. OR,
  • Postprocess the preprocessor output file: convert to unix style paths. This need implement in wine-msvc.sh wrapper. @mstorsjo What's your opinion?
  • Use ccache depend mode. It doesn't run preprocessor but hash files listed in /showIncludes, which we already convert them to unix style paths.

So this would require the user to set some option to make ccache not try to use this mode?

  • Postprocess the preprocessor output file: convert to unix style paths. This need implement in wine-msvc.sh wrapper.

Hmm. So the wrapper script would intercept any [/-]Fi option, and if present, do the path name rewriting on lines that look like #line in that output file? I guess that would work - if it doesn't end up being too much of a mess, I guess this could be acceptable?

So this would require the user to set some option to make ccache not try to use this mode?

Yes. User need define CCACHE_DEPEND env var, or add depend_mode = true to ccache.conf.

Please see proposed #70.