mstorsjo / msvc-wine

Scripts for setting up and running MSVC in Wine on Linux
Other
683 stars 83 forks source link

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

Closed huangqinjin closed 1 year ago

huangqinjin commented 1 year ago

Background

ccache has three working modes:

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

mstorsjo commented 1 year ago
  • 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?

huangqinjin commented 1 year ago

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 https://github.com/mstorsjo/msvc-wine/pull/70.