3 Compilation, Installation
4 =========================
14 The simplest way to install Why3 is via Opam, the OCaml package manager. It
21 Then jump to :numref:`sec.provers` to install external provers.
23 Why3 also provides a graphical user interface (see :numref:`sec.gui`
24 and :numref:`sec.ideref`), which can be installed using
30 Finally, the Opam package ``why3-coq`` provides realizations of Why3's
31 standard library, which are useful for doing interactive proofs using the
32 Coq formal system (see :numref:`chap.itp`).
34 Installation via Docker
35 ~~~~~~~~~~~~~~~~~~~~~~~
37 Instead of compiling Why3, one can also execute a precompiled version
38 (for *amd64* architecture) using Docker. The image containing Why3
39 as well as a few provers can be recovered using
43 docker pull registry.gitlab.inria.fr/why3/why3:|release|
44 docker tag registry.gitlab.inria.fr/why3/why3:|release| why3
46 Let us suppose that there is a file :file:`foo.mlw` in your current
47 directory. If you want to verify it using Z3, you can type
51 docker run --rm --volume `pwd`:/data --workdir /data why3 prove foo.mlw -P z3
53 If you want to verify :file:`foo.mlw` using the graphical user interface,
54 the invocation is slightly more complicated as the containerized
55 application needs to access your X server:
59 docker run --rm --network host --user `id -u` --volume $HOME/.Xauthority:/home/guest/.Xauthority --env DISPLAY=$DISPLAY --volume `pwd`:/data --workdir /data why3 ide foo.mlw
61 It certainly makes sense to turn this command line into a shell script for easier use:
66 exec docker run --rm --network host --user `id -u` --volume $HOME/.Xauthority:/home/guest/.Xauthority --env DISPLAY=$DISPLAY --volume `pwd`:/data --workdir /data why3 "$@"
68 It is also possible to run the graphical user interface from within a web
69 browser, thus alleviating the need for a X server. To do so, just set the
70 environment variable ``WHY3IDE`` to ``web`` and publish port 8080:
74 docker run --rm -p 8080:8080 --env WHY3IDE=web --user `id -u` --volume `pwd`:/data --workdir /data why3 ide foo.mlw
76 You can now point your web browser to http://localhost:8080/. As before,
77 this can be turned into a shell script for easier use:
82 exec docker --rm -p 8080:8080 --env WHY3IDE=web --user `id -u` --volume `pwd`:/data --workdir /data why3 "$@"
85 Installation from sources
86 ~~~~~~~~~~~~~~~~~~~~~~~~~
88 In short, installation from sources proceeds as follows.
96 After unpacking the distribution, go to the newly created directory
97 |whypath|. Compilation must start with a configuration phase which is
104 This analyzes your current configuration and checks if requirements
105 hold. Compilation requires:
107 - The Objective Caml compiler. It is available as a binary package for
108 most Unix distributions. For Debian-based Linux distributions, you
109 can install the packages
113 ocaml ocaml-native-compilers
115 It is also installable from sources, downloadable from the site
116 http://caml.inria.fr/ocaml/
118 For some of the Why3 tools, additional OCaml libraries are needed:
120 - For the graphical interface, the LablGtk3 library is needed. It
121 provides OCaml bindings of the GTK3 graphical library. For
122 Debian-based Linux distributions, you can install the packages
126 liblablgtk3-ocaml-dev liblablgtksourceview3-ocaml-dev
128 It is also installable from sources, available from the site
129 https://garrigue.github.io/lablgtk/
131 If you want to use the Coq realizations (:numref:`sec.realizations`),
132 then Coq has to be installed before Why3. Look at the summary printed at
133 the end of the configuration script to check if Coq has been detected
134 properly. Similarly, in order to use PVS (:numref:`sec.pvs`) or Isabelle
135 (:numref:`sec.isabelle`) to discharge proofs, PVS and Isabelle must be
136 installed before Why3. You should check that those proof assistants are
137 correctly detected by the :file:`configure` script.
139 When configuration is finished, you can compile Why3.
145 Installation is performed (as super-user if needed) using
151 Installation can be tested as follows:
153 #. install some external provers (see :numref:`sec.provers` below)
155 #. run :why3:tool:`why3 config`
157 #. run some examples from the distribution, e.g., you should obtain the
158 following (provided the required provers are installed on your
161 .. code-block:: console
164 $ why3 replay logic/scottish-private-club
166 $ why3 replay same_fringe
169 Local use, without installation
170 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172 Installing Why3 is not mandatory. It can be configured in a way such that
173 it can be used from its compilation directory:
177 ./configure --enable-local
180 The Why3 executable files are then available in the subdirectory :file:`bin/`.
181 This directory can be added to your :envvar:`PATH`.
185 Installation of the Why3 API
186 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188 By default, the Why3 API is not installed. It can be installed using
195 Beware that if your OCaml installation relies on Opam installed in your
196 own user space, then ``make install-lib`` should *not* be run as
199 Removing installation
200 ^^^^^^^^^^^^^^^^^^^^^
202 Removing installation can be done using
211 Installing External Provers
212 ---------------------------
214 Why3 can use a wide range of external theorem provers. These need to be
215 installed separately, and then Why3 needs to be configured to use them.
216 There is no need to install automatic provers, e.g., SMT solvers, before
217 compiling and installing Why3. For installation of external provers,
218 please refer to the specific section about provers from
219 https://www.why3.org/. (If you have installed Why3 via Opam, note that you can
220 install the SMT solver Alt-Ergo via Opam as well.)
222 Once you have installed a prover, or a new version of a prover, you have
223 to run the following command:
229 It scans your :envvar:`PATH` for provers and updates your configuration file
230 (see :numref:`sec.why3config`) accordingly.
232 Multiple versions of the same prover
233 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235 Why3 is able to use several versions of the same prover, e.g., it can use both
236 CVC4 1.4 and CVC4 1.5 at the same time. The automatic detection of
237 provers looks for typical names for their executable command, e.g., :program:`cvc4`
238 for CVC3. However, if you install several versions of the same prover it
239 is likely that you would use specialized executable names, such as
240 :program:`cvc4-1.4` or :program:`cvc4-1.5`. If needed, the command
241 :why3:tool:`why3 config add-prover` can be
242 used to specify names of prover executables:
246 why3 config add-prover CVC4 /usr/local/bin/cvc4-dev cvc4-dev
248 The first argument (here ``CVC4``) must be one of the known provers. The
249 list of these names can be obtained
250 using :why3:tool:`why3 config list-supported-provers`.
251 They can also be found in the file :file:`provers-detection-data.conf`,
252 typically located in :file:`/usr/local/share/why3` after installation. See
253 :numref:`sec.proverdetectiondata` for details.
255 .. _sec.uninstalledprovers:
257 Session update after prover upgrade
258 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260 If you happen to upgrade a prover, e.g., installing CVC4 1.5 in place of CVC4
261 1.4, then the proof sessions formerly recorded will still refer to the
262 old version of the prover. If you open one such a session with the GUI,
263 and replay the proofs, a popup window will show up for asking you to
264 choose between three options:
266 - Keep the former proof attempts as they are, with the old prover
267 version. They will not be replayed.
269 - Remove the former proof attempts.
271 - Upgrade the former proof attempts to an installed prover (typically
272 an upgraded version). The corresponding proof attempts will become
273 attached to this new prover, and marked as obsolete, to make their
274 replay mandatory. If a proof attempt with this installed prover is
275 already present the old proof attempt is just removed. Note that you
276 need to invoke again the replay command to replay those proof
279 - Copy the former proofs to an installed prover. This is a combination
280 of the actions above: each proof attempt is duplicated, one with the
281 former prover version, and one for the new version marked as
284 Notice that if the prover under consideration is an interactive one,
285 then the copy option will duplicate also the edited proof scripts,
286 whereas the upgrade-without-copy option will just reuse the former proof
289 Your choice between the three options above will be recorded, one for
290 each prover, in the Why3 configuration file. Within the GUI, you can
291 discard these choices via the :menuselection:`Files --> Preferences` dialog: just click on one choice to remove
294 Outside the GUI, the prover upgrades are handled as follows. The
295 :why3:tool:`replay` command will take into account any prover upgrade policy
296 stored in the configuration. The :why3:tool:`session` command performs move or
297 copy operations on proof attempts in a fine-grained way, using filters,
298 as detailed in :numref:`sec.why3session`.
301 .. _sec.installeditormodes:
303 Editing WhyML Sources
304 ---------------------
306 The Why3 distributions come with some configuration files for Emacs and for Vim.
307 These files are typically installed in the shared data directory,
308 which is given by :option:`why3 --print-datadir`.
313 The Why3 distributions come with a mode for Emacs in a file
314 :file:`why3.el`. That file is typically found in sub-directory
315 :file:`emacs`. Under OPAM, this file is installed in a shared
316 directory :file:`emacs/site-lisp` for all OPAM packages. Here is a
317 sample Emacs-Lisp code that can be added to your :file:`.emacs`
323 (if (boundp 'why3-share) why3-share
324 (ignore-errors (car (process-lines "why3" "--print-datadir")))))
326 (let ((f (expand-file-name "emacs/why3.elc" why3-share)))
327 (if (file-readable-p f) f
328 (when (and opam-share (file-directory-p opam-share))
329 (let ((f (expand-file-name "emacs/site-lisp/why3.elc" opam-share)))
330 (if (file-readable-p f) f nil))))))
331 (when why3el (require 'why3 why3el))
333 Notice that the code above checks the presence of the file
334 :file:`why3.el` in the OPAM repository using the :file:`opam-share`
335 variable, which is supposed to be set before, e.g. using
339 (setq opam-share (if (boundp 'opam-share) opam-share
340 (ignore-errors (car (process-lines "opam" "var" "share")))))
342 More generally, setting up a proper Emacs environment together with
343 OPAM can be done by installing the OPAM package :file:`user-setup` (see
344 https://opam.ocaml.org/packages/user-setup/).
349 Some configuration files are present in the share data directory, under sub-directory :file:`vim`.
352 .. _sec.installshellmodes:
354 Shells Auto-completion for Why3
355 -------------------------------
357 Some configuration files for shells are distributed in the shared data directory,
358 which is given by :option:`why3 --print-datadir`.
360 There are configuration files for ``bash`` and ``zsh``.
362 The configuration for ``bash`` can be made from Why3 sources using
366 sudo make install-bash
372 sudo /usr/bin/install -c `why3 --print-datadir`/bash/why3 /etc/bash_completion.d
375 .. _sec.installinferloop:
377 Inference of Loop Invariants
378 ----------------------------
380 This section shows how to install *infer-loop*, an utility based on
381 *abstract interpretation* to infer loop invariants
382 :cite:`baudin17`. This is still work in progress and many features are
385 The ``infer-loop`` utility has the following OCaml dependencies.
387 - ``apron``: can be installed using ``opam``.
389 - ``camllib``: can be installed using ``opam``.
391 - ``fixpoint``: follow instructions below.
393 The ``apron`` and ``camllib`` libraries can be installed using
394 ``opam``. The ``fixpoint`` library is not available in ``opam``, but
395 it can be easily compiled and installed using the source code. The
396 following commands are just an example of how the library can be
397 compiled and installed, and can be performed in any directory.
399 .. code-block:: shell
401 svn co svn://scm.gforge.inria.fr/svnroot/bjeannet/pkg/fixpoint
403 cp Makefile.config.model Makefile.config
404 # if required make modifications to Makefile.config
406 make install # uses ocamlfind to install the library
408 By default the *infer-loop* mechanism is not compiled and integrated
409 with Why3. So, once the dependencies above are installed, the
410 configuration script of Why3 should enable the compilation of the
411 ``infer-loop`` utility. This can be done by passing to the Why3
412 configure script the ``--enable-infer`` flag, as follows:
414 .. code-block:: console
416 $ ./configure --enable-infer
419 -----------------------------------------
421 Invariant inference(exp): yes
424 The line ``Invariant inference(exp)`` indicates whether the
425 dependencies are correctly installed and whether the flag mentioned
426 above was selected. After the compilation, the loop inference
427 mechanism should be available. See :numref:`sec.runwithinferloop` for