#!/bin/sh set -eu # Turmeric installer -- https://turmeric-lang.com # # Installs tvm (the Turmeric version manager) and then the latest release. # The release tarball is verified against the release's sha256sums.txt. # # TVM_DIR=~/somewhere install tvm elsewhere (default ~/.tvm) REPO="turmeric-lang/turmeric" API="${TUR_INSTALL_API:-https://api.github.com/repos/$REPO}" RAW="${TUR_INSTALL_RAW:-https://raw.githubusercontent.com/$REPO}" ASSETS="${TUR_INSTALL_ASSETS:-https://github.com/$REPO/releases/download}" have() { command -v "$1" >/dev/null 2>&1; } fetch() { if have curl; then curl -fsSL "$1" elif have wget; then wget -qO - "$1" else echo "The Turmeric installer needs curl or wget." >&2 exit 1 fi } # --- which release? -------------------------------------------------------- # Resolved at run time rather than baked in, so this script does not need # redeploying on every release. sed rather than jq: jq is not standard. TAG="$(fetch "$API/releases/latest" \ | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \ | head -n1)" if [ -z "$TAG" ]; then echo "Could not determine the latest Turmeric release." >&2 echo "Check https://github.com/$REPO/releases and install with tvm:" >&2 echo " https://github.com/turmeric-lang/tvm#readme" >&2 exit 1 fi VER="${TAG#v}" echo "Turmeric $VER" # --- bootstrap tvm, pinned to that release's tag --------------------------- TMP="$(mktemp -d "${TMPDIR:-/tmp}/tur-install.XXXXXX")" trap 'rm -rf "$TMP"' EXIT INT TERM mkdir -p "$TMP/tvm" for f in tvm.sh install.sh; do # tvm lives in turmeric-lang/tvm; the release workflow attaches the copy it # was tested with to each release. A release cut BEFORE that move has no such # asset but still has tvm/ in its tagged tree, so fall back to that. if ! fetch "$ASSETS/$TAG/$f" > "$TMP/tvm/$f" 2>/dev/null || [ ! -s "$TMP/tvm/$f" ]; then fetch "$RAW/$TAG/tvm/$f" > "$TMP/tvm/$f" || { echo "Could not download $f for $TAG." >&2; exit 1; } fi # A proxy that 200s an error page would otherwise be sourced as a shell # script. Non-empty is a weak check, but it is the cheap one worth having. [ -s "$TMP/tvm/$f" ] || { echo "$f downloaded empty." >&2; exit 1; } done sh "$TMP/tvm/install.sh" # --- install the compiler -------------------------------------------------- TVM_DIR="${TVM_DIR:-$HOME/.tvm}" # shellcheck disable=SC1090 . "$TVM_DIR/tvm.sh" # Branch on whether a prebuilt asset EXISTS for this host, not on whether the # install failed. Falling back to a source build on any error would quietly # paper over a checksum mismatch -- the one failure that must be loud. if __tvm_target >/dev/null 2>&1; then tvm install --activate "$VER" else echo "" echo "No prebuilt binary for $(uname -s)/$(uname -m) -- building $VER from source." echo "This needs cmake and a C compiler, and takes a few minutes." echo "" tvm install --build --activate "$VER" fi cat < Build main instead: brew install --HEAD ${REPO}/turmeric Playground: https://turmeric-lang.com/try EOF