generate make dependencies

Skip to first unread message

Dirk Jagdmann

Aug 5, 2021, 1:18:45 PM8/5/21
to Cap'n Proto
Hello Cap'n'Proto experts,

I would like to generate dependencies for Cap'n'Proto schema file imports in the syntax understood by (GNU) make. Similar to the gcc compiler's -M command line argument.

I'm happy to look into the Cap'n'Proto source code and see if I can implement this myself, but it would help if you can give me some guide which data structures in which files would have the information that I need (currently processed schema file, list of include directories, ...)

Ian Denhardt

Aug 5, 2021, 2:04:14 PM8/5/21
to Cap'n Proto, Dirk Jagdmann
I've vaguely wanted this in the past, glad someone is interested and
motivated enough to get their hands dirty :)

Assuming you're interested in doing this only for C++, you'd want to make
the changes in the capnpc-c++ code generator plugin. Maybe Kenton can
provide more specific guidance than this, since I'm not familiar with
that part of the codebase. But at a high level, the main schema compiler
is going to feed that program a CodeGeneratorRequest as defined in
schema.capnp. RequestedFile.imports should have the information you need
to generate dependencies.

A possible alternative wuold be to write a (separate) schema compiler
plugin that just dumps the input to a file (say foo.capnp.cgr) and also
generates Makefile stubs for that file; you could then feed in the
generated file to capnpc-c++ (or other plugins) manually, and add
rules like:

%.capnp.cgr: %.capnp
# ...
%.capnp.h %.capnp.c++: %.capnp.cgr
# ...

This would be more general, and might be a little easier.

Note that one thing that's a little sad about gcc's -M is that it will
fail if the file doesn't exist, so you can't use it to gather dependencies
for the *.capnp.{h,c++} files as easily as you can non-generated files.


Quoting Dirk Jagdmann (2021-08-05 11:50:58)
> --
> You received this message because you are subscribed to the Google
> Groups "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [1]
> To view this discussion on the web visit
> [2]
> Verweise
> 1.
> 2.

Kenton Varda

Aug 5, 2021, 2:34:04 PM8/5/21
to Ian Denhardt, Cap'n Proto, Dirk Jagdmann
I think this could be implemented as a regular old code generator plugin that directly produces the deps files. No need to integrate with the C++ plugin nor output an intermediate representation.

Note that `capnp compile` supports passing multiple `-o` flags to run multiple plugins, so you can run both your C++ generator and your deps generator in one pass.


To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages