Basic Oasis or Opam file for a simple OCaml project

一笑奈何 提交于 2019-12-10 13:08:46

问题


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)?


回答1:


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...



来源:https://stackoverflow.com/questions/28943745/basic-oasis-or-opam-file-for-a-simple-ocaml-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!