Skip to content

Commit

Permalink
Add docker configurations used by the buildbots.
Browse files Browse the repository at this point in the history
These are the scripts I use to create the docker images for
the build bots and run them.

llvm-svn: 347244
  • Loading branch information
EricWF committed Nov 19, 2018
1 parent c01fc1c commit 9c97ca1
Show file tree
Hide file tree
Showing 7 changed files with 676 additions and 0 deletions.
109 changes: 109 additions & 0 deletions libcxx/utils/docker/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash
#===- libcxx/utils/docker/build_docker_image.sh ----------------------------===//
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===----------------------------------------------------------------------===//
set -e

IMAGE_SOURCE=""
DOCKER_REPOSITORY=""
DOCKER_TAG=""

function show_usage() {
cat << EOF
Usage: build_docker_image.sh [options] [-- [cmake_args]...]
Available options:
General:
-h|--help show this help message
Docker-specific:
-s|--source image source dir (i.e. debian8, nvidia-cuda, etc)
-d|--docker-repository docker repository for the image
-t|--docker-tag docker tag for the image
Required options: --source and --docker-repository.
For example, running:
$ build_docker_image.sh -s debian9 -d mydocker/debian9-clang -t latest
will produce two docker images:
mydocker/debian9-clang-build:latest - an intermediate image used to compile
clang.
mydocker/clang-debian9:latest - a small image with preinstalled clang.
Please note that this example produces a not very useful installation, since it
doesn't override CMake defaults, which produces a Debug and non-boostrapped
version of clang.
EOF
}

while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_usage
exit 0
;;
-s|--source)
shift
IMAGE_SOURCE="$1"
shift
;;
-d|--docker-repository)
shift
DOCKER_REPOSITORY="$1"
shift
;;
-t|--docker-tag)
shift
DOCKER_TAG="$1"
shift
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
done


command -v docker >/dev/null ||
{
echo "Docker binary cannot be found. Please install Docker to use this script."
exit 1
}

if [ "$IMAGE_SOURCE" == "" ]; then
echo "Required argument missing: --source"
exit 1
fi

if [ "$DOCKER_REPOSITORY" == "" ]; then
echo "Required argument missing: --docker-repository"
exit 1
fi

SOURCE_DIR=$(dirname $0)
if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
exit 1
fi

BUILD_DIR=$(mktemp -d)
trap "rm -rf $BUILD_DIR" EXIT
echo "Using a temporary directory for the build: $BUILD_DIR"

cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"


if [ "$DOCKER_TAG" != "" ]; then
DOCKER_TAG=":$DOCKER_TAG"
fi

echo "Building ${DOCKER_REPOSITORY}${DOCKER_TAG} from $IMAGE_SOURCE"
docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
-f "$BUILD_DIR/$IMAGE_SOURCE/Dockerfile" \
"$BUILD_DIR"
echo "Done"
113 changes: 113 additions & 0 deletions libcxx/utils/docker/debian9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#===- libcxx/utils/docker/debian9/Dockerfile -------------------------===//
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===----------------------------------------------------------------------===//

# Setup the base builder image with the packages we'll need to build GCC and Clang from source.
FROM launcher.gcr.io/google/debian9:latest as 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 && \
update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.gold" 20 && \
update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.bfd" 10

# Build GCC 4.9 for testing our C++11 against
FROM builder-base as gcc-49-builder
LABEL maintainer "libc++ Developers"

ADD scripts/build_gcc.sh /tmp/build_gcc.sh

RUN git clone --depth=1 --branch gcc-4_9_4-release git://gcc.gnu.org/git/gcc.git /tmp/gcc-4.9.4
RUN cd /tmp/gcc-4.9.4/ && ./contrib/download_prerequisites
RUN /tmp/build_gcc.sh --source /tmp/gcc-4.9.4 --to /opt/gcc-4.9.4

# Build GCC ToT for testing in all dialects.
FROM builder-base as gcc-tot-builder
LABEL maintainer "libc++ Developers"

