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

Spurious error parsing depfiles: inputs may not also have inputs? #1962

Open
asutton opened this issue Apr 23, 2021 · 6 comments
Open

Spurious error parsing depfiles: inputs may not also have inputs? #1962

asutton opened this issue Apr 23, 2021 · 6 comments

Comments

@asutton
Copy link

asutton commented Apr 23, 2021

I'm trying to get C++20 modules working with CMake/Ninja, for some definition of "working". I'm using GCC, CMake, and Ninja compiled from github (today). The compilation rule for a single file is this:

~/opt/bin/g++   -I../. -fmodules-ts -std=gnu++2a -MD -MT project/CMakeFiles/project-core.dir/core/module.cpp.o -MF project/CMakeFiles/project-core.dir/core/module.cpp.o.d -o project/CMakeFiles/project-core.dir/core/module.cpp.o -c ../project/core/module.cpp

Which produces the following .d file:

project/CMakeFiles/project-core.dir/core/module.cpp.o \
 gcm.cache/project.core.gcm: ../project/core/module.cpp \
 /usr/include/stdc-predef.h
project.core.c++m: gcm.cache/project.core.gcm
.PHONY: project.core.c++m
gcm.cache/project.core.gcm:| \
 project/CMakeFiles/project-core.dir/core/module.cpp.o

The error happens on the last line. The input is poisoned on the line above because gcm.cache/project.core.gcm is registered as an input for the phony project.core.c++m target. And apparently, there's some prohibition against inputs (dependencies) also appearing as outputs (targets), but apparently, not the reverse. Or at least maybe all outputs need to appear lexically before their appearance as inputs?

I'm also not sure why GCC is producing a secondary dependency for the gcm target. It might have something to do with building module interface partitions. I'm currently looking at GCC to see why it's producing these things and in this order.

I'd submit a PR disabling the error, but I'm pretty sure that's not the right solution. I don't know enough about the internals of ninja to propose a better resolution.

@JohelEGP
Copy link

JohelEGP commented Apr 1, 2022

Do you think this is a different bug?

I have a module waarudo.details.std which imports the importable header "waarudo.details.std.headers.hpp".

When I compile the module without a dependency on the importable header, I do get

inputs may not also have inputs

But when I compile with parallelization, I get

error: failed to read compiled module: No such file or directory

because the module builds in parallel with the importable header, even though I have set the build dependency in CMake (even with -j1 because the module compiles before the importable header).
Then, when I attempt to recompile (note that the importable header successfully compiled in parallel in the first attempt), I then get:

ninja: error: dependency cycle: CMakeFiles/waarudo.details.std.headers.dir/waarudo.details.std.headers.hpp.o -> /home/johel/Documents/C++/Repos/Waarudo-builds/gcc-trunk-Release/JEGPModules/waarudo.details.std.headers.gcm -> CMakeFiles/waarudo.details.std.headers.dir/waarudo.details.std.headers.hpp.o

even though GCC doesn't generate an object file for an importable header.

@jpakkane
Copy link

jpakkane commented May 3, 2022

@mathstuf
Copy link
Contributor

FYI, -fdeps-format=p1689r5 will suppress this extra information.

@mathstuf
Copy link
Contributor

I'm also not sure why GCC is producing a secondary dependency for the gcm target.

It has to do with Nathan's GNU make work to support modules. See this paper: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1602r0.pdf

@jpakkane
Copy link

FYI, -fdeps-format=p1689r5 will suppress this extra information.

This is useful, but really a proper fix. Things like this should work out of the box with default values

@mathstuf
Copy link
Contributor

I am also disappointed at the depfiles being more Make syntax by default as well (I believe I expressed this to Nathan at the time in 2019, but it had already been merged by then).

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

No branches or pull requests

4 participants