0

I wanted to specify the versions of my dependencies in my dune-project file explicitly, to avoid any breakages due to newer versions (in the same way I might list Java dependencies in a Gradle build file, if that means anything to you).

The documentation for Dune suggests you can declare dependencies by using (depends ...) under (package ...).

In my dune-project, I have

(package
 (name my_app)
 (synopsis "A short synopsis")
 (description "A longer description")
 (depends 
  (ocaml (= "5.0.0")) 
  dune)
 (tags
  (topics "to describe" your project)))

Note here that I've listed "5.0.0" as the version of OCaml. On my system, I only have 4.14.1. When I run dune build, my program compiles, all the tests pass and the program runs.

The documentation doesn't really explain what depends is intended for. I had expected an error or something else to happen (like it would download the upgraded version, like how Gradle would work).

Could someone enlighten me please?

Chris
  • 26,361
  • 5
  • 21
  • 42
ndc85430
  • 1,395
  • 3
  • 11
  • 17
  • 1
    Are you sure you haven't typoed? You parens don't quite look like they're in the right place. Maybe you wanted `(depends (ocaml (= "5.0.0")))` You may also want to be a little more flexible by specifying `>= "5.0.0"` – Chris Jul 15 '23 at 17:58
  • Sorry, I fixed the typo in the post. I still don't get any error, or warning, though. – ndc85430 Jul 15 '23 at 18:08

1 Answers1

2

The depends field only matters at the package level.

Packages are published bundle of libraries or executables.

Consequently, the failure that you expect will only happen when trying to install the package (for instance with opam pin add .).

octachron
  • 17,178
  • 2
  • 16
  • 23