I'm in an internal package of my project and I ran dune build #doc. It does not complain and runs to completion. I then check the /_build/default directory and no _doc directory exists.
Am I missing something?
You should simply be able to generate docs by running dune build #doc if you have foo.ml, foo.opam, and a dune file containing simple contents. For example,
(library
(name foo))
To answer the question, the package name should be related to the library name or public name (if added as a stanza to the dune file).
Related
Say I run dune init proj hello_world, then modify the bin/dune and bin/main.ml files so that a new dependency foobar is in use.
The bin/dune file now:
(executable
(public_name hello_world)
(name main)
(libraries hello_world foobar))
1. How can I specify that the foobar library should have a certain exact version?
2. If we know that the foobar library uses semantic versioning, how could I specify that any version with the major version as 3 is required?
ocaml version 4.14.0
dune version 3.6.1
Package dependencies for a project are specified in the dune-project file, see https://dune.readthedocs.io/en/stable/dune-files.html#package
A default dune-project file is generated by dune init proj ....
You will and with a line in the depends field like
(depends
(foobar (>= 3))
Note that this is needed in addition to specifying which libraries the executable depends on.
I'm building a project using dune and I'm facing the following situation. Essentially, my project depends on another project, not developed by me, from which I want to use some parts of the source code.
Here is more or less my project tree
my_project/
|---dune-project
|---src/
|---dune
|---extrenal-project/
|---dune-project
|---dune
|---src/
|---dune
|---src-file.ml
The problem is that external-project has a dune file that builds it as an executable, instead of a library. Therefore, I cannot include it as a library in my dune file. Ideally, I don't want to modify the dune file inside of external-project.
I've tried a series of combinations. Here is the current status of my dune file:
(dirs external-project)
(executable
(name myexec)
(libraries containers)
(modules Myexec)
(promote (until-clean) (into ".."))
)
(env (dev (flags (:standard -warn-error -A))))
Which allows me to compile external-project correctly, but then does not allow me to reference any of its files. I also tried (dirs external-project external-project/src) but to no success.
So, my question is: is there a way for me to reference external-project as a library, even though it is build as an executable?
Thanks for your help!
Following the tutorial at https://dune.readthedocs.io/en/stable/quick-start.html, I created a file hello_world.ml containing
print_endline "Hello, world!"
and a file dune containing
(executable
(name hello_world))
and then typed
dune build hello_world.exe
but it complains about errors in other (completely unrelated) files.
Is it possible that dune looks at other files even though they are not mentioned in the dune file (even recursively) ? And how to prevent it ?
Yes, dune will search for all files that have *.ml or *.re files in the current folder. To disable this behavior use the modules stanza and explicitly specify which modules comprise your executable. For example, if it is made of hello_world.ml and utilities.ml compilation units, then the following specification will work for you,
(executable
(name hello_world)
(modules hello_world utilities))
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 )
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) .
I switched my dune project version from (lang dune 1.1) to (lang dune 2.0) which produced an error for the handling of alternate dependencies.
I had the foolowing in my dune file which worked with dune 1.1:
(select vpl_domain.ml from
(vpl -> domains/numeric/vpl_domain.ok.ml)
(!vpl -> domains/numeric/vpl_domain.ko.ml))
But produces with dune 2.0 the error
The format for files in this select branch must be
vpl_domain.{name}.ml
I've tried to remove the path before the filename like this:
(select vpl_domain.ml from
(vpl -> vpl_domain.ok.ml)
(!vpl -> vpl_domain.ko.ml)))
which seems to make dune happy about the format but gives the error
No rule found for vpl_domain.ko.ml
Am I doing something wrong, is this a bug of dune or did they voluntarily make breaking changes?
I finally found out in the documentation that:
Dune officially only supports user rules with targets in the current directory