Skip to content

Commit

Permalink
llvm: Add llvm docker build (#491)
Browse files Browse the repository at this point in the history
To be used by upstream docker images, builds took too long in upstream

Signed-off-by: Eli Uriegas <[email protected]>
  • Loading branch information
seemethere authored Aug 17, 2020
1 parent b6de62f commit a99c7a5
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
31 changes: 31 additions & 0 deletions llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ubuntu:xenial as dev
ARG LLVM_VERSION=9.0.1
ENV LLVM_URL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
build-essential \
curl \
cmake \
make \
python3 \
python3-dev \
xz-utils

RUN mkdir -p /opt/llvm /tmp/llvm/build
WORKDIR /tmp/llvm
RUN curl -fL -o llvm.tar.xz "${LLVM_URL}" && \
tar -xf llvm.tar.xz --strip-components=1
WORKDIR /tmp/llvm/build
RUN cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_INSTALL_PREFIX=/opt/llvm \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_BUILD_TOOLS=OFF \
-DLLVM_BUILD_UTILS=OFF \
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
../
RUN make -j"$(nproc --ignore=2)" && make install

FROM scratch as final
COPY --from=dev /opt/llvm /opt/llvm
21 changes: 21 additions & 0 deletions llvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# llvm

This contains the dockerfile used to build LLVM from source with assertions enabled.

This is ultimately used by the main `pytorch/pytorch`'s base Docker images

## How to build:

```bash
./build.sh
```

## How to deploy:

```
./deploy.sh
```

## Updating LLVM

Edit the LLVM_VERSION in `env_vars.sh`
11 changes: 11 additions & 0 deletions llvm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -eou pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "${DIR}/env_vars.sh"

(
set -x
cat Dockerfile | DOCKER_BUILDKIT=1 docker build --build-arg "LLVM_VERSION=${LLVM_VERSION}" -t "pytorch/llvm:${LLVM_VERSION}" -
)
22 changes: 22 additions & 0 deletions llvm/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -eou pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "${DIR}/env_vars.sh"

FORCE_PUSH=${FORCE_PUSH:-no}
IMAGE="pytorch/llvm:${LLVM_VERSION}"

if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "${IMAGE}" >/dev/null 2>/dev/null; then
if [[ ${FORCE_PUSH} = "no" ]]; then
echo "ERROR: ${IMAGE} already exists, run script with FORCE_PUSH=yes to forcefully push over the tag"
exit 1
else
echo "WARNING: Overwriting existing ${IMAGE}"
fi
fi
(
set -x
docker push "pytorch/llvm:${LLVM_VERSION}"
)
3 changes: 3 additions & 0 deletions llvm/env_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

LLVM_VERSION="9.0.1"

0 comments on commit a99c7a5

Please sign in to comment.