Stdin as an input file for MSVC

I have a special tool that I want to run as part of the compilation process, between preprocessing and compilation. For GCC, I:

gcc [options] -E source.c | mytool | gcc [options] -c source.o -xc - 

However, I did not understand how to do something similar for MSVC. I am currently

 cl.exe [options] /EP source.c | mytool.exe > temp.c cl.exe [options] /c temp.c 

The problem is that for each source file (thousands) I have an additional write / read disk cycle. Also, when MSVC outputs .i files, they tend to become very large. More than 10 MB. Thus, 10 MB of disk I / O for each file accumulates quickly.

So my questions are:

1) Is it possible to get cl.exe to read the call to stdin as an input file?

2) If not, is it possible to create a memory mapping file that it can read from?

3) Is there a better way to do this?

And no, "get SSDs" and "don't use MSVC" are not valid answers, sorry.

Related (but not a solution to the speed problem)

+5
source share
2 answers

In the future: I did not find a way to trick cl.exe into reading from memory instead of a disk.

However, I managed to speed up the process to an acceptable speed, using GNU CPP for the first stage, then cl.exe only for compilation. So:

 cpp.exe [options] source.c | mytool.exe > temp.c cl.exe [options] temp.c 

cpp.exe creates a file 5-10 times smaller than cl.exe /E The trick is only to define _MSC_VER and similar instead of __GNUC__ . I did this using the -undef option to get rid of everything, then define the MSFT-specific manually. I can learn to use clang as CPP since it can mimic MSVC.

CPP leaves the #pragma intact, so there are no compatibility issues there.


Now I have reached a performance point when the occurrence of a process has a significant impact on the overall build time, so I am looking for compilation of the preprocessor in mytool.exe .

+2
source

In Visual Studio 2010, under the Reliability pages, select Configuration Properties, section Custom Build Step. Try this section.

Also do an online search for "MSDN Visual Studio custom build".

+1
source

All Articles