Trying to get Cacti example working

I am extremely frustrated and hoping someone can help me. I am trying to get the example code in the Caqti github working working. It’s for a project they call bikereg.

Here are the steps I take:

dune init proj bikereg
cd bikereg

Then I replace bin/dune with the version in the examples directory mentioned above. It contains:

 (name bikereg)
 (modules bikereg)
 (libraries caqti caqti-dynload caqti-lwt caqti-lwt.unix testlib))

 (alias runtest)
 (package caqti-lwt)
 (deps (:test bikereg.exe) (alias ../testsuite/drivers) ../testsuite/uris.conf)
 (locks /db/bikereg)
  (setenv OCAMLPATH ../testsuite
   (run %{test} -U ../testsuite/uris.conf))))

Then I edit dune-project to depend on the libraries mentioned in the dune file. After editing, the package section reads:

 (name bikereg)
 (synopsis "A short synopsis")
 (description "A longer description")
 (depends ocaml dune caqti caqti-dynload caqti-lwt caqti-lwt.unix testlib)
  (topics "to describe" your project)))

Finally I run:
dune build

I get the output:

Error: The current scope doesn't define package "caqti-lwt".
The only packages for which you can declare elements to be installed in this
directory are:
- bikereg (because of bikereg.opam)

I’ve tried editing bikereg.opam to fix the problem, but it doesn’t help. Moreover the OCaml Quickstart says “Do not update project_name.opam manually! Let dune do it for you.” and says that we should use dune build to do that.

I have no idea what to do now to move forward. Perhaps the Caqti example is just wrong and shouldn’t be referring to caqti-lwt? But caqti-lwt does appear in the github directory for Caqti, so apparently it does exist. I don’t know why there would be a problem in referring to it.

Just a quick note that the convention is package.sublibrary, so you would only have a single depends ... package ..., not depends ... package package.sublibrary ... as above. But I don’t know anything about caqti.

I guess caqti-lwt should be install with opam (and its drivers too).

Hi Frederic, thanks for replying. I tried a manual
opam install caqti-lwt
and it installed without errors, including dependencies.

I then tried again to do
dune build

and got the same response as before:
File “bin/dune”, line 8, characters 10-19:

8 |  (package caqti-lwt)
Error: The current scope doesn't define package "caqti-lwt".
The only packages for which you can declare elements to be installed in this
directory are:
- bikereg (because of bikereg.opam)

This is really frustrating!

Hi lukstaff, thank you for replying… I removed the qaqti-lwt.unix entries in both the bin/dune and dune-project file, and got exactly the same result.

I think the problem is the (package caqti-lwt) in the rule for the test that runs the bikereg executable. This is telling dune that that specific test should be attached to the package caqti-lwt which makes sense in the caqti repository where that package is defined, but won’t work outside of it.

I think you just need to remove that line from that dune stanza. However, there are other bits in it that stanza that reference that repository too like the ../testsuite so it might just be better to remove the test stanza entirely and build the executable and run it yourself (you’ll need to change bikereg a bit and manually run the database, or try to copy the testsuite setup from the original repo)?

1 Like

patriocoferris: Thank you!!! I think you’re right. I’ll post here again when I get something working.

I’ve played with caqti a few months ago.

Maybe having a look at this project setup would help?

Thanks Benjamin! I’ll have a look.

To elaborate on the second point, the only purpose of the reference to ../testsuite is to make the META files of the driver available for dynamic loading. When building the example separately from the rest of the package, it can be removed, assuming the libraries are installed in the OPAM switch.