Using the most recent version of zarith with opam - ocaml

I am using zarith for handling arbitrary sized integers.
The most recent version I could find on opam.ocaml.org was v1.9.1 (published in August 2019). On the project's github page I read Latest commit a9a309d on 23 Jan (2020).
I'd like to switch to the newer version, but how do I do that? I want to
keep opam happy, and
always use the most current version of zarith.
Please help!

Indeed, currently 1.9.1 is both the latest version of Zarith available as an opam package (https://opam.ocaml.org/packages/zarith/) and as a GitHub tag (https://github.com/ocaml/Zarith/tags).
However, given this upstream Git repository also contains an .opam specification file, you can just as well use opam to install the latest development version available in the master branch, or if need be, a precise Git commit just by relying on the so-called pinning feature of opam.
So, you can run alternatively:
opam pin add -n -y -k git zarith.dev --dev-repo
or
opam pin add -n -y -k git zarith.dev "https://github.com/ocaml/Zarith.git#master"
or
opam pin add -n -y -k git zarith.dev "https://github.com/ocaml/Zarith.git#a9a309d0596d93b6c0c902951e1cae13d661bebd"
Then:
opam install zarith
Further details on the opam-pin command
The .dev version suffix is unneeded syntactically, but is recommended actually, as the zarith.opam file does not specify any version. To be more precise:
If you have other dependencies that would complain of zarith.dev when being installed, you can replace the version suffix of dev with any compatible version string, "close" to the commit or branch you selected.
However if you omit this version, opam will typically pick the latest version string from the opam package repository (i.e., 1.9.1), which wouldn't necessarily match the code of the Git branch or commit you selected.
-n, -y, and -k are the short form of the options:
--no-action (don't install the package readily but wait the subsequent opam install command),
--yes (answer potential yes/no questions without prompting − a common opam pin question is Package foo does not exist, create as a NEW package? [Y/n] if ever you'd want to install a custom package not yet released in the opam-repository),
--kind=KIND (as there are several KINDS of pinning, the most typical being version, path, and git)

If you really need to use the unreleased, in-development version of zarith you can use the --dev-repo option of opam pin add:
opam pin add --dev-repo zarith
opam install zarith

Related

How does one pin/freeze a version of the dependencies of an opam project/package and then install the project with such specified dependencies?

How do we freeze an entire dependency tree/chain from an already working opam install?
I have a bunch of coq projects installed via opam right now. I'd like to figure out what commit they are using for their current install. I want to know this -- ideally automatically -- such that the opam pkgs/projects and their dependencies are pinned/fixed/frozen so that future opam installs/pins on the never break on them. For example if I knew the commit I could construct the opam switch need and install it with:
eval $(opam env --switch=coq-8.10 --set-switch)
opam pin add coq-metalib https://github.com/plclub/metalib/commits/104fd9efbfd048b7df25dbac7b971f41e8e67897
how do I do this? at the very least I'd like to be able to get commits like 104fd9efbfd048b7df25dbac7b971f41e8e67897 from opam installs that are already working.
How to automatically determine the git commit to make a permanent opam pin add url.git#commit install?
If I have a working set-up with opam. How do I get all the git commits for each opam project/package I have so to make the current install permanent? e.g. some projects it seems in coq get over written in the OPAM official repo so I want to lock those with git commits. So far manually checking them works:
eval $(opam env --switch=coq-8.10 --set-switch)
opam pin add -y coq-metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897
but I have a massive list of opam packages working right now and would like to make their install robust with the git commits. e.g. all these work for now:
# --- Install all Opam Dependencies: 1. create opam switch needed 2. then install all opam dependencies & projs
opam list
# - Create the 8.10.2 switch
opam switch create coq-8.10 4.07.1
eval $(opam env --switch=coq-8.10 --set-switch)
opam pin add -y coq 8.10.2
# - Install dependency packages for 8.10
opam repo add coq-extra-dev https://coq.inria.fr/opam/extra-dev
# We don't need it in all opam switches due to incompatabilities: Run `opam repository add <coq-proj> --all-switches|--set-default' to use it in all existing switches, or in newly created switches, respectively. cmd: opam repository add coq-extra-dev --all-switches
opam repo add coq-released https://coq.inria.fr/opam/released
opam repo add psl-opam-repository https://github.com/uds-psl/psl-opam-repository.git
opam install -y coq-serapi
opam install -y coq-struct-tact
opam install -y coq-inf-seq-ext
opam install -y coq-smpl
opam install -y coq-int-map
opam install -y coq-pocklington
opam install -y coq-mathcomp-ssreflect coq-mathcomp-bigenough coq-mathcomp-algebra
opam install -y coq-fcsl-pcm
opam install -y coq-list-string
opam install -y coq-error-handlers
opam install -y coq-function-ninjas
opam install -y coq-algebra
opam install -y coq-zorns-lemma
opam pin -y add menhir 20190626
# coq-equations seems to rely on ocamlfind for it's build, but doesn't
# list it as a dependency, so opam sometimes tries to install
# coq-equations before ocamlfind. Splitting this into a separate
# install call prevents that. https://stackoverflow.com/questions/75452026/how-do-i-install-ocamlfind-first-properly-before-other-opam-packages-without-roo, untested for now
opam install -y ocamlfind
opam install -y coq-equations coq-metacoq coq-metacoq-checker coq-metacoq-template
# lin-alg-8.10 needs opam switch coq-8.10
git submodule add -f --name coq-projects/lin-alg-8.10 git#github.com:HazardousPeach/lin-alg-8.10.git coq-projects/lin-alg
git submodule update --init coq-projects/lin-alg
(cd coq-projects/lin-alg && make "$#" && make install)
# to confirm it installed look for lin-alg: https://github.com/UCSD-PL/proverbot9001/issues/81, for now you can confirm by trying to install it again and it all looks alright
#opam list
#opam list | grep lin-alg-8.10
# Install the psl base-library from source
mkdir -p deps
git clone -b coq-8.10 git#github.com:uds-psl/base-library.git deps/base-library
(cd deps/base-library && make "$#" && make install)
git clone git#github.com:davidnowak/bellantonicook.git deps/bellantonicook
(cd deps/bellantonicook && make "$#" && make install)
opam list | grep base-library
# -- Get cheerios, req to have old versions work in opam: https://github.com/uwplse/cheerios/issues/17
eval $(opam env --switch=coq-8.10 --set-switch)
# opam install might give issues since it gets the most recent version from the official OPAM repository
#opam -y install coq-cheerios
#opam install -y coq-verdi
# use opam pin since pin is created to install specific version (e.g. from git, local, etc.)
opam pin add coq-cheerios git+https://github.com/uwplse/cheerios.git#9c7f66e57b91f706d70afa8ed99d64ed98ab367
#opam pin add coq-cheerios https://github.com/uwplse/cheerios.git\#9c7f66e57b91f706d70afa8ed99d64ed98ab367d
#opam pin add coq-verdi https://github.com/uwplse/verdi/tree/f3ef8d77afcac495c0864de119e83b25d294e8bb
opam pin add coq-verdi git+https://github.com/uwplse/verdi.git#f3ef8d77afcac495c0864de119e83b25d294e8bb
# use opam pin since pin is created to install specific version (e.g. from git, local, etc.)
Context: installing proverbot9001 coq-projects dependencies that have their OPAM repo code overwritten by original authors
I have this issue were I try to install an opam package (coq project/pkg in my specific case) that I have downloaded/cloned via a git submodule and when I do try to opam install it it fails. It fails, although I have cloned the right version of the coq project/pkg. The source of failure is something I've been told here because it is imho very hard to infer/deduce that from the error message:
(iit_synthesis) brando9~ $ eval $(opam env --switch=coq-8.10 --set-switch)
(iit_synthesis) brando9~ $ opam install -y coq-cheerios
[ERROR] Package conflict!
* Missing dependency:
- coq >= 8.14
not available because the package is pinned to version 8.10.2
No solution found, exiting
it says a newer version of coq is needed but it's very confusing why that is the case. In python there is a setup.py or a requirements.txt file that makes all of this a little bit more clear (dependency management is always a pain afaik :( ).
I am wondering, is there such a file in opam where I can specify for the coq-projects I am using which version of the dependencies I need so I don't have to go back and fix everything? e.g. in python I'd do:
pip3 freeze > requirements.txt # Python3
pip freeze > requirements.txt # Python2
can I do this in ocaml? Ideally automatically. Even more ideally looping through all the coq-projs in my current repo under the folder coq-projects/ and create such a freeze of the dependencies for future installs? Once that is there how would I install the downloaded/cloned coq proj with the specified forzen dependencies?
Why can't we just extract the deps from a list like pip does? It's linear once a working installation is set up
I don't understand something about opam vs pip. Once a working installation is set up -- it's not a chain or recursive structure of installations. It's simply a list of installations that can be frozen with pip. Is that not possible with opam? If not why not and why is it so hard to fix?
Useful links
related discussion to solve this issue:
trying to get coq-cheerios & verdi to work by getting the right commits for them: https://github.com/uwplse/cheerios/issues/17 , trying to get support for cheerios for coq 8.10: https://github.com/uwplse/cheerios/issues/12
this is a related question I asked when I thought it was my cloning of the coq-projects I was going to build How does one git submodule add a specific commit and have it be recorded in the .modules files? but before I even build them I need to get their dependencies installed! e.g. via opam. Some proverbot installed from source :( and Idk how to fix those yet e.g. metalib: https://github.com/UCSD-PL/proverbot9001/issues/82
I might have an issue with coq-serapi too: https://github.com/UCSD-PL/proverbot9001/issues/78
when I thought creating my own forks would work https://github.com/UCSD-PL/proverbot9001/issues/83 but likely just getting the opam install/pin to work with the commit is better e.g. opam pin add coq-metalib https://github.com/plclub/metalib/commits/104fd9efbfd048b7df25dbac7b971f41e8e67897.
cross at ocaml discuss: https://discuss.ocaml.org/t/how-does-one-pin-freeze-a-version-of-the-dependencies-of-an-opam-project-package-and-then-install-the-project-with-such-specified-dependencies/11424
another discussion when running a giant set of opam installs: https://github.com/UCSD-PL/proverbot9001/issues/55
related & likely culprit of issues; is it true that OPAM allows none addative updates to their official repository of packages? https://discuss.ocaml.org/t/is-it-true-that-the-official-opam-repository-allows-non-additive-updates-to-the-projects-packages-pushed-to-it/11432
Yeah the problem here is that the Cheerios project used to be compatible with older versions of Coq, and other projects depend on that. In another package manager, you could just pin to the older version of Cheerios and everything that used that version would be fine. But in Opam there's no guarantee that having a working dependency chain at one time means there will always be a working dependency chain.
EDIT: I don't think opam lock would work here unless it's tarring up the packages or something, because opam is no longer aware of a version of Cheerios which is compatible with Coq 8.10. That version of Cheerios has been erased from the opam repositories, replaced with a newer version which is no longer compatible.
The cheerios coq project that you are building states explicitly that it is only compatible with Coq 8.14 and later in its README.md. I am not sure which part is confusing?
More generally, you can specify which versions of packages your project is compatible with in the dependency fields of your opam file.
If you need to freeze a dependency tree, you can also lock an opam package to depends on the installed versions of its dependencies with opam lock.

opam install error "no solution found"

I came across a bug when installing certain packages using opam.
> opam install foo
Sorry, no solution found: there seems to be a problem with your request.
No solution found, exiting
According to particular form of the error message I read you are using the opam v1.2 internal solver (which you can confirm via opam config report). This solver is no longer able to cope with the repository.
Either install an external solver, see here or switch to opam v2 (currently in rc) which bundles a decent solver.
Opam was using a version of the ocaml compiler that wasn't able to install this package. So unistall the current version and use opam switch to set opam to use the latest ocaml compiler.
> opam switch x.xx.x
Then make sure to update/upgrade opam.
> opam update
> opam upgrade

Opam switch install could not install the older version of ocaml (3.08.3)

I'm doing some works with ocaml and opam.
I need ocaml of version 3.08.3, so I tried install this version via opam.
opam switch install 3.08.3
The above command would install it successfully, I hoped. But it couldn't.
opam-switch could not install 3.* versions of ocaml with the following error message.
[ERROR] Could not resolve set of base packages
I searched this message everywhere, but I couldn't get any of hints. Does anyeone have a clue to solve this problem? Thanks.
compilers/3.08.3/3.08.3/3.08.3.comp, the file to describe the base packages for that compiler version tells:
packages: [
"base-unix"
"base-bigarray"
"base-threads"
"base-ocamlbuild"
]
So it requires base-unix, base-bigarray, base-threads and base-ocamlbuild. However, the package description of base-ocamlbuild, packages/base-ocamlbuild/base-ocamlbuild.base/opam says:
ocaml-version: [>= "3.10" & < "4.03"]
It says that ocamlbuild is not available before 3.10. Indeed, ocamlbuild was introduced since 3.10. It is likely that the compiler description file 3.08.3.comp has a bug. It is great if you would raise a bug ticket at https://github.com/ocaml/opam-repository/issues for the fix.
For a workaround, I recommend to install OCaml 3.08 by hand, not using OPAM command: I see almost no benefit to use OPAM with 3.08 where ocamlbuild is not available, since most of the OPAM packages assume the existence of ocamlbuild.
You could also create your own copy of OPAM repo with a fixed 3.08.3.comp file without "base-ocamlbuild". See the document of opam repo for more details.

How to upgrade a single package?

I did opam update and then opam upgrade, and now OPAM wants to upgrade 10 packages to more recent versions.
However, for fear of breaking something inadvertently, I'd like to upgrade a single package, without touching the others. This package has no dependencies and it seems that none of the other packages depends on it.
However, doing opam upgrade <package> results in the same thing as opam upgrade, that is, OPAM wants to upgrade all 10 packages, not just the one I want.
I even tried opam install <package>.<new version>, but it also wants to upgrade everything at once.
Is there a way to upgrade just this single package, without touching the rest? In theory nothing should break, but in practice it often happens...
I found out that doing
opam reinstall <package>.<new version>
allows me to obtain what I want, that is, install only package <package> and its dependencies, without upgrading unrelated packages.
OPAM emits a warning ([WARNING] <package>.<new version> is not installed.), but it proposes me to install it anyway.
Afterwards, despite some warnings about the destination directory not being empty (due to the already installed previous version), OPAM was able to install only the desired package, without upgrading everything.
Notice that the same thing happens if I try to install a new package: because my previous opam update added several packages to the update list, trying to install anything via opam install will trigger the "update everything" algorithm, while opam reinstall won't.
I don't know if this is undesired behavior, but if so, I hope that it will remain available in future OPAM versions, or that there will be a way to ignore unrelated upgrades.
Edit: as indicated in this OPAM Github issue, using --criteria=paranoid or --criteria=-changed,-notuptodate can also help with not modifying anything else.

Opam not getting latest packages

I just installed opam using the quick install
http://opam.ocaml.org/doc/Quick_Install.html
I now have
$opam --version
1.1.0
which is current. I ran "opam update" and "opam upgrade" to get the latest packages. However, when I install packages, it is still giving me the old versions (such as core 109.42 instead of core 109.55):
$ opam search core
Available packages for 4.01.0:
async_core 109.42.00 Monadic concurrency library
What do I need to do to get opam to give me the latest libraries?
If you previously built from source, make sure you uninstall that first. For whatever reason, even though the opam version correctly reports "1.1.0", it was still using the old repo address. After you uninstall old opam entirely, then follow the installation instructions at the link above.
You will know you succeeded when you do "opam update" and prints:
default Downloading http://opam.ocamlpro.com/urls.txt
[NOTE] The repository 'default' will be *permanently* redirected to https://opam.ocaml.org (opam-version >= "1.1.0")