On a Mac M1, it is possible to install two versions of the OCaml toolchain with opam: either compiled for the x86_64 architecture (and run using Rosetta 2) or for the arm64 architecture (and run nativelly). The former is what happens, IIUC, if you run the install process from a Rosetta-2 terminal.
Is it possible to have both versions installed in two different opam switches ?
#!/bin/sh
set -e
if test $# -lt 1 ; then
echo "$0 requires at least 1 argument."
exit 1
fi
arch=$1
shift
opam var --global "arch=$arch"
arch "-$arch" opam "$@"
which sets the arch opam variable and lunch opam with whichever argument you gave using Rosetta2 if needed.
Examples:
./custom_opam.sh x86_64 list # equivalent to opam list under Rosetta2
./custom_opam.sh arm64 list # basically just opam list
You could also switch automatically to the appropriate switch in this script.
An alternative would be to use two different OPAMROOT to separate x86_64 and arm64 installations