This patch implements support for [P1689R5][] to communicate to a build
system the C++20 module dependencies to build systems so that they may
build `.gcm` files in the proper order.
Support is communicated through the following three new flags:
- `-fdeps-format=` specifies the format for the output. Currently named
`p1689r5`.
- `-fdeps-file=` specifies the path to the file to write the format to.
- `-fdep-output=` specifies the `.o` that will be written for the TU
that is scanned. This is required so that the build system can
correlate the dependency output with the actual compilation that will
occur.
CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0)
using an experimental feature selection (to allow for future usage
evolution without committing to how it works today). While it remains
experimental, docs may be found in CMake's documentation for
experimental features.
Future work may include using this format for Fortran module
dependencies as well, however this is still pending work.
[P1689R5]: https://isocpp.org/files/papers/P1689R5.html
[cmake-experimental]:
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst
TODO:
- header-unit information fields
Header units (including the standard library headers) are 100%
unsupported right now because the `-E` mechanism wants to import their
BMIs. A new mode (i.e., something more workable than existing `-E`
behavior) that mocks up header units as if they were imported purely
from their path and content would be required.
- non-utf8 paths
The current standard says that paths that are not unambiguously
represented using UTF-8 are not supported (because these cases are rare
and the extra complication is not worth it at this time). Future
versions of the format might have ways of encoding non-UTF-8 paths. For
now, this patch just doesn't support non-UTF-8 paths (ignoring the
"unambiguously represetable in UTF-8" case).
- figure out why junk gets placed at the end of the file
Sometimes it seems like the file gets a lot of `NUL` bytes appended to
it. It happens rarely and seems to be the result of some
`ftruncate`-style call which results in extra padding in the contents.
Noting it here as an observation at least.
Signed-off-by: Ben Boeckel
---
gcc/ChangeLog | 9 ++
gcc/c-family/ChangeLog | 6 +
gcc/c-family/c-opts.cc | 40 ++-
gcc/c-family/c.opt | 12 ++
gcc/cp/ChangeLog| 5 +
gcc/cp/module.cc| 3 +-
gcc/doc/invoke.texi | 15 +++
gcc/fortran/ChangeLog | 5 +
gcc/fortran/cpp.cc | 4 +-
gcc/genmatch.cc | 2 +-
gcc/input.cc| 4 +-
libcpp/ChangeLog| 11 ++
libcpp/include/cpplib.h | 12 +-
libcpp/include/mkdeps.h | 17 ++-
libcpp/init.cc | 14 ++-
libcpp/mkdeps.cc| 235 ++--
16 files changed, 368 insertions(+), 26 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6dded16c0e3..2d61de6adde 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2022-09-20 Ben Boeckel
+
+ * doc/invoke.texi: Document -fdeps-format=, -fdep-file=, and
+ -fdep-output= flags.
+ * genmatch.cc (main): Add new preprocessor parameter used for C++
+ module tracking.
+ * input.cc (test_lexer): Add new preprocessor parameter used for C++
+ module tracking.
+
2022-09-19 Torbjörn SVENSSON
* targhooks.cc (default_zero_call_used_regs): Improve sorry
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index ba3d76dd6cb..569dcd96e8c 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2022-09-20 Ben Boeckel
+
+ * c-opts.cc (c_common_handle_option): Add fdeps_file variable and
+ -fdeps-format=, -fdep-file=, and -fdep-output= parsing.
+ * c.opt: Add -fdeps-format=, -fdep-file=, and -fdep-output= flags.
+
2022-09-15 Richard Biener
* c-common.h (build_void_list_node): Remove.
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index babaa2fc157..617d0e93696 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -77,6 +77,9 @@ static bool verbose;
/* Dependency output file. */
static const char *deps_file;
+/* Enhanced dependency output file. */
+static const char *fdeps_file;
+
/* The prefix given by -iprefix, if any. */
static const char *iprefix;
@@ -360,6 +363,23 @@ c_common_handle_option (size_t scode, const char *arg,
HOST_WIDE_INT value,
deps_file = arg;
break;
+case OPT_fdep_format_:
+ if (!strcmp (arg, "p1689r5"))
+ cpp_opts->deps.format = DEPS_FMT_P1689R5;
+ else
+ error ("%<-fdep-format=%> unknown format %s", arg);
+ break;
+
+case OPT_fdep_file_:
+ deps_seen = true;
+ fdeps_file = arg;
+ break;
+
+case OPT_fdep_output_:
+ deps_seen = true;
+ defer_opt (code, arg);
+ break;
+
case OPT_MF:
deps_seen = true;
d