[libc++] Rework buildbot configuration for the greater good.

This commit rewrites/removes the docker files used to create
the libc++ buildbots.

The major changes in this patch are:

1. Delete Dockerfiles used to build compilers. These have moved to
   github.com/efcs/compiler-images

2. Minimize the llvm-buildbot docker image. Instead of running the
buildbots from a committed docker image, the builders now build the
image on startup. This means changes to the docker file automatically
propogate to the builders (within ~24 hours without restart).

3. Version the compilers used by the builders. This means the bots
won't start failing because the apt.llvm.org clang package updated.
This commit is contained in:
Eric Fiselier 2020-03-21 09:58:10 -04:00
parent 05880fc9ae
commit deb5103378
17 changed files with 130 additions and 661 deletions

View File

@ -0,0 +1,40 @@
#===-------------------------------------------------------------------------------------------===//
# buildslave
#===-------------------------------------------------------------------------------------------===//
ARG gcc_tot
ARG llvm_tot
FROM ${gcc_tot} AS gcc-tot
FROM ${llvm_tot} AS llvm-tot
FROM debian:stretch AS base-image
ADD install-packages.sh /tmp/
RUN /tmp/install-packages.sh && rm /tmp/install-packages.sh
COPY --from=ericwf/gcc:5.5.0 /compiler /opt/gcc-5
COPY --from=ericwf/llvm:9.x /compiler /opt/llvm-9
FROM base-image as worker-image
COPY --from=gcc-tot /compiler /opt/gcc-tot
COPY --from=llvm-tot /compiler /opt/llvm-tot
ENV PATH /opt/llvm-tot/bin:$PATH
RUN clang++ --version && echo hello
RUN g++ --version
RUN /opt/gcc-tot/bin/g++ --version
RUN /opt/llvm-tot/bin/clang++ --version
RUN /opt/llvm-tot/bin/clang --version
# FIXME(EricWF): remove this once the buildbot's config doesn't clobber the path.
RUN ln -s /opt/llvm-tot/bin/clang /usr/local/bin/clang
RUN ln -s /opt/llvm-tot/bin/clang++ /usr/local/bin/clang++
ADD run_buildbot.sh /
CMD /run_buildbot.sh /run/secrets/buildbot-auth

View File

@ -0,0 +1,4 @@
{
"login": "<login>",
"password": "<password>"
}

View File

