-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
149 lines (127 loc) · 5.8 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
FROM microblinkdev/microblink-ninja:1.12.1 as ninja
FROM phusion/baseimage:noble-1.0.0 AS builder
ARG BUILDPLATFORM
ARG LLVM_VERSION=18.1.6
ARG CMAKE_VERSION=3.29.3
# setup build environment
RUN mkdir /home/build
COPY --from=ninja /usr/local/bin/ninja /usr/local/bin/
ENV NINJA_STATUS="[%f/%t %c/sec] "
RUN echo "BUILDPLATFORM is ${BUILDPLATFORM}"
# install packages required for build
RUN apt update -y && apt upgrade -y
RUN apt install -y bzip2 zip libedit-dev libxml2-dev libncurses-dev swig lzma g++ binutils-dev git openssl python3-pip python3-dev
# make sure bash is used instead of /bin/sh for RUN commands
RUN ln -f -s /usr/bin/bash /bin/sh
# download and install CMake
RUN cd /home && \
if [ "$BUILDPLATFORM" == "linux/arm64" ]; then arch=aarch64; else arch=x86_64; fi && \
curl -o cmake.tar.gz -L https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-${arch}.tar.gz && \
tar xf cmake.tar.gz && \
mv cmake-${CMAKE_VERSION}-linux-${arch} cmake
ENV PATH="/home/cmake/bin:${PATH}"
# clone LLVM
RUN cd /home/build && \
git clone --depth 1 --branch microblink-llvmorg-${LLVM_VERSION} https://github.com/microblink/llvm-project
# build LLVM in two stages
RUN cd /home/build && \
mkdir llvm-build-stage1 && \
cd llvm-build-stage1 && \
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
# For some weird reason building libc++abi.so.1 with LTO enabled creates a broken binary
-DLLVM_ENABLE_LTO=OFF \
-DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLLVM_TARGETS_TO_BUILD="Native" \
-DLLVM_BINUTILS_INCDIR="/usr/include" \
-DLLVM_ENABLE_EH=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_UNWINDLIB=libgcc \
-DCLANG_DEFAULT_LINKER=lld \
-DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=YES \
-DLIBCXX_ABI_VERSION=2 \
-DLIBCXX_ABI_UNSTABLE=ON \
-DLIBCXX_ENABLE_EXCEPTIONS=OFF \
-DLIBCXX_ENABLE_RTTI=OFF \
-DLIBCXX_INCLUDE_BENCHMARKS=OFF \
-DLIBCXX_INCLUDE_TESTS=OFF \
-DLIBCXX_INCLUDE_DOCS=OFF \
/home/build/llvm-project/llvm && \
ninja clang compiler-rt unwind cxx lib/LLVMgold.so llvm-ar llvm-ranlib llvm-nm lld
# second stage - use built clang to build entire LLVM
ENV CC="/home/build/llvm-build-stage1/bin/clang" \
CXX="/home/build/llvm-build-stage1/bin/clang++" \
LD_LIBRARY_PATH="/home/build/llvm-build-stage1/lib/x86_64-unknown-linux-gnu:/home/build/llvm-build-stage1/lib/aarch64-unknown-linux-gnu" \
LIBRARY_PATH="/usr/lib/gcc/aarch64-linux-gnu/11:/usr/lib/gcc/x86_64-linux-gnu/11"
RUN cd /home/build && \
if [ "$BUILDPLATFORM" == "linux/arm64" ]; then additional_flags="-Ofast"; else additional_flags="-Ofast -mavx"; fi && \
mkdir llvm-build-stage2 && \
cd llvm-build-stage2 && \
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;polly;clang-tools-extra" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;WebAssembly;X86" \
-DLLVM_ENABLE_LTO=Thin \
-DLLVM_PARALLEL_LINK_JOBS=3 \
-DLLVM_BINUTILS_INCDIR="/usr/include" \
-DLLVM_USE_LINKER="lld" \
-DCMAKE_C_FLAGS="-B/usr/local -fsplit-lto-unit $additional_flags" \
-DCMAKE_CXX_FLAGS="-B/usr/local -fsplit-lto-unit $additional_flags" \
-DCMAKE_AR="/home/build/llvm-build-stage1/bin/llvm-ar" \
-DCMAKE_RANLIB="/home/build/llvm-build-stage1/bin/llvm-ranlib" \
-DCMAKE_NM="/home/build/llvm-build-stage1/bin/llvm-nm" \
-DLLVM_ENABLE_EH=OFF \
-DLLVM_ENABLE_RTTI=OFF \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON \
-DCMAKE_INSTALL_PREFIX=/home/llvm \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DCLANG_DEFAULT_LINKER=lld \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_UNWINDLIB=libunwind \
-DLIBCXX_USE_COMPILER_RT=YES \
-DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=YES \
-DLIBCXXABI_USE_COMPILER_RT=YES \
-DLIBCXX_ABI_VERSION=2 \
-DLIBCXX_ABI_UNSTABLE=ON \
-DLIBCXX_ENABLE_EXCEPTIONS=OFF \
-DLIBCXX_ENABLE_RTTI=ON \
-DLLDB_ENABLE_PYTHON=ON \
-DLIBCXX_INCLUDE_BENCHMARKS=OFF \
-DLIBCXX_INCLUDE_TESTS=OFF \
-DLIBCXX_INCLUDE_DOCS=OFF \
-DLIBUNWIND_ENABLE_ASSERTIONS=OFF \
/home/build/llvm-project/llvm && \
ninja
# install everything
RUN cd /home/build/llvm-build-stage2 && \
ninja install
# Stage 2, copy artifacts to new image and prepare environment
FROM phusion/baseimage:noble-1.0.0
COPY --from=builder /home/llvm /usr/local/
# GCC is needed for providing crtbegin.o, crtend.o and friends, that are also used by clang
# Note: G++ is not needed
# ncurses-devel is needed when developing LLVM-based tools
# openssl11 is dependency of python3, which is a dependency of LLDB
RUN apt update && apt upgrade -y
RUN apt install -y libc-dev libatomic1 openssl libedit-dev libncurses-dev python3-pip
ENV CC="/usr/local/bin/clang" \
CXX="/usr/local/bin/clang++" \
AR="/usr/local/bin/llvm-ar" \
NM="/usr/local/bin/llvm-nm" \
RANLIB="/usr/local/bin/llvm-ranlib" \
LIBRARY_PATH="/usr/lib/gcc/aarch64-linux-gnu/13:/usr/lib/gcc/x86_64-linux-gnu/13"
# make sure bash is used instead of /bin/sh for RUN commands
RUN ln -f -s /usr/bin/bash /bin/sh
CMD ["/usr/bin/bash"]