一个简单的OCaml项目的基本Oasis或Opam文件 [英] Basic Oasis or Opam file for a simple OCaml project

查看:167
本文介绍了一个简单的OCaml项目的基本Oasis或Opam文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OCaml的新用户.我问了一个问题,以了解如何设置基本的OCaml项目,但我仍然有问题.跳到最后一个TL; DR

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

例如,我正在尝试学习Irmin.在Irmin的主页上,我看到我必须做

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

这样做,我最终得到的是Irmin版本0.8.3.不幸的是,我无法遵循他们的示例,因为显然Irmin的版本为0.9.4,并且API似乎已更改.因此,我想开始一个仅依赖Irmin 0.9.4的干净项目

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

首先,我设置了一个opam开关

First, I have set up an opam switch with

 opam switch install playground -A 4.02.1

确保在干净的面板上工作.然后,我创建了一个基本的_oasis文件,如下所示:

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

,然后我从example.ml的Irmin主页中复制了示例.

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

如果我先执行oasis setup,然后又执行ocamlbuild example.ml,则会遇到一堆错误

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:

要建立一个依赖Irmin 0.9.4的干净项目,最简单的方法是什么,并确保它是独立的(除了构建过程中安装的库以外,它不依赖于预安装的库)?

推荐答案

因此,首先,您的_oasis文件中没有任何活动目标.我的意思是,OASIS与构建可执行文件和库有关.您也没有描述.这意味着您的BuildDepends没有任何作用,因为它仅对LibraryExecutable条目有意义.因此,第一近似为:

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

这样做,我最终得到的是Irmin版本0.8.3.不幸的是,我不能 遵循他们的示例,因为显然Irmin的版本为0.9.4, 而且API似乎已更改.所以,我想开始一个 作为依赖项的干净项目只有Irmin 0.9.4

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

如果您使用的不是最新版本,则可以尝试说服opam约束求解器,您确实需要该特定版本,例如:

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

此外,opam内部约束求解器不是很完善,因此请确保在系统上安装了aspcud.以下将在全新的ubuntu安装上安装带有aspcud的最新opam:

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

建立一个依赖Irmin 0.9.4的干净项目的最简单方法是什么,请确保它是独立的(它不会依赖 预先安装的库,而不是由构建安装的库 过程)?

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

好吧,简单性是个人观点的问题.例如,只需使用opam文件,将build字段设置为["ocamlbuild"; "-use-ocamlfind"; "-pkgs irmin.unix,lwt.unix"; "example.native"],就可以完全没有绿洲地进行同样的操作,但是缩放的效果如何……

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

这篇关于一个简单的OCaml项目的基本Oasis或Opam文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