#!/usr/bin/env bash # This simple script can be used to set up a CI node running MacOS. # An additional requirement that is *not* handled by this script is the # installation of Xcode, which requires manual intervention. # # This script should first be run from an administrator account to install # the dependencies necessary for running CI. It can be run without having # to clone the LLVM repository with: # # $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)" # # Once the necessary dependencies have been installed, you can switch # to a non-administrator account and run the script again, passing the # --setup-launchd argument. That will install a Launchd agent to run the # BuildKite agent whenever the current user is logged in. You should enable # automatic login for that user, so that if the CI node goes down, the user # is logged back in automatically when the node goes up again, and the # BuildKite agent starts automatically. # # Alternatively, you can simply run the BuildKite agent by hand using: # # $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds set -e # Install a Launchd agent that will automatically start the BuildKite agent at login if [[ ${1} == "--setup-launchd" ]]; then HOMEBREW_PREFIX="$(brew --prefix)" mkdir -p ~/Library/LaunchAgents cat < ~/Library/LaunchAgents/libcxx.buildkite-agent.plist Label libcxx.buildkite-agent ProgramArguments ${HOMEBREW_PREFIX}/bin/buildkite-agent start --build-path ${HOME}/libcxx.buildkite-agent/builds EnvironmentVariables PATH ${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin RunAtLoad KeepAlive SuccessfulExit ProcessType Interactive ThrottleInterval 30 StandardOutPath ${HOME}/libcxx.buildkite-agent/stdout.log StandardErrorPath ${HOME}/libcxx.buildkite-agent/stderr.log EOF echo "Starting BuildKite agent" launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist else echo "Installing CI dependencies for macOS" if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script." exit 1 fi # Install Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" HOMEBREW_PREFIX="$(brew --prefix)" # Install the required tools to run CI brew install sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent # Setup BuildKite Agent config version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')" arch="$(uname -m)" sed -i '' "s/token=xxx/token=${BUILDKITE_AGENT_TOKEN}/g" "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg" echo "tags=\"queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}\"" >> "${HOMEBREW_PREFIX}/etc/buildkite-agent/buildkite-agent.cfg" fi