Some dune questions

Hello,

How do I tell dune that building the library depends on the preprocessor having been built first?

(executable
  (name prefilter)
  (modules prefilter)
  (libraries str)
  (modes byte))

(library
  (name batList)
  (public_name batList)
  (flags (:standard -pp _build/default/src/prefilter.bc))
  (modules batList))

I get this currently:

# dune build
      ocamlc src/.batList.objs/byte/batList.{cmi,cmti} (exit 2)
(cd _build/default && /home/berenger/.opam/default/bin/ocamlc.opt -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -pp _build/default/src/prefilter.bc -g -bin-annot -I src/.batList.objs/byte -no-alias-deps -opaque -o src/.batList.objs/byte/batList.cmi -c -intf src/batList.mli)
sh: 1: _build/default/src/prefilter.bc: not found
File "src/batList.mli", line 1:
Error: I/O error: _build/default/src/prefilter.bc 'src/batList.mli' > /tmp/builda72eb9.dune/ocamlppc00692
File "_unknown_", line 1, characters 0-0:
Error: File unavailable: prefilter.byte

Another question: how to tell dune to build only one library if the project has several?

dune build ???

Preprocessing steps should be specified using the (preprocess ...) field, see General concepts — dune documentation.

What you are looking for is called “preprocessing with an action”. Your action will be passed the file name of the input file and it is supposed to output the preprocessed file on standard output.

Cheers,
Nicolas

1 Like

This is not an exact answer to your question but you can tell dune to only compile the libraries/executables in directory foo by doing dune build @@foo/all or dune build @@foo/check (the @check target only compiles and does not link, so it is faster). The double at-sign means that dune does not look recursively for things to build. If you prefer a recursive build you can use a single @.

Cheers,
Nicolas

I am also looking how to tell dune: hey, this library depends on this executable, because this is the preprocessor for it…
I tried to find in dune’s documentation, but it is quite obscure for me.

1 Like

There is no need to tell this to dune explicitly as it will automatically figure out the dependencies when you specify your preprocessing steps using the (preprocess ...) field as shown in General concepts — dune documentation.

Cheers,
Nicolas

FTR, the working dune file I obtained in the end, with the help of @nojb:

(executable
  (name prefilter)
  (modules prefilter)
  (libraries str))

(library
  (name batList)
  (public_name batList)
  (preprocess
    (action
      (run ./src/prefilter.exe "%{input-file}")))
  (modules batList batEnum batInterfaces batInnerIO batConcurrent
  batOrd batInnerWeaktbl batBytesCompat batRef batSet batSeq batInnerShuffle
  batPrintf batBuffer batString batInt batNumber batInt32 batInt64 batNativeint
  batIO batUnix batFloat batChar))
1 Like

Great that it worked.

Two tips to improve the resulting dune file:

  • if name and public_name are equal, you can just put (public_name)
  • if there’s just one buildable thing in the directory, you don’t have to specify (modules). So you can make a prefilter subdirectory with a dune file and prefilter.ml and use the following dune files:
; src/dune
(library
  (public_name batList)
  (preprocess
    (action
      (run ./prefilter/prefilter.exe "%{input-file}"))))

; src/prefilter/dune
(executable
  (name prefilter)
  (libraries str))