#!/bin/bash -e if ! command -v buildah > /dev/null; then echo install buildah 1.19.3 or later exit 1 fi bv=$(buildah --version) # translate to array of version components bv="${bv#buildah version }" bv="${bv% (*}" bv=(${bv//./ }) maj=${bv[0]} min=${bv[1]} patch=${bv[2]} ok=$(( maj > 1 || ( maj == 1 && min > 19 ) || ( maj == 1 && min == 19 && patch >= 3 ) )) if (( ! ok )); then echo install buildah 1.19.3 or later exit 1 fi if ! command -v reg > /dev/null; then echo install the reg command for registry inspection exit 1 fi if reg digest $( /dev/null; then echo "Toolchain image $( specify one of following build modes: SKIP: skip building optimized clang INSTALL: build and install an optimized clang compiler binary, and save it as a tarball. INSTALL_FROM: install optimized clang from a tarball. --clang-archive specify optimized clang tarball path --help this help snippet EOF } CLANG_BUILD="SKIP" while [[ $# -gt 0 ]]; do case "$1" in "--clang-build-mode") if [[ -z "$2" ]]; then usage exit 1 fi CLANG_BUILD="$2" shift 2 ;; "--clang-archive") if [[ -z "$2" ]]; then usage exit 1 fi CLANG_ARCHIVE="$(realpath -m --relative-to=. "$2")" shift 2 ;; "--help") usage exit 0 ;; *) usage exit 1 ;; esac done case "${CLANG_BUILD}" in "SKIP" | "INSTALL" | "INSTALL_FROM") ;; *) echo "Invalid mode specified on CLANG_BUILD: ${CLANG_BUILD}" exit 1 ;; esac # clang archive file need to be under scylla directory, since we only share # scylla directory with the container if [[ "${CLANG_ARCHIVE}" = "../"* ]]; then echo "clang archive file need to be under scylla directory" exit 1 fi # set default archive path if not specified if [[ -z "${CLANG_ARCHIVE}" ]]; then CURDIR="$(dirname "$0")" LLVM_CLANG_TAG="$(sed -n -e 's/^LLVM_CLANG_TAG=\(.*\)/\1/p' "${CURDIR}"/optimized_clang.sh)" IMAGE_ID="$(sed -e 's#docker.io/scylladb/scylla-toolchain:##' "${CURDIR}"/image)" CLANG_ARCHIVE="clang_build/optimized_clang_${LLVM_CLANG_TAG}_${IMAGE_ID}.$(arch).tar.gz" fi if [[ "${CLANG_BUILD}" = "INSTALL_FROM" ]] && [[ ! -f "${CLANG_ARCHIVE}" ]]; then echo "${CLANG_ARCHIVE}" does not exist. echo "Please specify vaild file with --clang-archive" exit 1 fi buildah bud --platform="linux/${docker_arch[$(arch)]}" --jobs 0 --squash --no-cache --pull -f tools/toolchain/Dockerfile --manifest "$(