ADD scripts/build_gcc.sh /tmp/build_gcc.sh

RUN git clone --depth=1 git://gcc.gnu.org/git/gcc.git /tmp/gcc-tot
RUN cd /tmp/gcc-tot && ./contrib/download_prerequisites
RUN /tmp/build_gcc.sh --source /tmp/gcc-tot --to /opt/gcc-tot

# Build LLVM 4.0 which is used to test against a "legacy" compiler.
FROM builder-base as llvm-4-builder
LABEL maintainer "libc++ Developers"

ADD scripts/checkout_git.sh /tmp/checkout_git.sh
ADD scripts/build_install_llvm.sh /tmp/build_install_llvm.sh

RUN /tmp/checkout_git.sh --to /tmp/llvm-4.0 -p clang -p compiler-rt --branch release_40
RUN /tmp/build_install_llvm.sh \
--install /opt/llvm-4.0 \
--source /tmp/llvm-4.0 \
--build /tmp/build-llvm-4.0 \
-i install-clang -i install-clang-headers \
-i install-compiler-rt \
-- \
-DCMAKE_BUILD_TYPE=RELEASE \
-DLLVM_ENABLE_ASSERTIONS=ON

# Stage 2. Produce a minimal release image with build results.
FROM launcher.gcr.io/google/debian9:latest
LABEL maintainer "libc++ Developers"

# Copy over the GCC and Clang installations
COPY --from=gcc-49-builder /opt/gcc-4.9.4 /opt/gcc-4.9.4
COPY --from=gcc-tot-builder /opt/gcc-tot /opt/gcc-tot
COPY --from=llvm-4-builder /opt/llvm-4.0 /opt/llvm-4.0

RUN ln -s /opt/gcc-4.9.4/bin/gcc /usr/local/bin/gcc-4.9 && \
ln -s /opt/gcc-4.9.4/bin/g++ /usr/local/bin/g++-4.9

RUN apt-get update && \
apt-get install -y \
ca-certificates \
gnupg \
build-essential \
apt-transport-https \
curl \
software-properties-common

RUN apt-get install -y --no-install-recommends \
systemd \
sysvinit-utils \
cmake \
subversion \
git \
ninja-build \
gcc-multilib \
g++-multilib \
python \
buildbot-slave

ADD scripts /libcxx-scripts/
RUN /libcxx-scripts/install_clang_packages.sh
91 changes: 91 additions & 0 deletions libcxx/utils/docker/scripts/build_gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===-----------------------------------------------------------------------===//

set -e


function show_usage() {
cat << EOF
Usage: build-gcc.sh [options]
Run autoconf with the specified arguments. Used inside docker container.
Available options:
-h|--help show this help message
--source the source path from which to run the configuration.
--to destination directory where to install the targets.
Required options: --to, at least one --install-target.
All options after '--' are passed to CMake invocation.
EOF
}

GCC_INSTALL_DIR=""
GCC_SOURCE_DIR=""

while [[ $# -gt 0 ]]; do
case "$1" in
--to)
shift
GCC_INSTALL_DIR="$1"
shift
;;
--source)
shift
GCC_SOURCE_DIR="$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 --to argument."
exit 1
fi

if [ "$GCC_SOURCE_DIR" == "" ]; then
echo "No source directory. Please specify the --source argument."
exit 1
fi

GCC_NAME=`basename $GCC_SOURCE_DIR`
GCC_BUILD_DIR="/tmp/gcc-build-root/build-$GCC_NAME"

mkdir -p "$GCC_INSTALL_DIR"
mkdir -p "$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++

NPROC=`nproc`
echo "Running build with $NPROC threads"
make -j$NPROC

echo "Installing to $GCC_INSTALL_DIR"
make install -j$NPROC

popd

# Cleanup.
rm -rf "$GCC_BUILD_DIR"

echo "Done"
Loading

0 comments on commit 9c97ca1

Please sign in to comment.