-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
177 lines (159 loc) · 6.18 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# syntax=docker/dockerfile:1.4
# Stage 1. Check out LLVM source code and run the build.
FROM launcher.gcr.io/google/debian11:latest as builder
LABEL maintainer "ParaTools Inc."
# Install build dependencies of llvm.
# First, Update the apt's source list and include the sources of the packages.
# Improve caching too
RUN <<EOC
grep deb /etc/apt/sources.list | sed 's/^deb/deb-src /g' >> /etc/apt/sources.list
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
EOC
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache/ ls -l $CCACHE_DIR
# Install compiler, cmake, git, ccache etc.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked <<EOC
apt-get update
apt-get install -y --no-install-recommends ca-certificates \
build-essential cmake ccache make python3 zlib1g wget unzip git
EOC
# use ccache (make it appear in path earlier then /usr/bin/gcc etc)
RUN for p in gcc g++ clang clang++ cc c++; do ln -vs /usr/bin/ccache /usr/local/bin/$p; done
ARG CI=false
# Clone LLVM repo. A shallow clone is faster, but pulling a cached repository is faster yet
RUN --mount=type=cache,target=/git <<EOC
echo "Checking out LLVM."
echo "\$CI = $CI"
# If the job is killed during a git operation the cache might be broken
if [ -f /git/llvm-project.git/index.lock ]; then
echo "index.lock file found--git repo might be in a broken state."
echo "Removing /git/llvm-project.git and forcing a new checkout!"
rm -rf /git/llvm-project.git
fi
if ${CI:-false}; then
# Github CI never seems to use the cached git directory :-[
echo "Running under CI. \$CI=$CI. Shallow cloning will be used if a clone is required."
# export SHALLOW='--depth=1'
fi
if mkdir llvm-project && git --git-dir=/git/llvm-project.git -C llvm-project pull origin release/15.x --ff-only
then
echo "WARNING: Using cached llvm git repository and pulling updates"
cp -r /git/llvm-project.git /llvm-project/.git
git -C /llvm-project reset --hard HEAD
else
echo "Cloning a fresh LLVM repository"
git clone --separate-git-dir=/git/llvm-project.git \
${SHALLOW:-} --single-branch \
--branch=release/15.x \
--filter=blob:none \
https://github.com/llvm/llvm-project.git
if [ -f /llvm-project/.git ]; then
rm -f /llvm-project/.git
fi
cp -r /git/llvm-project.git /llvm-project/.git
fi
cd llvm-project/llvm
mkdir build
ls -lad /git/llvm-project.git
ls -la /llvm-project/.git
if [ -f /llvm-project/.git ]; then
echo "Contents of .git: "
cat /llvm-project/.git
real_git_dir="$(cat /llvm-project/.git | cut -d ' ' -f2)"
echo "Contents of $real_git_dir :"
ls -lad "$real_git_dir"
echo "$real_git_dir"/*
fi
git status
EOC
# Install a newer ninja release. It seems the older version in the debian repos
# randomly crashes when compiling llvm.
RUN <<EOC
wget --no-verbose "https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip"
echo "b901ba96e486dce377f9a070ed4ef3f79deb45f4ffe2938f8e7ddc69cfb3df77 ninja-linux.zip" \
| sha256sum -c
unzip ninja-linux.zip -d /usr/local/bin
rm ninja-linux.zip
EOC
# Configure and build LLVM/Clang components needed by SALT
RUN --mount=type=cache,target=/ccache/ <<EOC
nproc --all || lscpu || true
pwd
if ! git -C /llvm-project status ; then
echo "llvm-project git repository missing or broken!!!"
exit 1
fi
ccache -s
cmake -GNinja \
-DCMAKE_INSTALL_PREFIX=/tmp/llvm \
-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
-S /llvm-project/llvm -B /llvm-project/llvm/build
# Build libraries, headers, and binaries
# Do build
ccache -s
cd /llvm-project/llvm/build
# Actually do the build
ninja install-llvm-libraries install-llvm-headers \
install-clang-libraries install-clang-headers install-clang install-clang-cmake-exports \
install-clang-resource-headers install-llvm-config install-cmake-exports
ccache -s
git -C /llvm-project status
EOC
# Patch installed cmake exports/config files to not throw an error if not all components are installed
COPY patches/ClangTargets.cmake.patch .
COPY patches/LLVMExports.cmake.patch .
RUN <<EOC
find /tmp/llvm -name '*.cmake' -type f
patch --strip 1 --ignore-whitespace < ClangTargets.cmake.patch
patch --strip 1 --ignore-whitespace < LLVMExports.cmake.patch
EOC
# Stage 2. Produce a minimal release image with build results.
FROM launcher.gcr.io/google/debian11:latest
LABEL maintainer "ParaTools Inc."
# Install packages for minimal useful image.
RUN <<EOC
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
EOC
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked <<EOC
apt-get update
apt-get install -y --no-install-recommends libstdc++-10-dev \
ccache libz-dev libelf1 libtinfo-dev make binutils cmake git \
gcc g++ wget
rm -rf /var/lib/apt/lists/*
EOC
# Get ninja from builder
COPY --from=builder /usr/local/bin/ninja /usr/local/bin/
# Copy build results of stage 1 to /usr/local.
COPY --from=builder /tmp/llvm/ /usr/
# Setup ccache
ENV CCACHE_DIR=/home/salt/ccache
RUN <<EOC
for p in gcc g++ clang clang++ cc c++; do
ln -vs /usr/bin/ccache /usr/local/bin/$p
done
EOC
WORKDIR /home/salt/
# Download and install TAU
# http://tau.uoregon.edu/tau.tgz
# http://fs.paratools.com/tau-mirror/tau.tgz
# http://fs.paratools.com/tau-nightly.tgz
RUN --mount=type=cache,target=/home/salt/ccache <<EOC
ccache -s
echo "verbose=off" > ~/.wgetrc
wget http://tau.uoregon.edu/tau.tgz || wget http://fs.paratools.com/tau-mirror/tau.tgz
tar xzvf tau.tgz
cd tau*
./installtau -prefix=/usr/local/ -cc=gcc -c++=g++\
-bfd=download -unwind=download -dwarf=download -otf=download -pthread -iowrapper -j
./installtau -prefix=/usr/local/ -cc=clang -c++=clang++\
-bfd=download -unwind=download -dwarf=download -otf=download -pthread -iowrapper -j
cd ..
rm -rf tau*
ccache -s
EOC
ENV PATH="${PATH}:/usr/local/x86_64/bin"
RUN alias ls="ls --color=auto"