Local Switches & Coswitches

A "local switch" is an OPAM switch whose name is a directory path; this will often be the working directory ./ (which OPAM will expand to an absolute path), but this is not a requirement. The switch itself is located in the ./_opam subdirectory.

OPAM commands detect the presence of an _opam subdirectory in the current directory and automatically set it as the current switch. This means than any opam commands executed in that directory will apply to that local switch.

OBazl can be configured to use an OPAM local switch as a project coswitch. The first step is to create the switch:

$ opam create . <compiler version> (1)
1 where <compiler version> is one of the version strings listed by $ opam switch list-available, e.g. 4.14.0 or 4.14.0+options.

This creates a switch named $(PWD) and located at $(PWD)/_opam. To see the expanded switch name, run $ opam switch show.

$ bazel run @opam//local
$ bazel run @opam//local:import
$ bazel run @opam//local:export
$ bazel run @opam//local:refresh