diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml index 7b53d08d1e..5ee02d9449 100644 --- a/.github/workflows/docker_image.yml +++ b/.github/workflows/docker_image.yml @@ -9,6 +9,7 @@ on: - 'scripts/properties.sh' - 'scripts/setup-android-sdk.sh' - 'scripts/setup-ubuntu.sh' + - 'scripts/setup-cgct.sh' schedule: - cron: '0 2 * * 0' workflow_dispatch: diff --git a/scripts/Dockerfile b/scripts/Dockerfile index dfa9723b1c..54d2c3b6ba 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -10,7 +10,7 @@ FROM ubuntu:22.04 ENV LANG en_US.UTF-8 # Needed for setup: -COPY ./setup-ubuntu.sh ./setup-android-sdk.sh ./properties.sh ./openjdk-r-ppa.gpg /tmp/ +COPY ./setup-ubuntu.sh ./setup-android-sdk.sh ./setup-cgct.sh ./properties.sh ./openjdk-r-ppa.gpg /tmp/ RUN mkdir /tmp/build COPY ./build/termux_download.sh /tmp/build/ @@ -23,6 +23,7 @@ RUN apt-get update && \ chmod 0440 /etc/sudoers.d/builder && \ su - builder -c /tmp/setup-ubuntu.sh && \ su - builder -c /tmp/setup-android-sdk.sh && \ + su - builder -c /tmp/setup-cgct.sh && \ # Removed unused parts to make a smaller Docker image: apt-get remove -yq --autoremove lsb-release software-properties-common && \ apt-get clean && \ diff --git a/scripts/setup-cgct.sh b/scripts/setup-cgct.sh new file mode 100755 index 0000000000..db24aa7745 --- /dev/null +++ b/scripts/setup-cgct.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +. $(dirname "$(realpath "$0")")/properties.sh +. $(dirname "$(realpath "$0")")/build/termux_download.sh + +set -e -u + +ARCH="x86_64" +REPO_URL="https://service.termux-pacman.dev/gpkg-dev/${ARCH}" +VERSION_OF_CBT="2.41-0" +VERSION_OF_CGT="13.2.0-1" + +if [ "$ARCH" != "$(uname -m)" ]; then + echo "Error: the requested CGCT is not supported on your architecture" + exit 1 +fi + +declare -A CGCT=( + ["cbt"]="cbt-${VERSION_OF_CBT}-${ARCH}.pkg.tar.xz" + ["cgt"]="cgt-${VERSION_OF_CGT}-${ARCH}.pkg.tar.xz" +) + +: "${TERMUX_PKG_TMPDIR:="/tmp"}" +TMPDIR_CGCT="${TERMUX_PKG_TMPDIR}/cgct" + +# Creating a directory for CGCT in tmp +if [ ! -d "$TMPDIR_CGCT" ]; then + mkdir -p "$TMPDIR_CGCT" +fi + +# Removing the old CGCT +if [ -d "$CGCT_DIR" ]; then + echo "Removing the old CGCT..." + rm -fr "$CGCT_DIR" +fi + +# Installing CGCT +echo "Installing CGCT..." +curl "${REPO_URL}/gpkg-dev.json" -o "${TMPDIR_CGCT}/cgct.json" +for pkgname in ${!CGCT[@]}; do + SHA256SUM=$(jq -r '."'$pkgname'"."SHA256SUM"' "${TMPDIR_CGCT}/cgct.json") + if [ "$SHA256SUM" = "null" ]; then + echo "Error: package '${pkgname}' not found" + exit 1 + fi + filename="${CGCT[$pkgname]}" + filename_of_json=$(jq -r '."'$pkgname'"."FILENAME"' "${TMPDIR_CGCT}/cgct.json") + if [ "$filename" != "$filename_of_json" ]; then + echo "Error: files do not match: requested - '$filename'; actual - '$filename_of_json'" + exit 1 + fi + if [ ! -f "${TMPDIR_CGCT}/${filename}" ]; then + termux_download "${REPO_URL}/${filename}" \ + "${TMPDIR_CGCT}/${filename}" \ + "$SHA256SUM" + fi + tar xJf "${TMPDIR_CGCT}/${filename}" -C / data +done + +# Installing glibc for CGCT +if [ ! -d "${CGCT_DIR}/lib" ]; then + echo "Installing glibc for CGCT..." + for i in glibc gcc-libs; do + curl -L "https://archlinux.org/packages/core/${ARCH}/${i}/download/" -o "${TMPDIR_CGCT}/${i}.pkg.zstd" + tar --use-compress-program=unzstd -xf "${TMPDIR_CGCT}/${i}.pkg.zstd" -C "${TMPDIR_CGCT}" usr + done + cp -r "${TMPDIR_CGCT}/usr/lib" "${CGCT_DIR}/lib" +fi + +# Setting up CGCT for this glibc +echo "Setting up CGCT for this glibc..." +LD_LIB=$(ls ${CGCT_DIR}/lib/ld-* 2> /dev/null) +if [ ! -n "$LD_LIB" ]; then + echo "Error: interpreter not found in lib directory" + exit 1 +fi +for i in aarch64 arm x86_64 i686; do + for j in bin lib/gcc; do + for f in $(find "${CGCT_DIR}/${i}/${j}" -type f -exec grep -IL . "{}" \; | grep -v -e '\.a' -e '\.o' -e '\.so'); do + patchelf --set-rpath "${CGCT_DIR}/lib:/usr/lib:/usr/lib64" \ + --set-interpreter "$LD_LIB" "$f" + echo "Configured '${f}'" + done + done +done diff --git a/scripts/setup-ubuntu.sh b/scripts/setup-ubuntu.sh index 5978ddf90a..b308222868 100755 --- a/scripts/setup-ubuntu.sh +++ b/scripts/setup-ubuntu.sh @@ -292,6 +292,12 @@ PACKAGES+=" libwebp7 libwebp7:i386 libwebp-dev" PACKAGES+=" libwebpdemux2 libwebpdemux2:i386" PACKAGES+=" libwebpmux3 libwebpmux3:i386" +# Required by CGCT +PACKAGES+=" libdebuginfod-dev" + +# Needed to set up CGCT and also to set up other packages +PACKAGES+=" patchelf" + # Do not require sudo if already running as root. if [ "$(id -u)" = "0" ]; then SUDO=""