176d0caaeSpatrick#!/usr/bin/env bash 276d0caaeSpatrick 376d0caaeSpatrick# This simple script can be used to set up a CI node running MacOS. 476d0caaeSpatrick# An additional requirement that is *not* handled by this script is the 576d0caaeSpatrick# installation of Xcode, which requires manual intervention. 676d0caaeSpatrick# 776d0caaeSpatrick# This script should first be run from an administrator account to install 876d0caaeSpatrick# the dependencies necessary for running CI. It can be run without having 976d0caaeSpatrick# to clone the LLVM repository with: 1076d0caaeSpatrick# 1176d0caaeSpatrick# $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)" 1276d0caaeSpatrick# 13*4bdff4beSrobert# If you perform system updates, you should re-run the script from the 14*4bdff4beSrobert# administrator account -- this allows updating the packages used for 15*4bdff4beSrobert# CI and the BuildKite agent tags. 16*4bdff4beSrobert# 1776d0caaeSpatrick# Once the necessary dependencies have been installed, you can switch 1876d0caaeSpatrick# to a non-administrator account and run the script again, passing the 1976d0caaeSpatrick# --setup-launchd argument. That will install a Launchd agent to run the 2076d0caaeSpatrick# BuildKite agent whenever the current user is logged in. You should enable 2176d0caaeSpatrick# automatic login for that user, so that if the CI node goes down, the user 2276d0caaeSpatrick# is logged back in automatically when the node goes up again, and the 2376d0caaeSpatrick# BuildKite agent starts automatically. 2476d0caaeSpatrick# 2576d0caaeSpatrick# Alternatively, you can simply run the BuildKite agent by hand using: 2676d0caaeSpatrick# 2776d0caaeSpatrick# $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds 2876d0caaeSpatrick 2976d0caaeSpatrickset -e 3076d0caaeSpatrick 3176d0caaeSpatrick# Install a Launchd agent that will automatically start the BuildKite agent at login 3276d0caaeSpatrickif [[ ${1} == "--setup-launchd" ]]; then 3376d0caaeSpatrick HOMEBREW_PREFIX="$(brew --prefix)" 3476d0caaeSpatrick mkdir -p ~/Library/LaunchAgents 3576d0caaeSpatrick cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist 3676d0caaeSpatrick<?xml version="1.0" encoding="UTF-8"?> 3776d0caaeSpatrick<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3876d0caaeSpatrick<plist version="1.0"> 3976d0caaeSpatrick<dict> 4076d0caaeSpatrick <key>Label</key> 4176d0caaeSpatrick <string>libcxx.buildkite-agent</string> 4276d0caaeSpatrick 4376d0caaeSpatrick <key>ProgramArguments</key> 4476d0caaeSpatrick <array> 4576d0caaeSpatrick <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string> 4676d0caaeSpatrick <string>start</string> 4776d0caaeSpatrick <string>--build-path</string> 4876d0caaeSpatrick <string>${HOME}/libcxx.buildkite-agent/builds</string> 4976d0caaeSpatrick </array> 5076d0caaeSpatrick 5176d0caaeSpatrick <key>EnvironmentVariables</key> 5276d0caaeSpatrick <dict> 5376d0caaeSpatrick <key>PATH</key> 5476d0caaeSpatrick <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string> 5576d0caaeSpatrick </dict> 5676d0caaeSpatrick 5776d0caaeSpatrick <key>RunAtLoad</key> 5876d0caaeSpatrick <true/> 5976d0caaeSpatrick 6076d0caaeSpatrick <key>KeepAlive</key> 6176d0caaeSpatrick <dict> 6276d0caaeSpatrick <key>SuccessfulExit</key> 6376d0caaeSpatrick <false/> 6476d0caaeSpatrick </dict> 6576d0caaeSpatrick 6676d0caaeSpatrick <key>ProcessType</key> 6776d0caaeSpatrick <string>Interactive</string> 6876d0caaeSpatrick 6976d0caaeSpatrick <key>ThrottleInterval</key> 7076d0caaeSpatrick <integer>30</integer> 7176d0caaeSpatrick 7276d0caaeSpatrick <key>StandardOutPath</key> 7376d0caaeSpatrick <string>${HOME}/libcxx.buildkite-agent/stdout.log</string> 7476d0caaeSpatrick 7576d0caaeSpatrick <key>StandardErrorPath</key> 7676d0caaeSpatrick <string>${HOME}/libcxx.buildkite-agent/stderr.log</string> 7776d0caaeSpatrick</dict> 7876d0caaeSpatrick</plist> 7976d0caaeSpatrickEOF 8076d0caaeSpatrick 8176d0caaeSpatrick echo "Starting BuildKite agent" 8276d0caaeSpatrick launchctl load ~/Library/LaunchAgents/libcxx.buildkite-agent.plist 8376d0caaeSpatrick 8476d0caaeSpatrickelse 8576d0caaeSpatrick echo "Installing CI dependencies for macOS" 8676d0caaeSpatrick 8776d0caaeSpatrick if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then 8876d0caaeSpatrick echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script." 8976d0caaeSpatrick exit 1 9076d0caaeSpatrick fi 9176d0caaeSpatrick 9276d0caaeSpatrick # Install Homebrew 93*4bdff4beSrobert if ! which -s brew; then 9476d0caaeSpatrick /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 95*4bdff4beSrobert fi 9676d0caaeSpatrick 9776d0caaeSpatrick # Install the required tools to run CI 98*4bdff4beSrobert brew update 99*4bdff4beSrobert for package in sphinx-doc python3 ninja cmake clang-format buildkite/buildkite/buildkite-agent; do 100*4bdff4beSrobert if brew ls --versions "${package}" >/dev/null; then 101*4bdff4beSrobert brew upgrade "${package}" 102*4bdff4beSrobert else 103*4bdff4beSrobert brew install "${package}" 104*4bdff4beSrobert fi 105*4bdff4beSrobert done 106*4bdff4beSrobert python3 -m pip install --upgrade psutil 10776d0caaeSpatrick 108*4bdff4beSrobert echo "Setting up BuildKite Agent config" 10976d0caaeSpatrick version="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')" 11076d0caaeSpatrick arch="$(uname -m)" 111*4bdff4beSrobert cat <<EOF > "$(brew --prefix)/etc/buildkite-agent/buildkite-agent.cfg" 112*4bdff4beSroberttoken="${BUILDKITE_AGENT_TOKEN}" 113*4bdff4beSroberttags="queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}" 114*4bdff4beSrobertbuild-path=/tmp/buildkite-builds # Note that this is actually overwritten when starting the agent with launchd 115*4bdff4beSrobertEOF 11676d0caaeSpatrickfi 117