diff options
Diffstat (limited to 'llvm/utils')
-rw-r--r-- | llvm/utils/docker/README | 1 | ||||
-rwxr-xr-x | llvm/utils/docker/build_docker_image.sh | 121 | ||||
-rw-r--r-- | llvm/utils/docker/debian8/build/Dockerfile | 35 | ||||
-rw-r--r-- | llvm/utils/docker/debian8/release/Dockerfile | 21 | ||||
-rw-r--r-- | llvm/utils/docker/example/build/Dockerfile | 26 | ||||
-rw-r--r-- | llvm/utils/docker/example/release/Dockerfile | 24 | ||||
-rw-r--r-- | llvm/utils/docker/nvidia-cuda/build/Dockerfile | 25 | ||||
-rw-r--r-- | llvm/utils/docker/nvidia-cuda/release/Dockerfile | 23 | ||||
-rwxr-xr-x | llvm/utils/docker/scripts/build_install_llvm.sh | 169 |
9 files changed, 445 insertions, 0 deletions
diff --git a/llvm/utils/docker/README b/llvm/utils/docker/README new file mode 100644 index 00000000000..be08dfa4c50 --- /dev/null +++ b/llvm/utils/docker/README @@ -0,0 +1 @@ +See llvm/docs/Docker.rst for details diff --git a/llvm/utils/docker/build_docker_image.sh b/llvm/utils/docker/build_docker_image.sh new file mode 100755 index 00000000000..2ec07ab6da4 --- /dev/null +++ b/llvm/utils/docker/build_docker_image.sh @@ -0,0 +1,121 @@ +#!/bin/bash +#===- llvm/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="" +BUILDSCRIPT_ARGS="" + +function show_usage() { + usage=$(cat << EOF +Usage: build_docker_image.sh [options] [-- [buildscript_args]...] + +Available options: + -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. + +All options after '--' are passed to buildscript (see +scripts/build_install_llvm.sh). + +For example, running: +$ build_docker_image.sh -s debian8 -d mydocker/debian8-clang -t latest \ + -- -p clang -i install-clang -i install-clang-headers +will produce two docker images: + mydocker/debian8-clang-build:latest - an intermediate image used to compile + clang. + mydocker/clang-debian8: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. +For an example of a somewhat more useful build, see build_clang_image.sh. +EOF +) + echo "$usage" +} + +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 + ;; + --) + shift + BUILDSCRIPT_ARGS="$*" + 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 + +cd $(dirname $0) +if [ ! -d $IMAGE_SOURCE ]; then + echo "No sources for '$IMAGE_SOURCE' were found in $PWD" + exit 1 +fi + +echo "Building from $IMAGE_SOURCE" + +if [ "$DOCKER_TAG" != "" ]; then + DOCKER_TAG=":$DOCKER_TAG" +fi + +echo "Building $DOCKER_REPOSITORY-build$DOCKER_TAG" +docker build -t "$DOCKER_REPOSITORY-build$DOCKER_TAG" \ + --build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \ + -f "$IMAGE_SOURCE/build/Dockerfile" . + +echo "Copying clang installation to release image sources" +docker run -v "$PWD/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \ + cp /tmp/clang.tar.gz /workspace/release +trap "rm -f $PWD/$IMAGE_SOURCE/release/clang.tar.gz" EXIT + +echo "Building release image" +docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \ + "$IMAGE_SOURCE/release" + +echo "Done" diff --git a/llvm/utils/docker/debian8/build/Dockerfile b/llvm/utils/docker/debian8/build/Dockerfile new file mode 100644 index 00000000000..13a11a73be6 --- /dev/null +++ b/llvm/utils/docker/debian8/build/Dockerfile @@ -0,0 +1,35 @@ +#===- llvm/utils/docker/debian8/build/Dockerfile -------------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# Produces an image that compiles and archives clang, based on debian8. +FROM launcher.gcr.io/google/debian8:latest + +LABEL maintainer "LLVM Developers" + +# Install build dependencies of llvm. +# First, Update the apt's source list and include the sources of the packages. +RUN grep deb /etc/apt/sources.list | \ + sed 's/^deb/deb-src /g' >> /etc/apt/sources.list + +# Install compiler, python and subversion. +RUN apt-get update && \ + apt-get install -y --no-install-recommends build-essential python2.7 wget \ + subversion ninja-build && \ + rm -rf /var/lib/apt/lists/* + +# Install cmake version that can compile clang into /usr/local. +# (Version in debian8 repos is is too old) +RUN wget -O - "https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz" | \ + tar xzf - -C /usr/local --strip-components=1 + +# Arguments passed to build_install_clang.sh. +ARG buildscript_args + +# Run the build. Results of the build will be available as /tmp/clang.tar.gz. +ADD scripts/build_install_llvm.sh /tmp +RUN /tmp/build_install_llvm.sh ${buildscript_args} diff --git a/llvm/utils/docker/debian8/release/Dockerfile b/llvm/utils/docker/debian8/release/Dockerfile new file mode 100644 index 00000000000..d0214b9c67a --- /dev/null +++ b/llvm/utils/docker/debian8/release/Dockerfile @@ -0,0 +1,21 @@ +#===- llvm/utils/docker/debian8/release/Dockerfile -----------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# A release image, containing clang installation, produced by the 'build/' image +# and adding libstdc++ and binutils. +FROM launcher.gcr.io/google/debian8:latest + +LABEL maintainer "LLVM Developers" + +# Install packages for minimal usefull image. +RUN apt-get update && \ + apt-get install -y --no-install-recommends libstdc++-4.9-dev binutils && \ + rm -rf /var/lib/apt/lists/* + +# Unpack clang installation into this image. +ADD clang.tar.gz / diff --git a/llvm/utils/docker/example/build/Dockerfile b/llvm/utils/docker/example/build/Dockerfile new file mode 100644 index 00000000000..597ccfeb4f2 --- /dev/null +++ b/llvm/utils/docker/example/build/Dockerfile @@ -0,0 +1,26 @@ +#===- llvm/utils/docker/example/build/Dockerfile -------------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# This is an example Dockerfile to build an image that compiles clang. +# Replace FIXMEs to prepare your own image. + +# FIXME: Replace 'ubuntu' with your base image +FROM ubuntu + +# FIXME: Change maintainer name +LABEL maintainer "Maintainer <maintainer@email>" + +# FIXME: Install llvm/clang build dependencies. Including compiler to +# build stage1, cmake, subversion, ninja, etc. + +# Arguments to pass to build_install_clang.sh. +ARG buildscript_args + +# Run the build. Results of the build will be available as /tmp/clang.tar.gz. +ADD scripts/build_install_llvm.sh /tmp +RUN /tmp/build_install_llvm.sh ${buildscript_args} diff --git a/llvm/utils/docker/example/release/Dockerfile b/llvm/utils/docker/example/release/Dockerfile new file mode 100644 index 00000000000..953d81fc995 --- /dev/null +++ b/llvm/utils/docker/example/release/Dockerfile @@ -0,0 +1,24 @@ +#===- llvm/utils/docker/example/release/Dockerfile -----------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# An image that unpacks a clang installation, compiled by the 'build/' +# container. +# Replace FIXMEs to prepare your own image. + +# FIXME: Replace 'ubuntu' with your base image. +FROM ubuntu + +# FIXME: Change maintainer name. +LABEL maintainer "Maintainer <maintainer@email>" + +# FIXME: Install all packages you want to have in your release container. +# A minimal usefull installation must include libstdc++ and binutils. + +# Unpack clang installation into this container. +# It is copied to this directory by build_docker_image.sh script. +ADD clang.tar.gz / diff --git a/llvm/utils/docker/nvidia-cuda/build/Dockerfile b/llvm/utils/docker/nvidia-cuda/build/Dockerfile new file mode 100644 index 00000000000..619b80cbb61 --- /dev/null +++ b/llvm/utils/docker/nvidia-cuda/build/Dockerfile @@ -0,0 +1,25 @@ +#===- llvm/utils/docker/nvidia-cuda/build/Dockerfile ---------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# Produces an image that compiles and archives clang, based on nvidia/cuda +# image. +FROM nvidia/cuda:8.0-devel + +LABEL maintainer "LLVM Developers" + +# Arguments to pass to build_install_clang.sh. +ARG buildscript_args + +# Install llvm build dependencies. +RUN apt-get update && \ + apt-get install -y --no-install-recommends cmake python2.7 subversion ninja-build && \ + rm -rf /var/lib/apt/lists/* + +# Run the build. Results of the build will be available as /tmp/clang.tar.gz. +ADD scripts/build_install_llvm.sh /tmp +RUN /tmp/build_install_llvm.sh ${buildscript_args} diff --git a/llvm/utils/docker/nvidia-cuda/release/Dockerfile b/llvm/utils/docker/nvidia-cuda/release/Dockerfile new file mode 100644 index 00000000000..b9bcae15978 --- /dev/null +++ b/llvm/utils/docker/nvidia-cuda/release/Dockerfile @@ -0,0 +1,23 @@ +#===- llvm/utils/docker/nvidia-cuda/release/Dockerfile -------------------===// +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===// +# This is an example Dockerfile that copies a clang installation, compiled +# by the 'build/' container into a fresh docker image to get a container of +# minimal size. +# Replace FIXMEs to prepare a new Dockerfile. + +# FIXME: Replace 'ubuntu' with your base image. +FROM nvidia/cuda:8.0-devel + +# FIXME: Change maintainer name. +LABEL maintainer "LLVM Developers" + +# Unpack clang installation into this container. +ADD clang.tar.gz / + +# C++ standard library and binutils are already included in the base package. diff --git a/llvm/utils/docker/scripts/build_install_llvm.sh b/llvm/utils/docker/scripts/build_install_llvm.sh new file mode 100755 index 00000000000..7e0e9065741 --- /dev/null +++ b/llvm/utils/docker/scripts/build_install_llvm.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +#===- llvm/utils/docker/scripts/build_install_llvm.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() { + usage=$(cat << EOF +Usage: build_install_llvm.sh [options] -- [cmake-args] + +Checkout svn sources and run cmake with the specified arguments. Used +inside docker container. +Passes additional -DCMAKE_INSTALL_PREFIX and archives the contents of +the directory to /tmp/clang.tar.gz. + +Available options: + -h|--help show this help message + -b|--branch svn branch to checkout, i.e. 'trunk', + 'branches/release_40' + (default: 'trunk') + -r|--revision svn revision to checkout + -p|--llvm-project name of an svn project to checkout. Will also add the + project to a list LLVM_ENABLE_PROJECTS, passed to CMake. + For clang, please use 'clang', not 'cfe'. + Project 'llvm' is always included and ignored, if + specified. + Can be specified multiple times. + -i|--install-target name of a cmake install target to build and include in + the resulting archive. Can be specified multiple times. +Required options: At least one --install-target. + +All options after '--' are passed to CMake invocation. +EOF +) + echo "$usage" +} + +LLVM_SVN_REV="" +LLVM_BRANCH="" +CMAKE_ARGS="" +CMAKE_INSTALL_TARGETS="" +# We always checkout llvm +LLVM_PROJECTS="llvm" +CMAKE_LLVM_ENABLE_PROJECTS="" + +function contains_project() { + local TARGET_PROJ="$1" + local PROJ + for PROJ in $LLVM_PROJECTS; do + if [ "$PROJ" == "$TARGET_PROJ" ]; then + return 0 + fi + done + return 1 +} + +while [[ $# -gt 0 ]]; do + case "$1" in + -r|--revision) + shift + LLVM_SVN_REV="$1" + ;; + -b|--branch) + shift + LLVM_BRANCH="$1" + shift + ;; + -p|--llvm-project) + shift + PROJ="$1" + if [ "$PROJ" == "cfe" ]; then + PROJ="clang" + fi + if ! contains_project "$PROJ" ; then + LLVM_PROJECTS="$LLVM_PROJECTS $PROJ" + CMAKE_LLVM_ENABLE_PROJECTS="$CMAKE_LLVM_ENABLED_PROJECTS;$PROJ" + else + echo "Project '$PROJ' is already enabled, ignoring extra occurences." + fi + shift + ;; + -i|--install-target) + shift + CMAKE_INSTALL_TARGETS="$CMAKE_INSTALL_TARGETS $1" + shift + ;; + --) + shift + CMAKE_ARGS="$*" + shift $# + ;; + -h|--help) + show_usage + exit 0 + ;; + *) + echo "Unknown option: $1" + exit 1 + esac +done + +if [ "$CMAKE_INSTALL_TARGETS" == "" ]; then + echo "No install targets. Please pass one or more --install-target." + exit 1 +fi + +if [ "$LLVM_BRANCH" == "" ]; then + LLVM_BRANCH="trunk" +fi + +if [ "$LLVM_SVN_REVISION" != "" ]; then + SVN_REV_ARG="-r$LLVM_SVN_REVISION" +else + SVN_REV_ARG="" +fi + +CLANG_BUILD_DIR=/tmp/clang-build +CLANG_INSTALL_DIR=/tmp/clang-install + +mkdir "$CLANG_BUILD_DIR" + +# Get the sources from svn. +echo "Checking out sources from svn" +mkdir "$CLANG_BUILD_DIR/src" +for LLVM_PROJECT in $LLVM_PROJECTS; do + if [ "$LLVM_PROJECT" == "clang" ]; then + SVN_PROJECT="cfe" + else + SVN_PROJECT="$LLVM_PROJECT" + fi + + echo "Checking out http://llvm.org/svn/llvm-project/$SVN_PROJECT to $CLANG_BUILD_DIR/src/$LLVM_PROJECT" + # FIXME: --trust-server-cert is required to workaround 'SSL issuer is not + # trusted' error. Using https seems preferable to http either way, + # albeit this is not secure. + svn co -q $SVN_REV_ARG --trust-server-cert \ + "https://llvm.org/svn/llvm-project/$SVN_PROJECT/$LLVM_BRANCH" \ + "$CLANG_BUILD_DIR/src/$LLVM_PROJECT" +done + +pushd "$CLANG_BUILD_DIR" + +# Run the build as specified in the build arguments. +echo "Running build" +mkdir "$CLANG_BUILD_DIR/build" +cmake -GNinja \ + -DCMAKE_INSTALL_PREFIX="$CLANG_INSTALL_DIR" \ + -DLLVM_ENABLE_PROJECTS="$CMAKE_LLVM_ENABLE_PROJECTS" \ + $CMAKE_ARGS \ + "$CLANG_BUILD_DIR/src/llvm" +ninja $CMAKE_INSTALL_TARGETS + +popd + +# Pack the installed clang into an archive. +echo "Archiving clang installation to /tmp/clang.tar.gz" +cd "$CLANG_INSTALL_DIR" +tar -czf /tmp/clang.tar.gz * + +# Cleanup. +rm -rf "$CLANG_BUILD_DIR" "$CLANG_INSTALL_DIR" + +echo "Done" |