C++ Logo

sg15

Advanced search

Re: [isocpp-ext] Can we expect that all C++ source files can have the same suffix?

From: Daniel Ruoso <daniel_at_[hidden]>
Date: Wed, 20 Apr 2022 14:32:44 -0400
Em qua., 20 de abr. de 2022 às 14:10, Nicolai Josuttis
<nico_at_[hidden]> escreveu:
> IMO a compiler should parse a C++ file while a build system should not have to do that.

For this to be possible, we'd need additional requirements that I
don't think are something folks are open to.

 1. You would need the module interface and implementation unit source
files to be named in a predictable way in your source tree, so you can
identify which modules you have in your tree without reading the
files.

 2. You would need the dependency information to be extractable
without the use of the preprocessor. Currently it is valid to have the
preprocessor interfering into what are the modules imported by other
modules. The only thing that is possible without a preprocessor is to
detect if this c++ source file has module code or not.

As long as we allow any file to produce any module, and as long as we
allow dependencies to depend on the preprocessor, there's no way for a
build system to do this correctly without doing the scanning in order
to assemble the build rules correctly.

The current state of affairs is that modules require a multi-pass system:

 1. scan the sources to find which modules are where and which modules
depend on which
 2. produce the binary interface units in topological order,
 3. proper compilation phase that consumes the binary interface units

While it's technically possible to have that work in a "one-line"
command, this approach will only work on the most trivial cases, and
it will break down so quickly that there's no point in trying to make
compilers support that feature.

IMHO, it makes more sense to just accept that C++ with modules is not
really viable without a proper build system.

daniel

Received on 2022-04-20 18:32:56