Skip to content

Commit

Permalink
ci: deduplicate macOS SDK setup logic
Browse files Browse the repository at this point in the history
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
  • Loading branch information
kwvg and UdjinM6 committed Dec 16, 2024
1 parent 8dd0db7 commit 04ce1fe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 46 deletions.
21 changes: 3 additions & 18 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions ci/dash/build_depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 7 additions & 6 deletions contrib/containers/guix/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
13 changes: 2 additions & 11 deletions contrib/containers/guix/scripts/guix-start
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions contrib/containers/guix/scripts/setup-sdk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 04ce1fe

Please sign in to comment.