Using local esy/dune OCaml dependencies

To set the scene, I’m working on an OCaml tool, along with a VSCode extension to run alongside it.

The tool is built with dune and managed via esy. The extension exists in a subfolder, has its own package.json, and builds with npm/yarn independently from the base tool.

├ MyToolCore
│ └ <... OCaml code here ...>
├ MyToolCommon
│ └ <... OCaml code here ...>
├ extension
│ ├ src
│ │ └ <... TypeScript code here ...>
│ ├ package.json
│ └ webpack.config.js
├ esy.json
├ dune
└ duneproject

What I’d like to do is rewrite some or all of the extension in ReScript, thus being able to leverage common code (mostly for the sake of type definitions) with the base tool.

TL;DR: how can I include local OCaml dependencies in my ReScript project?

I think the easiest solution here is to move bsconfig.json and package.json to the root and point to the source directories, ie extension/src and the source directories shared with ocaml.

I maintain multiple projects that have this setup, it works quite well.


Thank you, that seems to be working!

One little hiccup - I wonder if there’s a decent way of working around this; I’ve started moving some shared types to the common library, but ReScript doesn’t like the yojson derivations on those types - is there a way to get RS to ignore them? Dune seems quite happy to ignore the [@@genType]s that it doesn’t understand :))

For example, the following snippet is accepted by Dune, but errors with ReScript’s compiler.

type MyType = A | B | C
[@@deriving yojson]

Do let me know if this should be a new thread.

This is because ReScript interprets any [@@deriving ...] PPX attribute as something it needs to process. Of course in the OCaml ecosystem the attribute is widely known to be reserved for use by specific deriving PPXs. So there is a conflict between them. I’m not sure how to get around that. Perhaps others have found a way.

A thought occurs; does RS provide mechanisms for one to write their own PPX? Perhaps I could write a dummy PPX of sorts that processes [@@deriving yojson] by doing nothing at all.

If there are any good resources / examples for this, I haven’t found them yet :^)

I might be wrong, but I think @deriving is a protected annotation in rescript now.

One solution could be to add those annotations to the interface file only, and have different interface files for native ocaml and rescript.