Skip to content

Support for functions that compute deps in (rule (deps ..)) #4089

@gmalecha

Description

@gmalecha

Desired Behavior

Generally, I need a bit more support for computing dependencies dynamically in rules. This would make it possible to do things like describing dependencies of C++ files and computing them in dune rather than using another build system to construct a dependency graph for me.

Example

I have a program that consumes a C++ file (.hpp or .cpp) and generates a Coq AST from it. In doing this, it performs all of the pre-processing so transitive dependencies need to be tracked and the output needs to be updated whenever a transitive dependency is updated.

@rgrinberg suggested the following on Zulip (see https://coq.zulipchat.com/#narrow/stream/240550-Dune-devs.20.26.20users/topic/Generated.20files.20dependency/near/222022318)

(rule
  (targets foo.cpp.deps)
 (deps (glob_files *.cpp *.hpp))
 (action (with-stdout-to foo.cpp.deps (gcc -MM foo.cpp))))

(rule
 (targets foo.v)
 (deps foo.cxx (:include foo.cxx.deps))
 (action (run cpp2v foo.cxx -o %{targets})))

The only catch is that (:include ..) isn't supported inside deps yet. There's no problem with adding support for that. We already have this feature, we just simply haven't exposed supported for it in the frontend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedaccepted proposals

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions