From 04ce1fea52b392d61fa4cbcd6c9a934aa225879e Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:13:27 +0000 Subject: [PATCH] ci: deduplicate macOS SDK setup logic Co-authored-by: UdjinM6 --- .gitlab-ci.yml | 21 +++-------------- ci/dash/build_depends.sh | 13 ++--------- contrib/containers/guix/Dockerfile | 13 ++++++----- contrib/containers/guix/scripts/guix-start | 13 ++--------- contrib/containers/guix/scripts/setup-sdk | 27 ++++++++++++++++++++++ 5 files changed, 41 insertions(+), 46 deletions(-) create mode 100755 contrib/containers/guix/scripts/setup-sdk diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae521f655b56c..ad27984761354 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,26 +40,11 @@ builder-image: needs: - builder-image image: $CI_REGISTRY_IMAGE:builder-$CI_COMMIT_REF_SLUG - variables: - SDK_URL: https://bitcoincore.org/depends-sources/sdks - XCODE_VERSION: "15.0" - XCODE_BUILD_ID: 15A240d before_script: - - echo HOST=$HOST - | - if [ "$HOST" = "x86_64-apple-darwin" ]; then - mkdir -p depends/SDKs - mkdir -p depends/sdk-sources - OSX_SDK_BASENAME="Xcode-${XCODE_VERSION}-${XCODE_BUILD_ID}-extracted-SDK-with-libcxx-headers.tar.gz" - OSX_SDK_PATH="depends/sdk-sources/${OSX_SDK_BASENAME}" - if [ ! -f "$OSX_SDK_PATH" ]; then - echo "Downloading MacOS SDK" - curl --location --fail "${SDK_URL}/${OSX_SDK_BASENAME}" -o "$OSX_SDK_PATH" - fi - if [ -f "$OSX_SDK_PATH" ]; then - echo "Extracting MacOS SDK" - tar -C depends/SDKs -xf "$OSX_SDK_PATH" - fi + echo HOST=${HOST} + if [[ "${HOST}" == "x86_64-apple-darwin" ]]; then + ./contrib/containers/guix/scripts/setup-sdk fi script: - make -j$(nproc) -C depends HOST=$HOST $DEP_OPTS diff --git a/ci/dash/build_depends.sh b/ci/dash/build_depends.sh index 6ad5803ae56f4..3f1ff978ebdbd 100755 --- a/ci/dash/build_depends.sh +++ b/ci/dash/build_depends.sh @@ -20,17 +20,8 @@ mkdir -p $CACHE_DIR/sdk-sources ln -s $CACHE_DIR/depends ${DEPENDS_DIR}/built ln -s $CACHE_DIR/sdk-sources ${DEPENDS_DIR}/sdk-sources -mkdir -p ${DEPENDS_DIR}/SDKs - -if [ -n "$XCODE_VERSION" ]; then - OSX_SDK_BASENAME="Xcode-${XCODE_VERSION}-${XCODE_BUILD_ID}-extracted-SDK-with-libcxx-headers.tar.gz" - OSX_SDK_PATH="${DEPENDS_DIR}/sdk-sources/${OSX_SDK_BASENAME}" - if [ ! -f "$OSX_SDK_PATH" ]; then - curl --location --fail "${SDK_URL}/${OSX_SDK_BASENAME}" -o "$OSX_SDK_PATH" - fi - if [ -f "$OSX_SDK_PATH" ]; then - tar -C ${DEPENDS_DIR}/SDKs -xf "$OSX_SDK_PATH" - fi +if [[ "${HOST}" == "x86_64-apple-darwin" ]]; then + ./contrib/containers/guix/scripts/setup-sdk fi make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS diff --git a/contrib/containers/guix/Dockerfile b/contrib/containers/guix/Dockerfile index 9039147011948..861678502c0ad 100644 --- a/contrib/containers/guix/Dockerfile +++ b/contrib/containers/guix/Dockerfile @@ -77,18 +77,19 @@ RUN usermod -aG sudo ${USERNAME} && \ echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers # Copy required files to container -COPY --from=docker_root ./motd.txt /etc/motd -COPY --from=docker_root ./scripts/entrypoint /usr/local/bin/entrypoint -COPY --from=docker_root ./scripts/guix-check /usr/local/bin/guix-check -COPY --from=docker_root ./scripts/guix-start /usr/local/bin/guix-start +COPY --from=docker_root ./motd.txt /etc/motd +COPY --from=docker_root ./scripts/entrypoint /usr/local/bin/entrypoint +COPY --from=docker_root ./scripts/guix-check /usr/local/bin/guix-check +COPY --from=docker_root ./scripts/guix-start /usr/local/bin/guix-start +COPY --from=docker_root ./scripts/setup-sdk /usr/local/bin/setup-sdk # Create directories for mounting to save/restore cache and grant necessary permissions RUN mkdir -p \ /home/${USERNAME}/.cache \ - /src/dash/depends/{built,sources,work} && \ + /src/dash/depends/{built,sources,work}; \ chown -R ${USER_ID}:${GROUP_ID} \ /home/${USERNAME}/.cache \ - /src + /src; WORKDIR "/src/dash" diff --git a/contrib/containers/guix/scripts/guix-start b/contrib/containers/guix/scripts/guix-start index 4d0c6f6dba71e..50264c42d0ee2 100755 --- a/contrib/containers/guix/scripts/guix-start +++ b/contrib/containers/guix/scripts/guix-start @@ -9,19 +9,10 @@ if [[ ! -d "${WORKSPACE_PATH}" || ! "${WORKSPACE_PATH}" = /* || ! -f "${WORKSPAC exit 1 fi -XCODE_VERSION="15.0" -XCODE_RELEASE="15A240d" -XCODE_ARCHIVE="Xcode-${XCODE_VERSION}-${XCODE_RELEASE}-extracted-SDK-with-libcxx-headers" -XCODE_SOURCE="${XCODE_SOURCE:-https://bitcoincore.org/depends-sources/sdks}" - export SDK_PATH="${SDK_PATH:-${WORKSPACE_PATH}/depends/SDKs}" +export SDK_SRCS="${SDK_PATH:-${WORKSPACE_PATH}/depends/sdk-sources}" -# Check if macOS SDK is present, if not, download it -if [[ ! -d "${SDK_PATH}/${XCODE_ARCHIVE}" ]]; then - echo "Preparing macOS SDK..." - mkdir -p "${SDK_PATH}" - curl -L "${XCODE_SOURCE}/${XCODE_ARCHIVE}.tar.gz" | tar -xz -C "${SDK_PATH}" -fi +./contrib/containers/guix/scripts/setup-sdk # Add safe.directory option only when WORKSPACE_PATH was specified via cmd-line arguments (happens in CI) if [[ -n "${1}" ]]; then diff --git a/contrib/containers/guix/scripts/setup-sdk b/contrib/containers/guix/scripts/setup-sdk new file mode 100755 index 0000000000000..4550aeed6424b --- /dev/null +++ b/contrib/containers/guix/scripts/setup-sdk @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Copyright (c) 2024 The Dash Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +set -eo pipefail + +SDK_URL="${SDK_URL:-https://bitcoincore.org/depends-sources/sdks}" +SDK_PATH="${SDK_PATH:-depends/SDKs}" +SDK_SRCS="${SDK_SOURCES:-depends/sdk-sources}" +XCODE_VERSION="${XCODE_VERSION:-15.0}" +XCODE_RELEASE="${XCODE_RELEASE:-15A240d}" +XCODE_ARCHIVE="Xcode-${XCODE_VERSION}-${XCODE_RELEASE}-extracted-SDK-with-libcxx-headers" +XCODE_AR_PATH="${SDK_SRCS}/${XCODE_ARCHIVE}.tar.gz" + +if [ ! -d "${SDK_PATH}/${XCODE_ARCHIVE}" ]; then + if [ ! -f "${XCODE_AR_PATH}" ]; then + echo "Downloading macOS SDK..." + mkdir -p "${SDK_SRCS}" + curl --location --fail "${SDK_URL}/${XCODE_ARCHIVE}.tar.gz" -o "${XCODE_AR_PATH}" + fi + echo "Extracting macOS SDK..." + mkdir -p "${SDK_PATH}" + tar -C "${SDK_PATH}" -xf "${XCODE_AR_PATH}" +fi