Jbuilder to dune : what is first-dep

I am trying to convert my jbuild files to dune files. Following this documentation :

I changed my jbuild file for the tests to:

 (names test)
 (libraries GObject_introspection oUnit ctypes ctypes.foreign)

  (name    runtest)
  (deps    test.exe)
  (action  (run %{first-dep})))

When I run the test I have the following error:

dune runtest
File "tests/dune", line 9, characters 18-28:                                                                 
Error: Unknown variable "first-dep"

I tried to look in the documentation for more information on the first-dep but found nothing.

My dune version is 1.0.1.

Does it works?

  (name    runtest)
  (deps    (:x test.exe))
  (action  (run %{x})))

Yes, it works thanks!. I thought that first-dep was a default/generic variable name. This is not something obvious, the documentation is not finished I guess.

Mind sending a pr to fix the docs here? %{first-dep} indeed used to be a built-in before we introduced the variable binding syntax. Now that there you can bind deps to your own names, there’s no need for this default name.

I am working on it but I don’t see how to replace it here :

     (targets foo.ml)
     (deps    foo.cppo.ml <other files that foo.ml includes>)
     (action  (run %{bin:cppo} %{first-dep} -o %{targets})))

and here:

    (preprocess (action (run %{bin:cppo} -V OCAML:%{ocaml_version} %{first-dep})))

In the first instance, you should write your deps field as such:

(deps (:first-dep foo.cppo.ml) <other files that foo.ml includes>)

The second example is dealt with the new special variable for preprocessing: %{input-file}

1 Like

I filed https://github.com/ocaml/dune/issues/1063 to track this in the meantime.

This should also work

  (name    runtest)
  (deps    test.exe)
  (action  (run %{deps})))

Even shorter:

 (name runtest)
 (action (run ./test.exe))

But this is best:

(test (name test.exe))