-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
293 lines (277 loc) · 9.99 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
##################################################
## "build" stage
##################################################
FROM docker.io/hectorm/wasm:v62@sha256:4d5b597466a797079637ecdd1042b6c800f02fdaa65b675f13f8d2f48bb698b6 AS build
# Environment
ENV BUILDDIR=/tmp/build
ENV SYSROOT=/tmp/sysroot
ENV PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
ENV PKG_CONFIG_LIBDIR=${SYSROOT}/lib/pkgconfig:${SYSROOT}/share/pkgconfig
ENV PKG_CONFIG_PATH=${PKG_CONFIG_LIBDIR}
ENV EM_PKG_CONFIG_PATH=${PKG_CONFIG_LIBDIR}
ENV CHOST=wasm32-unknown-emscripten
ENV CPPFLAGS='-Wdate-time'
ENV CFLAGS='-O3 -msimd128 -fwasm-exceptions -frandom-seed=42 -Wall -Wextra -Wformat -Werror=format-security'
ENV CXXFLAGS=${CFLAGS}
ENV LDFLAGS='-fwasm-exceptions'
# Build zlib-ng
ARG ZLIB_NG_TREEISH=2.2.1
ARG ZLIB_NG_REMOTE=https://github.com/zlib-ng/zlib-ng.git
WORKDIR ${BUILDDIR}/dep/zlib-ng/
RUN git clone "${ZLIB_NG_REMOTE:?}" ./ \
&& git checkout "${ZLIB_NG_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=OFF \
-D ZLIB_COMPAT=ON \
-D ZLIB_ENABLE_TESTS=OFF \
-D ZLIBNG_ENABLE_TESTS=OFF \
-D WITH_GTEST=OFF \
-D WITH_RUNTIME_CPU_DETECTION=OFF \
-D BASEARCH_X86_FOUND=ON \
-D FORCE_SSE2=ON
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors zlib
# Build brotli
ARG BROTLI_TREEISH=v1.1.0
ARG BROTLI_REMOTE=https://github.com/google/brotli.git
WORKDIR ${BUILDDIR}/dep/brotli/
RUN git clone "${BROTLI_REMOTE:?}" ./ \
&& git checkout "${BROTLI_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_TESTING=OFF
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libbrotlidec
# Build libffi
ARG LIBFFI_TREEISH=v3.4.6
ARG LIBFFI_REMOTE=https://github.com/libffi/libffi.git
WORKDIR ${BUILDDIR}/dep/libffi/
RUN git clone "${LIBFFI_REMOTE:?}" ./ \
&& git checkout "${LIBFFI_TREEISH:?}" \
&& git submodule update --init --recursive
RUN NOCONFIGURE=1 ./autogen.sh
RUN emconfigure ./configure \
--prefix="${SYSROOT:?}" \
--libdir="${SYSROOT:?}"/lib \
--host="${CHOST:?}" \
--enable-static \
--disable-shared \
--disable-docs
RUN emmake make -j"$(nproc)" install
RUN pkg-config --static --exists --print-errors libffi
# Build glib
ARG GLIB_TREEISH=2.82.0
ARG GLIB_REMOTE=https://github.com/GNOME/glib.git
WORKDIR ${BUILDDIR}/dep/glib/
RUN git clone "${GLIB_REMOTE:?}" ./ \
&& git checkout "${GLIB_TREEISH:?}" \
&& git submodule update --init --recursive
# Apply patch for Emscripten (https://github.com/kleisauke/glib)
RUN curl -sSL "https://github.com/GNOME/glib/compare/${GLIB_TREEISH:?}...kleisauke:wasm-vips-${GLIB_TREEISH:?}.patch" | patch -p1
RUN emconfigure meson setup ./build/ \
--prefix="${SYSROOT:?}" \
--libdir="${SYSROOT:?}"/lib \
--cross-file="${CHOST:?}" \
--buildtype=release \
--default-library=static \
--force-fallback-for=gvdb,zlib \
-D man-pages=disabled \
-D documentation=false \
-D tests=false \
-D nls=disabled \
-D selinux=disabled \
-D xattr=false \
-D libmount=disabled \
-D glib_assert=false \
-D glib_checks=false
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors glib-2.0
# Build highway
ARG HIGHWAY_TREEISH=1.2.0
ARG HIGHWAY_REMOTE=https://github.com/google/highway.git
WORKDIR ${BUILDDIR}/dep/highway/
RUN git clone "${HIGHWAY_REMOTE:?}" ./ \
&& git checkout "${HIGHWAY_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_TESTING=OFF
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libhwy
# Build libspng
ARG LIBSPNG_TREEISH=v0.7.4
ARG LIBSPNG_REMOTE=https://github.com/randy408/libspng.git
WORKDIR ${BUILDDIR}/dep/libspng/
RUN git clone "${LIBSPNG_REMOTE:?}" ./ \
&& git checkout "${LIBSPNG_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_FLAGS="${CFLAGS:-} -msse4.2 -DSPNG_SSE=4 -D__x86_64__" \
-D SPNG_STATIC=ON \
-D SPNG_SHARED=OFF \
-D BUILD_EXAMPLES=OFF
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libspng_static
# Build libjpeg-turbo
ARG LIBJPEG_TURBO_TREEISH=3.0.3
ARG LIBJPEG_TURBO_REMOTE=https://github.com/libjpeg-turbo/libjpeg-turbo.git
WORKDIR ${BUILDDIR}/dep/libjpeg-turbo/
RUN git clone "${LIBJPEG_TURBO_REMOTE:?}" ./ \
&& git checkout "${LIBJPEG_TURBO_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D ENABLE_STATIC=ON \
-D ENABLE_SHARED=OFF \
-D WITH_JPEG8=ON \
-D WITH_TURBOJPEG=OFF \
-D WITH_SIMD=0
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libjpeg
# Build libjxl
ARG LIBJXL_TREEISH=v0.10.3
ARG LIBJXL_REMOTE=https://github.com/libjxl/libjxl.git
WORKDIR ${BUILDDIR}/dep/libjxl/
RUN git clone "${LIBJXL_REMOTE:?}" ./ \
&& git checkout "${LIBJXL_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D JPEGXL_STATIC=ON \
-D JPEGXL_FORCE_SYSTEM_BROTLI=ON \
-D JPEGXL_FORCE_SYSTEM_HWY=ON \
-D JPEGXL_BUNDLE_LIBPNG=OFF \
-D JPEGXL_ENABLE_JPEGLI=OFF \
-D JPEGXL_ENABLE_MANPAGES=OFF \
-D JPEGXL_ENABLE_DOXYGEN=OFF \
-D JPEGXL_ENABLE_TOOLS=OFF \
-D JPEGXL_ENABLE_VIEWERS=OFF \
-D JPEGXL_ENABLE_DEVTOOLS=OFF \
-D JPEGXL_ENABLE_EXAMPLES=OFF \
-D JPEGXL_ENABLE_COVERAGE=OFF \
-D JPEGXL_ENABLE_FUZZERS=OFF \
-D JPEGXL_ENABLE_BENCHMARK=OFF \
-D BUILD_TESTING=OFF
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libjxl
# Build libwebp
ARG LIBWEBP_TREEISH=v1.4.0
ARG LIBWEBP_REMOTE=https://github.com/webmproject/libwebp.git
WORKDIR ${BUILDDIR}/dep/libwebp/
RUN git clone "${LIBWEBP_REMOTE:?}" ./ \
&& git checkout "${LIBWEBP_TREEISH:?}" \
&& git submodule update --init --recursive
RUN emcmake cmake -G 'Ninja' -S ./ -B ./build/ \
-D CMAKE_INSTALL_PREFIX="${SYSROOT:?}" \
-D CMAKE_INSTALL_LIBDIR="${SYSROOT:?}"/lib \
-D CMAKE_FIND_ROOT_PATH="${SYSROOT:?}" \
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=OFF \
-D WEBP_ENABLE_SIMD=OFF \
-D WEBP_USE_THREAD=OFF \
-D WEBP_BUILD_CWEBP=OFF \
-D WEBP_BUILD_DWEBP=OFF \
-D WEBP_BUILD_GIF2WEBP=OFF \
-D WEBP_BUILD_IMG2WEBP=OFF \
-D WEBP_BUILD_VWEBP=OFF \
-D WEBP_BUILD_WEBPINFO=OFF \
-D WEBP_BUILD_LIBWEBPMUX=OFF \
-D WEBP_BUILD_WEBPMUX=OFF \
-D WEBP_BUILD_ANIM_UTILS=OFF \
-D WEBP_BUILD_EXTRAS=OFF
RUN emmake ninja -C ./build/ install
RUN pkg-config --static --exists --print-errors libwebp
# Build Chafa
ARG CHAFA_TREEISH=1.14.4
ARG CHAFA_REMOTE=https://github.com/hpjansson/chafa.git
WORKDIR ${BUILDDIR}/dep/chafa/
RUN git clone "${CHAFA_REMOTE:?}" ./ \
&& git checkout "${CHAFA_TREEISH:?}" \
&& git submodule update --init --recursive
RUN NOCONFIGURE=1 ./autogen.sh
RUN emconfigure ./configure \
--prefix="${SYSROOT:?}" \
--libdir="${SYSROOT:?}"/lib \
--host="${CHOST:?}" \
--enable-static \
--disable-shared \
--disable-man \
--disable-gtk-doc \
--without-tools
RUN emmake make -j"$(nproc)" install
RUN pkg-config --static --exists --print-errors chafa
# Build Chafa WebAssembly module
COPY --chown=wasm:wasm ./src/ ${BUILDDIR}/src/
WORKDIR ${BUILDDIR}/src/
RUN mkdir "${BUILDDIR:?}"/dist/
RUN em++ ${CPPFLAGS-} ${CXXFLAGS-} ${LDFLAGS-} \
"${BUILDDIR:?}"/src/chafa.cpp \
--post-js "${BUILDDIR:?}"/src/chafa.js \
-I"${SYSROOT:?}"/include \
-I"${SYSROOT:?}"/include/chafa \
-I"${SYSROOT:?}"/lib/chafa/include \
-I"${SYSROOT:?}"/include/glib-2.0 \
-L"${SYSROOT:?}"/lib \
-I"${SYSROOT:?}"/lib/glib-2.0/include \
-lembind -lchafa -lglib-2.0 \
$(pkg-config --libs --cflags zlib) \
$(pkg-config --libs --cflags libbrotlicommon) \
$(pkg-config --libs --cflags libbrotlidec) \
$(pkg-config --libs --cflags libhwy) \
$(pkg-config --libs --cflags libspng_static) \
$(pkg-config --libs --cflags libjpeg) \
$(pkg-config --libs --cflags libjxl) \
$(pkg-config --libs --cflags libwebp) \
-s ENVIRONMENT=web,worker,node \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=Chafa \
-s EXPORTED_FUNCTIONS=["$(paste -sd, "${BUILDDIR:?}"/src/exported_functions.txt)"] \
-s EXPORTED_RUNTIME_METHODS=["$(paste -sd, "${BUILDDIR:?}"/src/exported_runtime_methods.txt)"] \
-s STRICT=1 \
-s WASM_BIGINT=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s IGNORE_MISSING_MAIN=1 \
-s DYNAMIC_EXECUTION=0 \
-s FILESYSTEM=0 \
-s POLYFILL=0 \
--closure 1 \
--extern-pre-js "${BUILDDIR:?}"/src/pre.txt \
-o "${BUILDDIR:?}"/dist/chafa.js
##################################################
## "dist" stage
##################################################
FROM scratch AS dist
COPY --from=build /tmp/build/dist/chafa.js /
COPY --from=build /tmp/build/dist/chafa.wasm /