1

I have written a library in OCaml with all of its sources located in lib folder. I also prepared "facade" executables in bin folder. Now I would like to prepare some examples how to use the above mentioned executables. To do this I need to either copy an executable beforehand or (preferably) tell Dune to use a newly created one after build.

And here is my question. Dune's copy_files stanza does not allow1 me to copy from _build folder. Is there any other way to use fresh executables each time after building or do I need to copy them at some point and keep up to date?

Below is the structure of the project (in case verbal description was misleading in any way).

root
   lib <- source
   bin <- frontend for source
   examples <- how to use the above frontend

1 By not allow I mean the following usage of this stanza: ( copy_files %{project_root}/_build/default/bin/program.exe )

zajer
  • 649
  • 6
  • 17
  • 1
    See https://stackoverflow.com/questions/64373805/copy-the-produced-executable-in-my-root-dir-with-dune Unless you create a Makefile that copies the generated executable to the root, I don't know any other way to do it – Lhooq Mar 27 '21 at 09:08

1 Answers1

0

A solution, as suggested by @Lhooq, might be to use dune exec command with --root parameter.

In regard to the provided scenario, if we make a script:

   dune exec --root=../.. ./bin/some_program.exe 
(* 
   Where 'some_program' is the name of an .ml file located in bin folder.
   I assumed here that the program is compiled to native code, not to bytecode (hence the .exe).
*)

and place it in examples directory, then by invoking it we will actually run the latest build of the program defined in some_program.ml located in bin folder.

And just to make things clear: bin folder does NOT contain any compiled files (neither .exe nor .bc) .

zajer
  • 649
  • 6
  • 17