forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.ccache
208 lines (164 loc) · 7.64 KB
/
Dockerfile.ccache
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# syntax=docker.io/docker/dockerfile:1.2
# To easily reuse the build cache,
# this Dockerfile uses "RUN --mount=..."
# https://hub.docker.com/r/docker/dockerfile
# SPDX-License-Identifier: CC0-1.0
# Version of LLVM, can "-13", "-14", "-15" or "" (empty for GCC)
ARG LLVM=-15
# Compiler, can be: gcc-10 gcc-11 gcc-12 clang-13 clang-14 clang-15
ARG CC=clang$LLVM
# Linker, can be: lld-13 lld-14 lld-15 or empty
ARG ldPkg=lld$LLVM
ARG LD=ld.$ldPkg
# ARG CFLAGS="-march=native -O3 -falign-functions=64 -fno-semantic-interposition"
# ARG LDFLAGS="-Wl,-O2 -Wl,--as-needed"
##################################################
# vDebian = version of the Debian image
# See https://hub.docker.com/_/debian/
# can be vDebian=testing-20230208-slim
# (testing-20230208-slim ships Clang-13, Clang-14 and Clang-15)
ARG vDebian=testing-slim
FROM docker.io/debian:$vDebian AS base
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/var/cache \
set -ex ;\
apt-get update ;\
echo "Install Git" ;\
apt-get install -y --no-install-recommends \
git \
ca-certificates ;\
echo "Dependencies to configure the Linux kernel" ;\
apt-get install -y --no-install-recommends \
bc \
bison \
cpio \
flex \
kmod \
libelf-dev \
libssl-dev:native \
make ;\
echo "Dependencies to build a Debian package" ;\
apt-get install -y --no-install-recommends \
build-essential:native \
rsync ;\
echo "Dependencies to build ZFS" ;\
apt-get install -y --no-install-recommends \
alien \
autoconf \
automake \
dkms \
fakeroot \
gawk \
libaio-dev \
libattr1-dev \
libblkid-dev \
libcurl4-openssl-dev \
libffi-dev \
libssl-dev \
libtool \
python3 \
python3-dev \
python3-packaging \
uuid-dev \
zlib1g-dev ;\
echo "Optional: pahole for BTF type information" ;\
apt-get install -y --no-install-recommends \
pahole
##################################################
FROM base AS cached
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/var/cache \
echo "Optional: CCache to speedup the next attempts" ;\
apt-get install -y --no-install-recommends \
ccache ;\
ccache --max-files 0 --max-size 0 --show-config
ENV PATH=/usr/lib/ccache:$PATH
##################################################
FROM cached AS compiler
ARG CC
ARG ldPkg
ARG LLVM
ARG llvmPkg=llvm$LLVM
# Install the build chain: compiler, linker...
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/var/cache \
set -x ;\
apt-get install -y --no-install-recommends \
"$CC" \
"$ldPkg" \
$llvmPkg
##################################################
FROM cached AS linux-code
# Kernel version: v5.18.19, v6.1.10 ...
ARG vLinux=linux-rolling-stable
# Clone Linux repo
RUN git clone -b $vLinux --depth 1 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
##################################################
FROM cached AS zfs-code
ARG vZFS=master
# Clone OpenZFS repo
RUN git clone -b "$vZFS" --depth 1 https://github.com/openzfs/zfs
RUN /zfs/autogen.sh
##################################################
FROM compiler AS builder
COPY --from=linux-code /linux /linux
COPY .config /linux/.config
ARG CC
ARG LD
ARG LLVM
RUN make -C linux oldconfig CC="$CC" LD="$LD" LLVM="$LLVM"
# Disable -Werror because Clang fires warnings in OpenZFS source code
RUN echo "CONFIG_WERROR=n" >>linux/.config
# Enable additional dependencies
RUN echo "CONFIG_CRYPTO_DEFLATE=y" >>linux/.config
RUN echo "CONFIG_ZLIB_DEFLATE=y" >>linux/.config
RUN echo "CONFIG_KALLSYMS=y" >>linux/.config
RUN echo "CONFIG_EFI_PARTITION=y" >>linux/.config
# LTO
RUN echo "CONFIG_LTO=y" >>linux/.config
RUN echo "CONFIG_LTO_CLANG=y" >>linux/.config
RUN echo "CONFIG_ARCH_SUPPORTS_LTO_CLANG=y" >>linux/.config
RUN echo "CONFIG_ARCH_SUPPORTS_LTO_CLANG_THIN=y" >>linux/.config
RUN echo "CONFIG_HAS_LTO_CLANG=y" >>linux/.config
RUN echo "CONFIG_LTO_CLANG_FULL=y" >>linux/.config
# Disable deduplicated BTF type information (requires "apt install pahole")
# see: https://stackoverflow.com/q/61657707#71977338
RUN echo "CONFIG_DEBUG_INFO_BTF=n" >>linux/.config
RUN echo "CONFIG_MODULES=y" >>linux/.config
RUN make -C linux mod2yesconfig CC="$CC" LD="$LD" LLVM="$LLVM"
# ARG CFLAGS
# ARG LDFLAGS
RUN set -x ;\
echo "PATH=$PATH" ;\
command -V "$CC" ;\
command -V "$LC" ;\
make -C linux prepare \
CC="$CC" LD="$LD" LLVM="$LLVM"
# KCFLAGS="$CFLAGS" \
# KLDFLAGS+="$LDFLAGS"' $(KCFLAGS)'
COPY --from=zfs-code /zfs /zfs
RUN set -ex ;\
cd /zfs ;\
export CC="$CC" ;\
export LD="$LD" ;\
export LLVM="$LLVM" ;\
./configure -v \
KERNEL_CC="$CC" \
KERNEL_LD="$LD" \
KERNEL_LLVM="$LLVM" \
--disable-debug \
--disable-debuginfo \
--enable-linux-builtin=yes \
--with-linux=/linux ;\
./copy-builtin /linux
# CFLAGS="$CFLAGS $LDFLAGS" \
# Enable built-in ZFS
RUN echo "CONFIG_ZFS=y" >>linux/.config
# Build a Debian package
RUN --mount=type=cache,target=/root/.cache \
--mount=type=cache,target=/var/cache \
make -C /linux modules bindeb-pkg -j $(nproc --all) -l $(nproc --all) || \
make -C /linux modules bindeb-pkg V=1
##################################################
FROM scratch AS final
COPY --from=builder /linux/.config /linux-* /deb-pkg/