Cannot find included file during preprocessing

So I was recently tasked to update an old project, which uses dune, and I am not sure I fully grasp what is happening in one specific part.
The project was last used 2+ years ago with dune 1.8 and ocaml 4.09.0, which i updated to what I am now using; dune 3.8.0 and ocaml 5.0.0, as well as cppo 1.6.9.

When attempting to dune build, this happened:

File "dune", line 4, characters 22-54:
4 |   (preprocess (action (run %{bin:cppo}  %{input-file})))
Error: File "", line 613, characters 0-39
Error: Cannot find included file ""

Which dissappeared after i added (preprocessor_deps
I then had the same error with not finding some of the templates:

File "dune", line 7, characters 22-54:
7 |   (preprocess (action (run %{bin:cppo}  %{input-file})))
Error: File "", line 616, characters 0-50
Error: Cannot find included file "templates/"

And I cannot seem to fix this one. So far I have tried:
Adding (source_tree _build/default/templates/) to the preprocessor_deps.
Adding (include_subdirs unqualified) to the dune file.
Modifying the path of the included file in
Using -I option in the cppo action.

My understanding is that I fail to specify to dune and/or cppo where it should look for the files, but even that may be wrong.

My dune file is:

(ocamllex lexer)
(menhir (flags ("--explain" "--dump")) (modules grammar))
  (preprocess (action (run %{bin:cppo}  %{input-file})))
  (name      parser)
  (libraries core))

An extract of, where the problematic line is:

    method visit_script (my:script) = 
      #include ""

      #include "templates/"

My project tree is as follows:

├── _build
│   ├── default 
│   │   ├──
│   │   ├──
│   │   ├──
│   │   ├── grammar.mly
│   │   ├──
│   │   ├──
│   │   ├──
│   │   ├── lexer.mll
│   │   ├──
│   │   ├──
│   │   ├──
│   │   ├── templates
│   │   │   ├──
│   │   │   ├──
│   │   │   └── every other template
│   │   └──
│   └── log
├── dune
├── dune-project
├── grammar.mly
├── io_externs.phaistos
├── lexer.mll
├── Makefile
├── templates
│   ├──
│   ├──
│   └── other templates
├── temp.txt

I do not understand how your project structure works. Who generates templates/

In general I would approach this by defining targets, e.g.

 (action  (run %{bin:cppo} %{deps} -o %{targets})))

This way you can specify which modules need to be created and what depends on what and how it is created.

First, thank you for your reply.

all of the files are generated by a different part of the project, called in a previous make step.
I am a little confused as to what I should add in the targets/deps parts of the rule: To my understanding deps would be the files I need, so the generated ones, but the only ‘target’ I can identify in the current version of this is the target of the dune build command: parser.exe

but trying with this:

 (deps templates/
 (targets parser.exe)
 (action  (run %{bin:cppo} %{deps} -o %{targets})))

give me No rule found for templates/
and so i think i misunderstood how to use your advice.

So generally I would avoid mixing build systems, because now you need to make both aware of each other. Maybe you can make dune build these too?

In any case, Dune resolves dependencies by 1. either checking whether the file exists (in your case, templates/ relative to the dune file) or running the rule that has the dependency as a target (only one of them, if there is both a file and a rule it will complain because it is unclear which one to pick — unless you specify otherwise).

In your case, No rule found for templates/ means that Dune did not find the templates/ file nor is there any rule to produce this file. You’d need to make sure the paths fit.

Also, the rule you wrote means “to create parser.exe you need to procure templates/ and run cppo templates/ -o parser.exe” which will generate a parser.exe but it will not be an executable, it will be an text file with the output of cppo.

What you probably want is something more like

  (name parser)
  (modules parser))

 (deps templates/
 (action  (run %{bin:cppo} %{deps} -o %{targets})))

Which means “to create parser.exe you need to create is generated by cppo, which needs templates/ and will run cppo templates/ -o to create it”.