Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huangqinjin opened this issue Jun 2, 2023 · 2 comments · Fixed by #70
Closed

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

huangqinjin opened this issue Jun 2, 2023 · 2 comments · Fixed by #70

Comments

@huangqinjin
Copy link
Contributor

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?
@mstorsjo
Copy link
Owner

mstorsjo commented Jun 2, 2023

  • 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
Copy link
Contributor Author

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.

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 a pull request may close this issue.

2 participants