Files
gps/setup_tools.sh

114 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Reproducible Linux x86_64 SoC generation tool setup.
# Installs only host-side Scala/Chisel/CIRCT tools. The RISC-V bare-metal
# toolchain remains an external dependency selected by source.sh.
TOOLS_ROOT="${SOC_TOOLS_ROOT:-/tools/soc-tools}"
JDK_VERSION="17.0.19+10"
MILL_VERSION="0.11.1"
FIRTOOL_VERSION="1.151.0"
Z3_VERSION="4.16.0"
JDK_ARCHIVE="OpenJDK17U-jdk_x64_linux_hotspot_17.0.19_10.tar.gz"
JDK_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.19%2B10/$JDK_ARCHIVE"
JDK_SHA256="d8afc263758141a66e0e3aafc321e783f7016696f4eaea067d340a269037d331"
MILL_URL="https://github.com/com-lihaoyi/mill/releases/download/$MILL_VERSION/$MILL_VERSION"
MILL_SHA256="ebe83649cd63acd33608f6d14452c074be2ed7d00cd2f69f88573d3f6909774f"
CIRCT_ARCHIVE="firrtl-bin-linux-x64.tar.gz"
CIRCT_URL="https://github.com/llvm/circt/releases/download/firtool-$FIRTOOL_VERSION/$CIRCT_ARCHIVE"
CIRCT_SHA256="10bf9b135a65e5d93fb0555e967eac4258400ee629731ba68a69be6b7f9781ce"
Z3_ARCHIVE="z3-$Z3_VERSION-x64-glibc-2.39.zip"
Z3_URL="https://github.com/Z3Prover/z3/releases/download/z3-$Z3_VERSION/$Z3_ARCHIVE"
Z3_SHA256="7288c49a5bd6dbafd7b0b0d1f65956b91672da24b08f09242919af159be3418e"
if [[ "$(uname -s)" != Linux || "$(uname -m)" != x86_64 ]]; then
printf 'Unsupported host: %s-%s (this lock file is for Linux-x86_64)\n' "$(uname -s)" "$(uname -m)" >&2
exit 2
fi
for command_name in curl sha256sum tar unzip find; do
command -v "$command_name" >/dev/null || {
printf 'Missing required command: %s\n' "$command_name" >&2
exit 2
}
done
if [[ -w "$(dirname "$TOOLS_ROOT")" ]] || [[ -w "$TOOLS_ROOT" ]]; then
SUDO=()
else
command -v sudo >/dev/null || {
printf '%s is not writable and sudo is unavailable\n' "$TOOLS_ROOT" >&2
exit 2
}
SUDO=(sudo)
fi
work_dir="$(mktemp -d "${TMPDIR:-/tmp}/soc-tools.XXXXXXXX")"
trap 'rm -rf "$work_dir"' EXIT
download() {
local url="$1" output="$2" sha256="$3"
printf 'Downloading %s\n' "$(basename "$output")"
curl --fail --location --retry 3 --output "$output" "$url"
printf '%s %s\n' "$sha256" "$output" | sha256sum --check --status || {
printf 'Checksum mismatch: %s\n' "$output" >&2
exit 1
}
}
install_tree() {
local source_dir="$1" destination="$2"
"${SUDO[@]}" rm -rf "$destination.tmp"
"${SUDO[@]}" mkdir -p "$(dirname "$destination")"
"${SUDO[@]}" cp -a "$source_dir" "$destination.tmp"
"${SUDO[@]}" rm -rf "$destination"
"${SUDO[@]}" mv "$destination.tmp" "$destination"
}
"${SUDO[@]}" mkdir -p "$TOOLS_ROOT"
if [[ ! -x "$TOOLS_ROOT/jdks/jdk-$JDK_VERSION/bin/java" ]]; then
download "$JDK_URL" "$work_dir/$JDK_ARCHIVE" "$JDK_SHA256"
mkdir -p "$work_dir/jdk"
tar -xzf "$work_dir/$JDK_ARCHIVE" -C "$work_dir/jdk"
install_tree "$work_dir/jdk/jdk-$JDK_VERSION" "$TOOLS_ROOT/jdks/jdk-$JDK_VERSION"
fi
if [[ ! -x "$TOOLS_ROOT/mill/$MILL_VERSION/mill" ]]; then
download "$MILL_URL" "$work_dir/mill" "$MILL_SHA256"
"${SUDO[@]}" mkdir -p "$TOOLS_ROOT/mill/$MILL_VERSION"
"${SUDO[@]}" install -m 0755 "$work_dir/mill" "$TOOLS_ROOT/mill/$MILL_VERSION/mill"
fi
if ! "$TOOLS_ROOT/circt/firtool-$FIRTOOL_VERSION/bin/firtool" --version \
>/dev/null 2>&1; then
download "$CIRCT_URL" "$work_dir/$CIRCT_ARCHIVE" "$CIRCT_SHA256"
mkdir -p "$work_dir/circt"
tar -xzf "$work_dir/$CIRCT_ARCHIVE" -C "$work_dir/circt"
firtool_path="$(find "$work_dir/circt" -type f -path '*/bin/firtool' -print -quit)"
[[ -n "$firtool_path" ]] || { printf 'firtool not found in CIRCT archive\n' >&2; exit 1; }
install_tree "$(dirname "$(dirname "$firtool_path")")" "$TOOLS_ROOT/circt/firtool-$FIRTOOL_VERSION"
fi
if [[ ! -f "$TOOLS_ROOT/z3/$Z3_VERSION/bin/libz3.so" ]]; then
download "$Z3_URL" "$work_dir/$Z3_ARCHIVE" "$Z3_SHA256"
mkdir -p "$work_dir/z3"
unzip -q "$work_dir/$Z3_ARCHIVE" -d "$work_dir/z3"
z3_path="$(find "$work_dir/z3" -type f -path '*/bin/libz3.so' -print -quit)"
[[ -n "$z3_path" ]] || { printf 'libz3.so not found in Z3 archive\n' >&2; exit 1; }
install_tree "$(dirname "$(dirname "$z3_path")")" "$TOOLS_ROOT/z3/$Z3_VERSION"
fi
"${SUDO[@]}" ln -sfn "jdks/jdk-$JDK_VERSION" "$TOOLS_ROOT/jdk17"
"${SUDO[@]}" ln -sfn "mill/$MILL_VERSION/mill" "$TOOLS_ROOT/mill-current"
"${SUDO[@]}" ln -sfn "circt/firtool-$FIRTOOL_VERSION" "$TOOLS_ROOT/circt-current"
"${SUDO[@]}" ln -sfn "z3/$Z3_VERSION" "$TOOLS_ROOT/z3-current"
printf '\nInstalled SoC tools in %s\n' "$TOOLS_ROOT"
printf 'Run: source %q/source.sh && make doctor\n' "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"