Support for precompiled headers
Hi, I've been trying to compile a project that uses precompiled headers.
Issue
gcc
(and apparently other compilers, I've only tested gcc
) will treat a file called ${name}.gch
as if it was a precompiled header called ${name}
, and will prioritize using such a file over the normal header.
I believe that recc
currently does not recognize precompiled headers as dependencies, and therefore doesn't upload them. This results in compilation failures if the precompiled headers are not in the same directory as the original headers (and results in wasted precompilation otherwise).
Reproduction
To sketch the problem, I wrote this little mini-project:
.
├── headers
│ └── stuff.h
├── main.c
├── Makefile
└── stuff.c
1 directory, 4 files
The files are as follows:
Makefile:
%.h.gch: headers/%.h
$(CC) -c $^ -o $@
%.o: %c
$(CC) -c $^ -o $@
main: main.o stuff.o
$(CC) -o $@ $^
main.o: main.c stuff.h.gch
main.c
:
#include "stuff.h"
<snip>
Other contents are unimportant, the C file just imports the header from the current directory, which should contain the precompiled header (but not the original header, since it is in a different directory), and then calls a function from inside it.
This is the error:
../build/bin/recc /nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0/bin/gcc -c -o main.o main.c
I0000 00:00:00.000000 26497 vlog_is_on.cc:197] RAW: Set VLOG level for "*" to 1
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [env.cpp:403] [DEBUG] No RECC_PROJECT_ROOT directory specified. Defaulting to current working directory (/home/tlater/Documents/Work/TS010/recc/gch-example)
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [env.cpp:417] [WARNING] Warning: RECC_REMOTE_PLATFORM has no values.
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [recc.m.cpp:219] [DEBUG] RECC_REAPI_VERSION == '2.0'
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [parsedcommandfactory.cpp:282] [DEBUG] Parsing command:
argv[1] = /nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0/bin/gcc
argv[2] = -c
argv[3] = -o
argv[4] = main.o
argv[5] = main.c
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [actionbuilder.cpp:189] [DEBUG] Getting dependencies using the command:
2021-02-01T15:03:31.471+0000 [26497:139989592723328] [actionbuilder.cpp:195] [DEBUG] /nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0/bin/gcc -c main.c -M
main.c:1:10: fatal error: stuff.h: No such file or directory
1 | #include "stuff.h"
| ^~~~~~~~~
compilation terminated.
2021-02-01T15:03:31.486+0000 [26497:139989592723328] [deps.cpp:147] [ERROR] Failed to execute get dependencies command: /nix/store/y78inja64xaaq6bx33nxn2h1lgw0jswk-gcc-wrapper-10.2.0/bin/gcc -c main.c -M
2021-02-01T15:03:31.486+0000 [26497:139989592723328] [deps.cpp:148] [ERROR] Exit status: 1
2021-02-01T15:03:31.486+0000 [26497:139989592723328] [deps.cpp:149] [DEBUG] stdout:
2021-02-01T15:03:31.486+0000 [26497:139989592723328] [deps.cpp:150] [DEBUG] stderr:
2021-02-01T15:03:31.486+0000 [26497:139989592723328] [actionbuilder.cpp:254] [DEBUG] Running locally to display the error.
main.c:1:19: error: one or more PCH files were found, but they were invalid
1 | #include "stuff.h"
| ^
main.c:1:19: error: use -Winvalid-pch for more information
main.c:1:10: fatal error: stuff.h: No such file or directory
1 | #include "stuff.h"
| ^~~~~~~~~
compilation terminated.
make: *** [<builtin>: main.o] Error 1
The errors here are a bit hard to navigate. one or more PCH files were found, but they were invalid
is a red herring, because the precompiled header exists locally - the problem is that it's missing on the server (as the debug message logs). I'm not sure why the command fails locally, but this is separate from the main problem.
Nonetheless, when downloading the root from the remote, the precompiled header is missing, and hence the compilation fails.