https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105467
Bug ID: 105467 Summary: Dependency file produced by C++ modules causes Ninja errors Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jpakkane at gmail dot com Target Milestone: --- Currently if you try to build C++ modules using Ninja and a dependency file, things fail with this fairly cryptic error message (that comes from Ninja): inputs may not also have inputs The commend line is this: g++ -Igcc/modtest.p -Igcc '-I../test cases/unit/85 cpp modules/gcc' -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++20 -O0 -g -fmodules-ts -MD -MQ gcc/modtest.p/src0.cxx.o -MF gcc/modtest.p/src0.cxx.o.d -o gcc/modtest.p/src0.cxx.o -c '../test cases/unit/85 cpp modules/gcc/src0.cxx and the generated dependency file looks like this: gcc/modtest.p/src0.cxx.o gcm.cache/M0.gcm: \ ../test\ cases/unit/85\ cpp\ modules/gcc/src0.cxx \ /usr/include/stdc-predef.h gcc/modtest.p/src0.cxx.o gcm.cache/M0.gcm: M1.c++m M0.c++m: gcm.cache/M0.gcm .PHONY: M0.c++m gcm.cache/M0.gcm:| gcc/modtest.p/src0.cxx.o CXX_IMPORTS += M1.c++m This sets things up so that the object file depends on the sources and the generated module file depends on the object file only. Ninja does not like this and errors out because it thinks that outputs (the .o file in this case) may not be used as a dependency to other outputs. A possible fix would be to set the dependencies of the module output to be the same source files as are used for the object file. Something like this: gcc/modtest.p/src0.cxx.o gcm.cache/M0.gcm: \ ../test\ cases/unit/85\ cpp\ modules/gcc/src0.cxx \ /usr/include/stdc-predef.h gcc/modtest.p/src0.cxx.o gcm.cache/M0.gcm: M1.c++m M0.c++m: gcm.cache/M0.gcm .PHONY: M0.c++m gcm.cache/M0.gcm: \ ../test\ cases/unit/85\ cpp\ modules/gcc/src0.cxx \ /usr/include/stdc-predef.h CXX_IMPORTS += M1.c++m The corresponding Ninja bug is here: https://github.com/ninja-build/ninja/issues/1962