7

Dependency file produced by C++ modules causes Ninja errors

 9 months ago
source link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105467
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

105467 – Dependency file produced by C++ modules causes Ninja errors

GCC Bugzilla – Bug 105467

Dependency file produced by C++ modules causes Ninja errors

Last modified: 2023-10-20 19:55:48 UTC

Bug 105467 - Dependency file produced by C++ modules causes Ninja errors

Attachments
Add an attachment (proposed patch, testcase, etc.)
Note You need to log in before you can comment on or make changes to this bug.

Description

jpakkane

2022-05-03 15:04:37 UTC

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

Comment 1

Ben Boeckel

2023-10-18 01:32:18 UTC

-fdeps-format=p1689r5 will suppress this extra information. A new `-Mno-modules` flag may be more useful (and certainly discoverable).

Comment 2

jpakkane

2023-10-20 19:55:48 UTC

It would be preferable to have the default work out of the box than having every end user having to add compiler flags to make things work.

Ninja is the most popular underlying build system for modules, having it work by default would make things easier for many people.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK