| 1 | #!/usr/bin/env bash |
| 2 | # Runs a command in this app's x86 opam switch (.cache/opam-x86), creating |
| 3 | # it on first use. The compiler is the bakeoff's OCaml 5.3.0, used as |
| 4 | # ocaml-system; libraries, SQLite included, are compiled into .cache. |
| 5 | # tools/x86.sh <command> [args...] |
| 6 | set -euo pipefail |
| 7 | app=$(cd "$(dirname "$0")/.." && pwd) |
| 8 | cache=$app/.cache |
| 9 | source "$app/../../scripts/env.sh" |
| 10 | ocaml_bin=$(dirname "$(readlink -f "$(command -v ocamlopt)")") |
| 11 | unset OPAMSWITCH OPAM_SWITCH_PREFIX OPAM_LAST_ENV CAML_LD_LIBRARY_PATH OCAML_TOPLEVEL_PATH OCAMLTOP_INCLUDE_PATH MANPATH |
| 12 | export OPAMROOT=$cache/opam-x86 OPAMYES=1 OPAMCOLOR=never DUNE_CACHE=disabled |
| 13 | |
| 14 | # opam ignores compilers inside another opam root, so expose this one by |
| 15 | # symlink. docs-t1 has no pkg-config; Debian's is unpacked into .cache. |
| 16 | bin=$cache/x86-bin |
| 17 | if [ ! -x "$bin/pkg-config" ]; then |
| 18 | mkdir -p "$bin" "$cache/debs" |
| 19 | for f in "$ocaml_bin"/ocaml*; do ln -sf "$f" "$bin/"; done |
| 20 | (cd "$cache/debs" && apt-get download -q pkgconf-bin libpkgconf3 >/dev/null) |
| 21 | for d in "$cache"/debs/*.deb; do dpkg-deb -x "$d" "$cache/x86-sysroot"; done |
| 22 | cat > "$bin/pkg-config" <<EOS |
| 23 | #!/bin/sh |
| 24 | root=$cache/x86-sysroot |
| 25 | LD_LIBRARY_PATH=\$root/usr/lib/x86_64-linux-gnu PKG_CONFIG_LIBDIR=$cache/sqlite-x86/lib/pkgconfig \\ |
| 26 | exec \$root/usr/bin/pkgconf "\$@" |
| 27 | EOS |
| 28 | chmod +x "$bin/pkg-config" |
| 29 | fi |
| 30 | export PATH=$bin:/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin |
| 31 | |
| 32 | "$app/tools/sqlite.sh" fetch |
| 33 | "$app/tools/sqlite.sh" build "$cache/sqlite-x86" |
| 34 | if [ ! -d "$OPAMROOT/default" ]; then |
| 35 | [ -f "$OPAMROOT/config" ] || opam init -q --bare -n --disable-sandboxing default https://opam.ocaml.org |
| 36 | opam switch remove -q default >/dev/null 2>&1 || true # forget one make clean-deps deleted |
| 37 | opam switch create -q default ocaml-system.5.3.0 |
| 38 | fi |
| 39 | if [ ! -f "$OPAMROOT/default/.deps-installed" ] || [ "$app/todo_ocaml.opam.locked" -nt "$OPAMROOT/default/.deps-installed" ]; then |
| 40 | (cd "$app" && opam install -q --switch default --deps-only --with-test $([ -f todo_ocaml.opam.locked ] && echo --locked) --assume-depexts .) |
| 41 | touch "$OPAMROOT/default/.deps-installed" |
| 42 | fi |
| 43 | exec opam exec --switch default -- "$@" |
| 44 | |