How to fill dune file to compile pgocaml ppx syntax code?

Hi !
I am intended to build with dune this small piece of code:

open Os_db
include Type
    
let post_wish user_id wish =
  full_transaction_block (fun dbh ->
    [%pgsql dbh "UPDATE ocsigen_start.wishes SET info = (info || jsonb_build_object($wish :: text, $wish :: text))"])

little experienced with compiling with ppx, I do not succeed writing properly the dune file. Here is my dune file:

(library
  (name administrative_book)
  (libraries type pgocaml pgocaml.ppx ocsigen-start.server)
  (preprocess (pps ppx_deriving.std pgocaml pgocaml.ppx)))

Here is error message I get when building above library:

$ dune build administrative_book/administrative_book.a
File "administrative_book/administrative_book.ml", line 6, characters 6-11:
Error: Uninterpreted extension 'pgsql'.

I am using pgocaml version 3.2 (that is why I have to write pgocaml.ppx instead of pgocaml_ppx).
I have been searching ocsigen makefile where are written rules to compile such files, I tried several combinations but I could not make it work. Here are packages referenced for compilation of such files inside ocsigen makefile, as an important hint I think:

SERVER_ELIOM_PACKAGES := ocsigen-start.server
SERVER_PACKAGES       := lwt_ppx js_of_ocaml-ppx.deriving ppx_deriving.std pgocaml
SERVER_DB_PACKAGES    := pgocaml pgocaml.ppx

Thank you a lot for your help :slight_smile:

It looks like in the version 3.2 of pgocaml, pgocaml.ppx is not compatible with dune. If you can’t upgrade to a more recent of pgocaml, a quick workaround is to add the two following lines to the META file of pgocaml, in the package "ppx" section:

archive(ppx_driver,byte) = "ppx_pgsql.cma"
archive(ppx_driver,native) = "ppx_pgsql.cmxa"
1 Like

Thanks diml ! Indeed I cannot upgrade for this project. I just tried to modify META file as you advise me but nothing seems to occur (I tried to run eval $(opam env) in case). Here is my modified META file in case it can be helpful:

# OASIS_START
version = "3.2"
description = "OCaml bindings for the PostgreSQL database"
requires = "unix calendar csv re bytes hex"
archive(byte) = "pgocaml.cma"
archive(byte, plugin) = "pgocaml.cma"
archive(native) = "pgocaml.cmxa"
archive(native, plugin) = "pgocaml.cmxs"
exists_if = "pgocaml.cma"
package "syntax" (
 version = "3.2"
 description = "Syntax extension for PG'OCaml"
 requires = "pgocaml camlp4"
 archive(syntax, preprocessor) = "pa_pgsql.cma"
 archive(syntax, toploop) = "pa_pgsql.cma"
 exists_if = "pa_pgsql.cma"
)

package "ppx" (
 version = "3.2"
 description = "Syntax extension for PG'OCaml using PPX"
 requires = "pgocaml"
 archive(syntax, preprocessor) = "ppx_pgsql.cma"
 archive(syntax, toploop) = "ppx_pgsql.cma"
 archive(syntax, preprocessor, native) = "ppx_pgsql.cmxa"
 archive(syntax, preprocessor, native, plugin) = "ppx_pgsql.cmxs"
 archive(ppx_driver,byte) = "ppx_pgsql.cma"
 archive(ppx_driver,native) = "ppx_pgsql.cmxa"
 ppx = "ppx_pgsql"
 exists_if = "ppx_pgsql.cma"
)
# OASIS_STOP

Ah, it’s probably because the archive is not built with linkall and doesn’t end up linked in the ppx driver. You can try to edit the source code of pgocaml and add a line like this to the _tags file: <ppx/ppx_pgsql.*>: linkall

1 Like

There is no such _tags file, here is the list of files on my pgocaml directory:

$ ~/.opam/myswitch/lib/pgocaml$ ls -a
.               PGOCaml.annot      PGOCaml.cmti           PGOCaml_generic.cmi
..              PGOCaml_aux.annot  PGOCaml.cmx            PGOCaml_generic.cmt
META            PGOCaml_aux.cmi    pgocaml.cmxa           PGOCaml_generic.cmti
META~           PGOCaml_aux.cmt    pgocaml.cmxs           PGOCaml_generic.cmx
pa_pgsql.annot  PGOCaml_aux.cmti   PGOCaml_config.annot   PGOCaml_generic.mli
pa_pgsql.cma    PGOCaml_aux.cmx    PGOCaml_config.cmi     PGOCaml.mli
pa_pgsql.cmi    PGOCaml_aux.mli    PGOCaml_config.cmt     ppx_pgsql.a
pa_pgsql.cmt    pgocaml.cma        PGOCaml_config.cmx     ppx_pgsql.cma
pa_pgsql.ml     PGOCaml.cmi        PGOCaml_config.ml      ppx_pgsql.cmxa
pgocaml.a       PGOCaml.cmt        PGOCaml_generic.annot  ppx_pgsql.cmxs

Anyway thanks for your help since diml !

I meant to modify the source code of pgocaml and rebuild&reinstall it. You can’t add the -linkall flag after the archive file is built. Or well, maybe you could do it with an hexadecimal editor…

Anyway thanks for your help since diml !

No problem :slight_smile:

1 Like

Ah yeah, I did not get it at first !
As there is a bit of work there (not so easy to automatize for devops), I explore if I can upgrade my project in order to use a more modern version of pgocaml. I keep you up to date if I do what you just advised.
Thanks again and have a good day :slight_smile:

No problem, have a good day too!