3 # This simple script can be used to set up a CI node running MacOS.
4 # An additional requirement that is *not* handled by this script is the
5 # installation of Xcode, which requires manual intervention.
7 # This script should first be run from an administrator account to install
8 # the dependencies necessary for running CI. It can be run without having
9 # to clone the LLVM repository with:
11 # $ /bin/bash -c "$(curl -fsSl https://raw.githubusercontent.com/llvm/llvm-project/main/libcxx/utils/ci/macos-ci-setup)"
13 # If you perform system updates, you should re-run the script from the
14 # administrator account -- this allows updating the packages used for
15 # CI and the BuildKite agent tags.
17 # Once the necessary dependencies have been installed, you can switch
18 # to a non-administrator account and run the script again, passing the
19 # --setup-launchd argument. That will install a Launchd agent to run the
20 # BuildKite agent whenever the current user is logged in. You should enable
21 # automatic login for that user, so that if the CI node goes down, the user
22 # is logged back in automatically when the node goes up again, and the
23 # BuildKite agent starts automatically.
25 # Alternatively, you can simply run the BuildKite agent by hand using:
27 # $ caffeinate -s buildkite-agent start --build-path /tmp/buildkite-builds
31 # Install a Launchd agent that will automatically start the BuildKite agent at login
32 if [[ ${1} == "--setup-launchd" ]]; then
33 HOMEBREW_PREFIX
="$(brew --prefix)"
34 mkdir
-p ~
/Library
/LaunchAgents
35 cat <<EOF > ~/Library/LaunchAgents/libcxx.buildkite-agent.plist
36 <?xml version="1.0" encoding="UTF-8"?>
37 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
41 <string>libcxx.buildkite-agent</string>
43 <key>ProgramArguments</key>
45 <string>${HOMEBREW_PREFIX}/bin/buildkite-agent</string>
46 <string>start</string>
47 <string>--build-path</string>
48 <string>${HOME}/libcxx.buildkite-agent/builds</string>
51 <key>EnvironmentVariables</key>
54 <string>${HOMEBREW_PREFIX}/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
62 <key>SuccessfulExit</key>
66 <key>ProcessType</key>
67 <string>Interactive</string>
69 <key>ThrottleInterval</key>
72 <key>StandardOutPath</key>
73 <string>${HOME}/libcxx.buildkite-agent/stdout.log</string>
75 <key>StandardErrorPath</key>
76 <string>${HOME}/libcxx.buildkite-agent/stderr.log</string>
81 echo "Starting BuildKite agent"
82 launchctl load ~
/Library
/LaunchAgents
/libcxx.buildkite-agent.plist
85 echo "Installing CI dependencies for macOS"
87 if [[ -z "${BUILDKITE_AGENT_TOKEN}" ]]; then
88 echo "The BUILDKITE_AGENT_TOKEN environment variable must be set to a BuildKite Agent token when calling this script."
93 if ! which -s brew
; then
94 /bin
/bash
-c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
97 # Install the required tools to run CI
99 for package
in sphinx-doc python3 ninja cmake clang-format buildkite
/buildkite
/buildkite-agent
; do
100 if brew
ls --versions "${package}" >/dev
/null
; then
101 brew upgrade
"${package}"
103 brew
install "${package}"
106 python3
-m pip
install --upgrade psutil
108 echo "Setting up BuildKite Agent config"
109 version
="$(sw_vers -productVersion | sed -E 's/([0-9]+).([0-9]+).[0-9]+/\1.\2/')"
111 cat <<EOF > "$(brew --prefix)/etc/buildkite-agent/buildkite-agent.cfg"
112 token="${BUILDKITE_AGENT_TOKEN}"
113 tags="queue=libcxx-builders,arch=${arch},os=macos,os=macos${version}"
114 build-path=/tmp/buildkite-builds # Note that this is actually overwritten when starting the agent with launchd