Skip to content

Instantly share code, notes, and snippets.

@informationsea informationsea/Dockerfile

Last active Feb 28, 2020
Embed
What would you like to do?
Build LLVM for Cent OS 7
FROM centos:7 AS download-llvm
ENV LLVM_VERSION 9.0.1
RUN mkdir -p /download
WORKDIR /download
RUN curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/compiler-rt-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/libunwind-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/lld-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/lldb-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/openmp-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/polly-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang-tools-extra-${LLVM_VERSION}.src.tar.xz &&\
curl -OL https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/test-suite-${LLVM_VERSION}.src.tar.xz
RUN mkdir -p /src
WORKDIR /src
RUN tar xJf /download/llvm-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/clang-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/compiler-rt-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/libcxx-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/libcxxabi-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/libunwind-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/lld-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/lldb-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/openmp-${LLVM_VERSION}.src.tar.xz&&\
tar xJf /download/polly-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/clang-tools-extra-${LLVM_VERSION}.src.tar.xz &&\
tar xJf /download/test-suite-${LLVM_VERSION}.src.tar.xz &&\
mv /src/clang-tools-extra-${LLVM_VERSION}.src /src/clang-${LLVM_VERSION}.src/tools/extra
FROM centos:7 AS download-cmake
RUN mkdir -p /download
WORKDIR /download
RUN curl -OL https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz
RUN tar xzf cmake-3.15.2.tar.gz
FROM centos:7 AS build-cmake
RUN yum update -y
RUN yum install -y gcc gcc-c++ make zlib-devel curl-devel openssl-devel libarchive-devel ncurses-devel readline-devel
COPY --from=download-cmake /download/cmake-3.15.2 /src/cmake-3.15.2
WORKDIR /src/cmake-3.15.2
RUN ./configure --prefix=/opt/cmake && make -j4
RUN make install
FROM centos:7 AS download-gcc
RUN mkdir -p /download
WORKDIR /download
RUN curl -OL http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.2.0/gcc-9.2.0.tar.xz
RUN tar xJf gcc-9.2.0.tar.xz
FROM centos:7 AS build-gcc
RUN yum update -y
RUN yum install -y gcc gcc-c++ make zlib-devel libmpc-devel libmpfr-devel libgmp-devel
COPY --from=download-gcc /download/gcc-9.2.0 /src/gcc
RUN mkdir -p /build/gcc
WORKDIR /build/gcc
RUN /src/gcc/configure --prefix=/opt/gcc-9.2.0 --enable-languages=c,c++,fortran,lto --disable-multilib
RUN make -j4
RUN make install
# build LLVM
FROM centos:7 AS build-llvm
RUN yum update -y
RUN yum install -y gcc gcc-c++ make zlib-devel zip unzip bzip2 python
COPY --from=build-cmake /opt/cmake /opt/cmake
COPY --from=build-gcc /opt/gcc-9.2.0 /opt/gcc-9.2.0
ENV PATH /opt/llvm/bin:/opt/cmake/bin:/opt/gcc-9.2.0/bin:$PATH
ENV LD_LIBRARY_PATH /opt/llvm/lib:/opt/llvm/lib64:/opt/gcc-9.2.0/lib64
COPY --from=download-llvm /src /src
ENV LLVM_VERSION 9.0.1
RUN ln -s /opt/gcc-9.2.0/bin/gcc /opt/gcc-9.2.0/bin/cc
RUN mkdir -p /build/llvm-${LLVM_VERSION}
WORKDIR /build/llvm-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm -DLLVM_TARGETS_TO_BUILD="X86" /src/llvm-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/clang-${LLVM_VERSION}
WORKDIR /build/clang-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/clang-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/compiler-rt-${LLVM_VERSION}
WORKDIR /build/compiler-rt-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/compiler-rt-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/libcxx-${LLVM_VERSION}
WORKDIR /build/libcxx-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/libcxx-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/libcxxabi-${LLVM_VERSION}
WORKDIR /build/libcxxabi-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/libcxxabi-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/libunwind-${LLVM_VERSION}
WORKDIR /build/libunwind-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/libunwind-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN yum install -y perl elfutils-libelf-devel perl-Data-Dumper
RUN mkdir -p /build/openmp-${LLVM_VERSION}
WORKDIR /build/openmp-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/openmp-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/polly-${LLVM_VERSION}
WORKDIR /build/polly-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/polly-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN mkdir -p /build/lld-${LLVM_VERSION}
WORKDIR /build/lld-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/lld-${LLVM_VERSION}.src
RUN make -j4
RUN make install
RUN yum install -y python-devel ncurses-devel libedit-devel swig
RUN mkdir -p /build/lldb-${LLVM_VERSION}
WORKDIR /build/lldb-${LLVM_VERSION}
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/llvm /src/lldb-${LLVM_VERSION}.src
RUN make -j4
RUN cp -R /build/lldb-${LLVM_VERSION}/lib64/python2.7 /build/lldb-${LLVM_VERSION}/lib/python2.7
RUN make install
FROM centos:7
RUN yum update -y
RUN yum install -y perl libmpc libmpfr libgmp
ENV PATH /opt/llvm/bin:/opt/cmake/bin:/opt/gcc-9.2.0/bin:$PATH
ENV LD_LIBRARY_PATH /opt/llvm/lib:/opt/llvm/lib64:/opt/gcc-9.2.0/lib64
COPY --from=build-llvm /opt /opt
COPY Dockerfile /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.