OPAM Configuration

OBazl supports three kinds of OPAM switch configuration:

  • System switch - installed by default in $(HOME)/.opam

    • Switches are named, user can specify the name

  • Local switch - installed in _opam, a subdirectory of a specified directory, usually $(PWD)

    • The installation directory containing _opam is treated as the name of the switch

    • Local switches use information in the system OPAM root ~/.opam, e.g. ~/.opam/repo

  • Here switch - installed in <projroot>/.opam

    • TODO: make it <projroot>/.obazl.d/_opam

    • Here switch initialization also creates an OPAM root, so they are independent of the system OPAM root

All three may be used as the basis of a project’s OBazl coswitch.

System Switches

Local Switches

A "local switch" is an OPAM switch whose name is a directory path; usually this will be the working directory ./ (which OPAM will expand to an absolute path). The switch itself is located in the ./_opam subdirectory. OPAM commands detect the presence of ./_opam and automatically set it as the current switch.

Cmd: $ opam create . --packages <pkg1>,<pkg2>…​

This creates a switch in the global OPAM installation (default location: $HOME/.opam), named $(PWD) and located at $(PWD)/_opam. To see the expanded switch name, run $ opam switch show.

OBazl can be configured to use a local directory switch as a project here-coswitch; see Here-coswitch configuration and @opam//here:create for more information.

Compiler build variants

The OCaml compiler(s) are available in several buld variants, which are controlled by build options. For example, to use the flamba optimizers, you must build the compilers with the -flambda configuration option.

Under OPAM these build variations are exposed as installable "option packages", which will ensure that the compilers are built with the appropriate configuration options. They can be enabled via the following protocol:

  • install the +options version of the compiler, e.g. ocaml-variants.4.14.0+options instead of ocaml-base-compiler.4.14.0

  • install the desired option package, e.g. ocaml-option-flambda.

To list the available compiler packages, run

$ opam switch list-available
$ opam switch list-available
# Listing available compilers from repositories: default
# Name                                 # Version                              # Synopsis
ocaml-option-32bit                     1                                      Set OCaml to be compiled in 32-bit mode for 64-bit Linux and OS X hosts
ocaml-option-afl                       1                                      Set OCaml to be compiled with afl-fuzz instrumentation
.
.
.
ocaml-base-compiler                    4.14.0~alpha1                          First alpha release of OCaml 4.14.0
ocaml-variants                         4.14.0~alpha1+options                  First alpha release of OCaml 4.14.0
ocaml-base-compiler                    4.14.0~alpha2                          Second alpha release of OCaml 4.14.0
ocaml-variants                         4.14.0~alpha2+options                  Second alpha release of OCaml 4.14.0
ocaml-base-compiler                    4.14.0~beta1                           First beta release of OCaml 4.14.0
ocaml-variants                         4.14.0~beta1+options                   First beta release of OCaml 4.14.0
ocaml-base-compiler                    4.14.0~rc1                             First release candidate of OCaml 4.14.0
ocaml-variants                         4.14.0~rc1+options                     First release candidate of OCaml 4.14.0
ocaml-base-compiler                    4.14.0~rc2                             Second release candidate of OCaml 4.14.0
ocaml-variants                         4.14.0~rc2+options                     Second release candidate of OCaml 4.14.0
ocaml-base-compiler                    4.14.0                                 Official release 4.14.0
ocaml-variants                         4.14.0+options                         Official release of OCaml 4.14.0
ocaml-variants                         4.14.1+trunk                           Latest 4.14.1 development
ocaml-variants                         5.0.0+trunk                            Current trunk

To list the available option packages, run

$ opam search ocaml-option
$ opam search ocaml-option
# Packages matching: match(*ocaml-option*)
# Name                                 # Installed # Synopsis
ocaml-option-32bit                     --          Set OCaml to be compiled in 32-bit mode for 64-bit Linux and OS X hosts
ocaml-option-afl                       --          Set OCaml to be compiled with afl-fuzz instrumentation
ocaml-option-bytecode-only             --          Compile OCaml without the native-code compiler
ocaml-option-default-unsafe-string     --          Set OCaml to be compiled without safe strings by default
ocaml-option-flambda                   --          Set OCaml to be compiled with flambda activated
ocaml-option-fp                        --          Set OCaml to be compiled with frame-pointers enabled
ocaml-option-musl                      --          Set OCaml to be compiled with musl-gcc
ocaml-option-nnp                       --          Set OCaml to be compiled with --disable-naked-pointers
ocaml-option-nnpchecker                --          Set OCaml to be compiled with --enable-naked-pointers-checker
ocaml-option-no-flat-float-array       --          Set OCaml to be compiled with --disable-flat-float-array
ocaml-option-spacetime                 --          Set OCaml to be compiled with spacetime activated
ocaml-option-static                    --          Set OCaml to be compiled with musl-gcc -static
ocaml-options-only-afl                 --          Ensure that OCaml is compiled with AFL support enabled, and no other custom options
ocaml-options-only-flambda             --          Ensure that OCaml is compiled with flambda activated, and no other custom options
ocaml-options-only-flambda-fp          --          Ensure that OCaml is compiled with flambda and frame-pointer enabled, and no other custom options
ocaml-options-only-fp                  --          Ensure that OCaml is compiled with only frame-pointer enabled, and no other custom options
ocaml-options-only-nnp                 --          Ensure that OCaml is compiled with no-naked-pointers, and no other custom options
ocaml-options-only-nnpchecker          --          Ensure that OCaml is compiled with enable-naked-pointers-checker, and no other custom options
ocaml-options-only-no-flat-float-array --          Ensure that OCaml is compiled with no-flat-float-array, and no other custom options
ocaml-options-vanilla                  1           Ensure that OCaml is compiled with no special options enabled

Examples:

  • Create a local switch with compiler version 4.14.0 with flambda support:

    opam switch create . --packages=ocaml-variants.4.14.0+options,ocaml-option-flambda

Here switches