@ -0,0 +1,19 @@
version: '3.7'
services:
llvm-buildbot-worker:
build:
context: https://github.com/llvm-project/llvm-project.git#master:libcxx/utils/docker/debian9/buildbot
args:
gcc_tot: "ericwf/gcc:9.2.0"
llvm_tot: "ericwf/llvm:9.x"
image: llvm-buildbot-worker
volumes:
- /var/run/docker.sock:/var/run/docker.sock
secrets:
- buildbot-auth
logging:
driver: gcplogs
secrets:
buildbot-auth:
file: buildbot-auth.json

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
cd /tmp/
curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
sudo bash install-monitoring-agent.sh
rm install-monitoring-agent.sh
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh
rm install-logging-agent.sh

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -x
set -e
apt-get update && \
apt-get install -y --no-install-recommends \
buildbot-slave \
ca-certificates \
gnupg \
build-essential \
wget \
unzip \
python \
cmake \
ninja-build \
curl \
git \
gcc-multilib \
g++-multilib \
libc6-dev \
libtool \
binutils-dev \
binutils-gold \
software-properties-common \
gnupg \
apt-transport-https \
sudo \
bash-completion \
vim \
jq \
systemd \
sysvinit-utils \
systemd-sysv && \
rm -rf /var/lib/apt/lists/*

View File

@ -2,27 +2,27 @@
set -x
readonly BOT_ROOT=/b
readonly BOT_ROOT_NAME=$1
readonly BOT_PASS=$2
readonly AUTH_FILE=$1
readonly BOT_ROOT_NAME=$(jq -r ".login" $AUTH_FILE)
#pushd /tmp
#curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
#bash install-monitoring-agent.sh
#curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
#bash install-logging-agent.sh --structured
#popd
systemctl daemon-reload
service buildslave stop
mkdir -p /b
rm -rf /b/*
service buildslave stop
apt-get update -y
apt-get upgrade -y
pushd /tmp/
apt-get install sudo -y
curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
sudo bash install-monitoring-agent.sh
rm install-monitoring-agent.sh
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh
rm install-logging-agent.sh
popd
# FIXME(EricWF): Remove this hack. It's only in place to temporarily fix linking libclang_rt from the
# debian packages.
# WARNING: If you're not a buildbot, DO NOT RUN!
apt-get install lld-11 -y
rm /usr/bin/ld
ln -s /usr/bin/lld-11 /usr/bin/ld
systemctl set-property buildslave.service TasksMax=100000
@ -32,10 +32,10 @@ function setup_numbered_bot() {
mkdir -p $BOT_DIR
buildslave stop $BOT_DIR
chown buildbot:buildbot $BOT_DIR
chown buildbot $BOT_DIR
rm -rf $BOT_DIR/*
buildslave create-slave --allow-shutdown=signal "$BOT_DIR" "lab.llvm.org:9990" "$BOT_NAME" "$BOT_PASS"
buildslave create-slave --allow-shutdown=signal "$BOT_DIR" "lab.llvm.org:9990" "$BOT_NAME" $(jq -r ".password" $AUTH_FILE)
echo "Eric Fiselier <ericwf@google.com>" > $BOT_DIR/info/admin
@ -44,6 +44,7 @@ function setup_numbered_bot() {
uname -a | head -n1
cmake --version | head -n1
g++ --version | head -n1
clang++ --version | head -n1
ld --version | head -n1
date
lscpu
@ -74,7 +75,7 @@ function try_start_builder {
systemctl daemon-reload
service buildslave restart
chown -R buildbot:buildbot $BOT_DIR/
chown -R buildbot $BOT_DIR/
sudo -u buildbot /usr/bin/buildslave start $BOT_DIR/
sleep 30

View File

@ -1,174 +0,0 @@
version: '3.7'
x-build-clang: &build-clang
context: .
dockerfile: compilers/clang.Dockerfile
x-build-gcc: &build-gcc
context: .
dockerfile: compilers/gcc.Dockerfile
services:
gcc-4.8.5:
build:
<<: *build-gcc
args:
branch: releases/gcc-4.8.5
install_prefix: /opt/gcc-4.8.5
cherry_pick: 3a27b4db566c2cde8e043220f3d2c5401159b10e
image: ericwf/compiler:gcc-4.8.5
gcc-4.9.4:
build:
<<: *build-gcc
args:
branch: releases/gcc-4.9.4
install_prefix: /opt/gcc-4.9.4
image: ericwf/compiler:gcc-4.9.4
gcc-5:
build:
<<: *build-gcc
args:
branch: releases/gcc-5.5.0
install_prefix: /opt/gcc-5
image: ericwf/compiler:gcc-5
gcc-6:
build:
<<: *build-gcc
args:
branch: releases/gcc-6.5.0
install_prefix: /opt/gcc-6
image: ericwf/compiler:gcc-6
gcc-7:
build:
<<: *build-gcc
args:
branch: releases/gcc-7.4.0
install_prefix: /opt/gcc-7
image: ericwf/compiler:gcc-7
gcc-8:
build:
<<: *build-gcc
args:
branch: releases/gcc-8.2.0
install_prefix: /opt/gcc-8
image: ericwf/compiler:gcc-8
gcc-9:
build:
<<: *build-gcc
args:
branch: releases/gcc-9.2.0
install_prefix: /opt/gcc-9
image: ericwf/compiler:gcc-9
# Add LLVM compilers
llvm-3.6:
build:
<<: *build-clang
args:
branch: release/3.6.x
install_prefix: /opt/llvm-3.6
image: ericwf/compiler:llvm-3.6
llvm-3.7:
build:
<<: *build-clang
args:
branch: release/3.7.x
install_prefix: /opt/llvm-3.7
image: ericwf/compiler:llvm-3.7
llvm-3.8:
build:
<<: *build-clang
args:
branch: release/3.8.x
install_prefix: /opt/llvm-3.8
image: ericwf/compiler:llvm-3.8
llvm-3.9:
build:
<<: *build-clang
args:
branch: release/3.9.x
install_prefix: /opt/llvm-3.9
image: ericwf/compiler:llvm-3.9
llvm-4:
build:
<<: *build-clang
args:
branch: release/4.x
install_prefix: /opt/llvm-4
image: ericwf/compiler:llvm-4
llvm-5:
build:
<<: *build-clang
args:
branch: release/5.x
install_prefix: /opt/llvm-5
image: ericwf/compiler:llvm-5
llvm-6:
build:
<<: *build-clang
args:
branch: release/6.x
install_prefix: /opt/llvm-6
image: ericwf/compiler:llvm-6
llvm-7:
build:
<<: *build-clang
args:
branch: release/7.x
install_prefix: /opt/llvm-7
image: ericwf/compiler:llvm-7
llvm-8:
build:
<<: *build-clang
args:
branch: release/8.x
install_prefix: /opt/llvm-8
image: ericwf/compiler:llvm-8
llvm-9:
build:
<<: *build-clang
args:
branch: release/9.x
install_prefix: /opt/llvm-9
image: ericwf/compiler:llvm-9
gcc-tot:
build:
<<: *build-gcc
args:
branch: master
cache_date: feb-27
install_prefix: /opt/gcc-tot
image: ericwf/compiler:gcc-tot
llvm-tot:
build:
<<: *build-clang
args:
branch: master
cache_date: feb-27
install_prefix: /opt/llvm-tot
image: ericwf/compiler:llvm-tot
compiler-zoo:
build:
context: .
dockerfile: compilers/compiler-zoo.Dockerfile
target: compiler-zoo
image: ericwf/compiler-zoo:latest
depends_on:
- gcc-4.8.5
- gcc-4.9.4
- gcc-5
- gcc-6
- gcc-7
- gcc-8
- gcc-9
- gcc-tot
- llvm-3.6
- llvm-3.7
- llvm-3.8
- llvm-3.9
- llvm-4
- llvm-5
- llvm-6
- llvm-7
- llvm-8
- llvm-9
- llvm-tot

View File

@ -1,19 +0,0 @@
#===----------------------------------------------------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===//
# Build GCC versions
FROM ericwf/llvm-builder-base:latest
LABEL maintainer "libc++ Developers"
ARG install_prefix
ARG branch
ARG cache_date=stable
ADD scripts/build_llvm_version.sh /tmp/
RUN /tmp/build_llvm_version.sh --install "$install_prefix" --branch "$branch" \
&& rm /tmp/build_llvm_version.sh

View File

@ -1,37 +0,0 @@
#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-------------------------------------------------------------------------------------------===//
#===-------------------------------------------------------------------------------------------===//
# compiler-zoo
#===-------------------------------------------------------------------------------------------===//
FROM ericwf/llvm-builder-base:latest AS compiler-zoo
LABEL maintainer "libc++ Developers"
# Copy over the GCC and Clang installations
COPY --from=ericwf/compiler:gcc-4.8.5 /opt/gcc-4.8.5 /opt/gcc-4.8.5
COPY --from=ericwf/compiler:gcc-4.9.4 /opt/gcc-4.9.4 /opt/gcc-4.9.4
COPY --from=ericwf/compiler:gcc-5 /opt/gcc-5 /opt/gcc-5
COPY --from=ericwf/compiler:gcc-6 /opt/gcc-6 /opt/gcc-6
COPY --from=ericwf/compiler:gcc-7 /opt/gcc-7 /opt/gcc-7
COPY --from=ericwf/compiler:gcc-8 /opt/gcc-8 /opt/gcc-8
COPY --from=ericwf/compiler:gcc-9 /opt/gcc-9 /opt/gcc-9
COPY --from=ericwf/compiler:gcc-tot /opt/gcc-tot /opt/gcc-tot
COPY --from=ericwf/compiler:llvm-3.6 /opt/llvm-3.6 /opt/llvm-3.6
COPY --from=ericwf/compiler:llvm-3.7 /opt/llvm-3.7 /opt/llvm-3.7
COPY --from=ericwf/compiler:llvm-3.8 /opt/llvm-3.8 /opt/llvm-3.8
COPY --from=ericwf/compiler:llvm-3.9 /opt/llvm-3.9 /opt/llvm-3.9
COPY --from=ericwf/compiler:llvm-4 /opt/llvm-4 /opt/llvm-4
COPY --from=ericwf/compiler:llvm-5 /opt/llvm-5 /opt/llvm-5
COPY --from=ericwf/compiler:llvm-6 /opt/llvm-6 /opt/llvm-6
COPY --from=ericwf/compiler:llvm-7 /opt/llvm-7 /opt/llvm-7
COPY --from=ericwf/compiler:llvm-8 /opt/llvm-8 /opt/llvm-8
COPY --from=ericwf/compiler:llvm-9 /opt/llvm-9 /opt/llvm-9
COPY --from=ericwf/compiler:llvm-tot /opt/llvm-tot /opt/llvm-tot

View File

@ -1,24 +0,0 @@
#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-------------------------------------------------------------------------------------------===//
# Build GCC versions
FROM ericwf/llvm-builder-base:latest
LABEL maintainer "libc++ Developers"
ARG branch
ARG cherry_pick=""
ARG install_prefix
ARG cache_date=stable
ADD scripts/build_gcc_version.sh /tmp/
RUN /tmp/build_gcc_version.sh \
--install "$install_prefix" \
--branch "$branch" \
--cherry-pick "$cherry_pick" \
&& rm /tmp/build_gcc_version.sh

View File

@ -1,14 +0,0 @@
version: '3.7'
services:
llvm-builder-base:
build:
context: .
dockerfile: llvm-builder-base.Dockerfile
target: llvm-builder-base
image: ericwf/llvm-builder-base:latest
llvm-buildbot-worker:
build:
context: .
dockerfile: llvm-buildbot-worker.Dockerfile
target: llvm-buildbot-worker
image: ericwf/llvm-buildbot-worker:latest

View File

@ -1,23 +0,0 @@
#===-------------------------------------------------------------------------------------------===//
# buildslave
#===-------------------------------------------------------------------------------------------===//
FROM ericwf/llvm-builder-base:latest AS llvm-buildbot-worker
COPY --from=ericwf/compiler:gcc-5 /opt/gcc-5 /opt/gcc-5
COPY --from=ericwf/compiler:gcc-tot /opt/gcc-tot /opt/gcc-tot
COPY --from=ericwf/compiler:llvm-4 /opt/llvm-4 /opt/llvm-4.0
# FIXME(EricWF): Remove this hack once zorg has been updated.
RUN ln -s /opt/gcc-5/bin/gcc /usr/local/bin/gcc-4.9 && \
ln -s /opt/gcc-5/bin/g++ /usr/local/bin/g++-4.9
RUN apt-get update && \
apt-get install -y --no-install-recommends \
buildbot-slave \
&& rm -rf /var/lib/apt/lists/*
ADD scripts/install_clang_packages.sh /tmp/
RUN /tmp/install_clang_packages.sh && rm /tmp/install_clang_packages.sh
RUN rm -rf /llvm-project/ && git clone --depth=1 https://github.com/llvm/llvm-project.git /llvm-project

View File

@ -1,47 +0,0 @@
#===----------------------------------------------------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===//
FROM launcher.gcr.io/google/debian9:latest AS llvm-builder-base
LABEL maintainer "libc++ Developers"
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
build-essential \
wget \
subversion \
unzip \
automake \
python \
cmake \
ninja-build \
curl \
git \
gcc-multilib \
g++-multilib \
libc6-dev \
bison \
flex \
libtool \
autoconf \
binutils-dev \
binutils-gold \
software-properties-common \
gnupg \
apt-transport-https \
sudo \
bash-completion \
vim \
systemd \
sysvinit-utils \
systemd-sysv && \
update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.gold" 20 && \
update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.bfd" 10 && \
rm -rf /var/lib/apt/lists/*

View File

@ -1,108 +0,0 @@
#!/usr/bin/env bash
#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-----------------------------------------------------------------------===//
set -e
function show_usage() {
cat << EOF
Usage: build_gcc_version.sh [options]
Run autoconf with the specified arguments. Used inside docker container.
Available options:
-h|--help show this help message
--branch the branch of gcc you want to build.
--cherry-pick a commit hash to apply to the GCC sources.
--install destination directory where to install the targets.
Required options: --install and --branch
All options after '--' are passed to CMake invocation.
EOF
}
GCC_INSTALL_DIR=""
GCC_BRANCH=""
CHERRY_PICK=""
while [[ $# -gt 0 ]]; do
case "$1" in
--install)
shift
GCC_INSTALL_DIR="$1"
shift
;;
--branch)
shift
GCC_BRANCH="$1"
shift
;;
--cherry-pick)
shift
CHERRY_PICK="$1"
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
esac
done
if [ "$GCC_INSTALL_DIR" == "" ]; then
echo "No install directory. Please specify the --install argument."
exit 1
fi
if [ "$GCC_BRANCH" == "" ]; then
echo "No branch specified. Please specify the --branch argument."
exit 1
fi
set -x
NPROC=`nproc`
TMP_ROOT="$(mktemp -d -p /tmp)"
GCC_SOURCE_DIR="$TMP_ROOT/gcc"
GCC_BUILD_DIR="$TMP_ROOT/build"
echo "Cloning source directory for branch $GCC_BRANCH"
git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR
pushd "$GCC_SOURCE_DIR"
if [ "$CHERRY_PICK" != "" ]; then
git fetch origin master --unshallow # Urg, we have to get the entire history. This will take a while.
git cherry-pick --no-commit -X theirs "$CHERRY_PICK"
fi
./contrib/download_prerequisites
popd
mkdir "$GCC_BUILD_DIR"
pushd "$GCC_BUILD_DIR"
# Run the build as specified in the build arguments.
echo "Running configuration"
$GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
--disable-bootstrap --disable-libgomp --disable-libitm \
--disable-libvtv --disable-libcilkrts --disable-libmpx \
--disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
echo "Running build with $NPROC threads"
make -j$NPROC
echo "Installing to $GCC_INSTALL_DIR"
make install -j$NPROC
popd
# Cleanup.
rm -rf "$TMP_ROOT"
echo "Done"

View File

@ -1,106 +0,0 @@
#!/usr/bin/env bash
#===- libcxx/utils/docker/scripts/build_install_llvm_version_default.sh -----------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-------------------------------------------------------------------------------------------===//
set -e
function show_usage() {
cat << EOF
Usage: build_install_llvm.sh [options] -- [cmake-args]
Run cmake with the specified arguments. Used inside docker container.
Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
the directory specified by --to option.
Available options:
-h|--help show this help message
--install destination directory where to install the targets.
--branch the branch or tag of LLVM to build
Required options: --install, and --version.
All options after '--' are passed to CMake invocation.
EOF
}
LLVM_BRANCH=""
CMAKE_ARGS=""
LLVM_INSTALL_DIR=""
while [[ $# -gt 0 ]]; do
case "$1" in
--install)
shift
LLVM_INSTALL_DIR="$1"
shift
;;
--branch)
shift
LLVM_BRANCH="$1"
shift
;;
--)
shift
CMAKE_ARGS="$*"
shift $#
;;
-h|--help)
show_usage
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
esac
done
if [ "$LLVM_INSTALL_DIR" == "" ]; then
echo "No install directory. Please specify the --install argument."
exit 1
fi
if [ "$LLVM_BRANCH" == "" ]; then
echo "No install directory. Please specify the --branch argument."
exit 1
fi
if [ "$CMAKE_ARGS" == "" ]; then
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RELEASE '-DCMAKE_C_FLAGS=-gline-tables-only' '-DCMAKE_CXX_FLAGS=-gline-tables-only' -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
fi
set -x
TMP_ROOT="$(mktemp -d -p /tmp)"
LLVM_SOURCE_DIR="$TMP_ROOT/llvm-project"
LLVM_BUILD_DIR="$TMP_ROOT/build"
LLVM="$LLVM_SOURCE_DIR/llvm"
git clone --branch $LLVM_BRANCH --single-branch --depth=1 https://github.com/llvm/llvm-project.git $LLVM_SOURCE_DIR
pushd "$LLVM_SOURCE_DIR"
# Setup the source-tree using the old style layout
ln -s $LLVM_SOURCE_DIR/libcxx $LLVM/projects/libcxx
ln -s $LLVM_SOURCE_DIR/libcxxabi $LLVM/projects/libcxxabi
ln -s $LLVM_SOURCE_DIR/compiler-rt $LLVM/projects/compiler-rt
ln -s $LLVM_SOURCE_DIR/clang $LLVM/tools/clang
ln -s $LLVM_SOURCE_DIR/clang-tools-extra $LLVM/tools/clang/tools/extra
popd
# Configure and build
mkdir "$LLVM_BUILD_DIR"
pushd "$LLVM_BUILD_DIR"
cmake -GNinja "-DCMAKE_INSTALL_PREFIX=$LLVM_INSTALL_DIR" $CMAKE_ARGS $LLVM
ninja install
popd
# Cleanup
rm -rf "$TMP_ROOT/"
echo "Done"

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -x
# Update the libc++ sources in the image in order to use the most recent version of
# run_buildbots.sh
cd /llvm-project/
git pull
/llvm-project/libcxx/utils/docker/debian9/scripts/buildbot/run_buildbot.sh "$@"

View File

@ -1,81 +0,0 @@
#!/usr/bin/env bash
#===- libcxx/utils/docker/scripts/install_clang_package.sh -----------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===-----------------------------------------------------------------------===//
set -e
function show_usage() {
cat << EOF
Usage: install_clang_package.sh [options]
Install
Available options:
-h|--help show this help message
--version the numeric version of the package to use.
EOF
}
VERSION="11"
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
shift
VERSION="$1"
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
esac
done
set -x
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
add-apt-repository -s "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
apt-get update
apt-get upgrade -y
apt-get install -y --no-install-recommends "clang-$VERSION"
# FIXME(EricWF): Remove this once the clang packages are no longer broken.
if [ -f "/usr/local/bin/clang" ]; then
echo "clang already exists"
exit 1
else
CC_BINARY="$(which clang-$VERSION)"
ln -s "$CC_BINARY" "/usr/local/bin/clang"
fi
if [ -f "/usr/local/bin/clang++" ]; then
echo "clang++ already exists"
exit 1
else
CXX_BINARY="$(which clang++-$VERSION)"
ln -s "$CXX_BINARY" "/usr/local/bin/clang++"
fi
echo "Testing clang version..."
clang --version
echo "Testing clang++ version..."
clang++ --version
# Figure out the libc++ and libc++abi package versions that we want.
if [ "$VERSION" == "" ]; then
VERSION="$(apt-cache search 'libc\+\+-[0-9]+-dev' | awk '{print $1}' | awk -F- '{print $2}')"
echo "Installing version '$VERSION'"
fi
apt-get purge -y "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
apt-get install -y --no-install-recommends "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
echo "Done"