Basic Oasis or Opam file for a simple OCaml project
Asked Answered
P

1

6

I am a new OCaml user. I have asked a question to learn how to set up a basic OCaml project, but I still have issues. Jump to the end for a TL;DR

For instance, I am trying to learn Irmin. On the home page of Irmin I see I have to do

opam install irmin git cohttp

Doing so, I end up with Irmin version 0.8.3. Unfortunately, I cannot follow their examples, because apparently Irmin is at version 0.9.4, and it looks like the API has changed. So, I would like to start a clean project having as dependency just Irmin 0.9.4

First, I have set up an opam switch with

 opam switch install playground -A 4.02.1

to be sure to work on a clean slate. Then, I have created a basic _oasis file that looks like this

OASISFormat: 0.4
Name:        Playground
Version:     0.1.0
Synopsis:    OCaml playground
Authors:     Andrea Ferretti
License:     Apache-2.0
BuildTools: ocamlbuild

BuildDepends:
  irmin,
  irmin.unix,
  lwt,
  lwt.unix

and then I have copied the example from the Irmin homepage in example.ml.

open Lwt
open Irmin_unix
let store = Irmin.basic (module Irmin_git.FS) (module Irmin.Contents.String)
let config = Irmin_git.config ~root:"/tmp/irmin/test" ~bare:true ()
let prog =
  Irmin.create store config task >>= fun t ->
  Irmin.update (t "Updating foo/bar")  ["foo"; "bar"] "hi!" >>= fun () ->
  Irmin.read_exn (t "Reading foo/bar") ["foo"; "bar"] >>= fun x ->
  Printf.printf "Read: %s\n%!" x;
  return_unit
let () = Lwt_main.run prog

If I do oasis setup and then ocamlbuild example.ml I get a bunch of errors

W: Cannot get variable ext_obj
W: Cannot get variable ext_lib
W: Cannot get variable ext_dll
W: Cannot get variable ocamlfind

So in short my question is:

What is the simplest way to set up a clean project that depends on Irmin 0.9.4, being sure that it is self-contained (it will not rely on preinstalled libraries other than those installed by the build process)?

Patriarchate answered 9/3, 2015 at 13:55 Comment(3)
Irmin is noted as 0.9.3 in the official repository. Is it a typo in your question or did you forgot to do a opam update for a long time?Krieg
he also might have some dependencies forcing him to downgrade. Although, I had no problem with installing that with a fair amount of packages installed.Vito
that's a usual problem when you don't have aspcud. Many times it downgrades everything.Trisect
T
4

So, first of all your don't have any active targets in your _oasis file. What I mean, is that OASIS is about building exectuables and libraries. You haven't described either. That means, that your BuildDepends doesn't have any effect, since it has only sense for Library and Executable entries. So, a first approximation would be the following:

OASISFormat: 0.4
Name:        Playground
Version:     0.1.0
Synopsis:    OCaml playground
Authors:     Andrea Ferretti
License:     Apache-2.0
BuildTools:   ocamlbuild
BuildDepends: irmin.unix, lwt.unix

Executable "example"
  Path: .
  MainIs: example.ml
  CompiledObject: best

Doing so, I end up with Irmin version 0.8.3. Unfortunately, I cannot follow their examples, because apparently Irmin is at version 0.9.4, and it looks like the API has changed. So, I would like to start a clean project having as dependency just Irmin 0.9.4

If you got a version that is not the newest, then you can try to persuade opam constraint solver, that you really need that specific version, like:

 opam install irmin.0.9.4 git cohttp

Also, opam internal constraint solver isn't very sophisticated, so make sure that you have aspcud installed on your system. The following will install the latest opam with aspcud on a fresh ubuntu installation:

sudo add-apt-repository --yes ppa:avsm/ppa
sudo apt-get update
sudo apt-get --yes install opam

What is the simplest way to set up a clean project that depends on Irmin 0.9.4, being sure that it is self-contained (it will not rely on preinstalled libraries other than those installed by the build process)?

Well, simplicity is a matter of personal opinion. For example, you can do the same without any oasis at all, just using opam file, where you set your build field, just to ["ocamlbuild"; "-use-ocamlfind"; "-pkgs irmin.unix,lwt.unix"; "example.native"], but how well it will scale...

Trisect answered 9/3, 2015 at 14:22 Comment(1)
Thank you, you are being really helpful!Patriarchate

© 2022 - 2024 — McMap. All rights reserved.