Dune Local Install Not Appearing in Opam

Hi Everyone,

I have been working on getting Cucumber ML ready to be published on opam. In the course of this, I got the C library that it depends on to compile with Dune rather than needing to do it separately. In preparation for sending this for release with opam, I did a dune build && dune install which duly installed the files into opam under the correct switch. However, when I do an opam list to see it in the listings, it is not listed. I can see it listed in ocamlfind and I can compile my test program fine. I made sure that I had a public_name in my dune file as described in the documentation but it is not appearing either in the installed list or under --all . I am at a loss as to what else to try or where I went wrong. Any help would be greatly appreciated.

dune-project

(lang dune 2.6)
(version 2.0.0)

(generate_opam_files true)

(source (github cucumber/cucumber.ml))
(license MIT)
(authors "Christopher Guy Yocum")
(maintainers "cyocum@gmail.com")

(package
	(name cucumber)
	(synopsis "Cucumber BDD for OCaml")
	(description "Cucumber BDD for OCaml using the gherkin-c library to parse")
	(depends
	 (dune (>= 2.6))
	 (re (= 1.9.0))
	 (base (= 0.14.0))
	 (cmdliner (= 1.0.2))))

lib/dune

(data_only_dirs gherkin-c)

(rule
 (deps (source_tree gherkin-c))
 (targets libgherkin-c.a dllgherkin-c.so)
 (action
 (no-infer
  (progn
   (chdir gherkin-c (run make libs libs_so))
   (copy gherkin-c/libs/libgherkin.a libgherkin-c.a)
   (copy gherkin-c/libs/libgherkin.so.7.0.4 dllgherkin-c.so)))))

(library
	(public_name cucumber)
	(libraries cmdliner re re.perl base)
	(synopsis "BDD style testing for OCaml")
	(foreign_archives gherkin-c)
	(foreign_stubs (language c) (names gherkin_intf)))

As I understand it, dune install isn’t aware of opam's metadata that tracks what libraries it has installed in the switch: it’s just copying sources into the opam switch directory where they can be found by dune. (For instance, .opam-switch/switch-state contains an installed list that is not updated by Dune.)

I suggest using some combination of opam pin and opam install <file> to install local Opam packages. opam doesn’t seem designed for other tools to inject sources into its switches. I’ve never found I needed dune install.

3 Likes

Thank you very much for this @CraigFe I just figured it out myself at the same time :smile:. I used opam install . which used the files generated by dune to then install. This gave me the confidence that it should now all work. I will play around with this. I like dune install do to quick compiles of my library so I can do a bit of testing with it from a user’s point of view (or some approximation thereof). Hopefully, this thread will help anyone else who gets confused in the future.

Thanks again!

1 Like