Files
roc-lang-tools/scripts/download-roc.sh
T
2026-06-04 15:35:52 -04:00

80 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROC_VERSION="${1:?Usage: $0 <roc-version> [target-arch]}"
TARGETARCH="${2:-amd64}"
# Map Docker buildx arch names to Roc tarball arch names
case "$TARGETARCH" in
amd64) ROC_ARCH="x86_64" ;;
arm64) ROC_ARCH="aarch64" ;;
*) echo "Unsupported architecture: $TARGETARCH" >&2; exit 1 ;;
esac
# Use the GitHub API to find the correct asset URL for this version + arch.
# We can't construct the URL from the version string because Roc release
# tarball naming is inconsistent across releases (e.g. 0.0.0-alpha1 uses
# "roc-linux_x86_64-0-alpha1.tar.gz" while alpha4-rolling uses
# "roc-linux_x86_64-alpha4-rolling.tar.gz").
# awk is used instead of jq/python because neither is guaranteed in slim images.
API_URL="https://api.github.com/repos/roc-lang/roc/releases/tags/${ROC_VERSION}"
echo "Looking up release ${ROC_VERSION} via GitHub API..."
curl -fsSL "$API_URL" -o /tmp/gh-release.json
ASSET_URL=$(awk -v arch="roc-linux_${ROC_ARCH}" '
/"browser_download_url"/ {
url = $2
gsub(/[",]/, "", url)
if (index(url, arch) > 0 && url ~ /\.tar\.gz$/) {
print url
exit
}
}
' /tmp/gh-release.json)
rm -f /tmp/gh-release.json
if [ -z "$ASSET_URL" ]; then
echo "ERROR: No linux ${ROC_ARCH} tarball found for release ${ROC_VERSION}" >&2
exit 1
fi
echo "Downloading Roc ${ROC_VERSION} for ${ROC_ARCH}..."
curl -fsSL "$ASSET_URL" -o /tmp/roc.tar.gz
echo "Extracting..."
tar -xzf /tmp/roc.tar.gz -C /tmp/
# The tarball contains a single directory with an unpredictable name
# e.g. roc_nightly-linux_x86_64-2025-09-09-d73ea109/
EXTRACTED_DIR=$(find /tmp -maxdepth 1 -type d -name "roc_*" | head -1)
if [ -z "$EXTRACTED_DIR" ]; then
echo "ERROR: Could not find extracted Roc directory in /tmp" >&2
exit 1
fi
echo "Installing to /opt/roc..."
mkdir -p /opt/roc/bin /opt/roc/lib
install -m 0755 "$EXTRACTED_DIR/roc" /opt/roc/bin/roc
# LSP may or may not be present in older releases; install if found
if [ -f "$EXTRACTED_DIR/roc_language_server" ]; then
install -m 0755 "$EXTRACTED_DIR/roc_language_server" /opt/roc/bin/roc_language_server
fi
# WASI libc is needed for some platforms
if [ -d "$EXTRACTED_DIR/lib" ]; then
cp -r "$EXTRACTED_DIR/lib/"* /opt/roc/lib/
fi
# License
if [ -f "$EXTRACTED_DIR/LICENSE" ]; then
cp "$EXTRACTED_DIR/LICENSE" /opt/roc/LICENSE
fi
# Cleanup
rm -rf /tmp/roc.tar.gz "$EXTRACTED_DIR"
echo "Roc ${ROC_VERSION} installed successfully."
/opt/roc/bin/roc --version