Repository navigation
Expand file tree
/
Copy pathDockerfile.android
More file actions
277 lines (257 loc) · 16.2 KB
/
Copy pathDockerfile.android
File metadata and controls
277 lines (257 loc) · 16.2 KB
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
ARG MARCH_FLAG="-march=armv8-a+crc -mtune=cortex-a78"
ARG WEBKIT_RELEASE_TYPE=Release
ARG LTO_FLAG=""
ARG LLVM_VERSION="23"
ARG LLVM_DEBS_SHA256="993eba8b8ca23ea4d6074643d52ff9397b411e6ac5af6b7b2ca09dca2b351011"
ARG NDK_VERSION="r27c"
ARG NDK_SHA256="59c2f6dc96743b5daf5d1626684640b20a6bd2b1d85b13156b90333741bad5cc"
ARG ANDROID_API="28"
ARG ANDROID_ARCH="aarch64"
ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -g -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 "
ARG USE_MIMALLOC="OFF"
ARG USE_EXTERNAL_MIMALLOC="OFF"
FROM ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac AS base
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG LLVM_VERSION
ARG LLVM_DEBS_SHA256
ARG NDK_VERSION
RUN apt-get update && apt-get install -y --no-install-recommends \
wget unzip xz-utils ca-certificates \
cmake ninja-build make git patch \
ruby ruby-getoptlong perl python3 rsync file cpio \
lsb-release software-properties-common gnupg \
&& rm -rf /var/lib/apt/lists/*
# Host clang (same version Bun uses) — we cross-compile via --target/--sysroot,
# not via the NDK's bundled clang. apt.llvm.org installs version-suffixed names
# only (ld.lld-23, not ld.lld), so add unversioned links for -fuse-ld=lld.
# The debs are mirrored from apt.llvm.org to a GitHub release (see
# scripts/mirror-llvm-debs.sh) so the build doesn't depend on apt.llvm.org.
ADD --checksum=sha256:${LLVM_DEBS_SHA256} \
https://github.com/oven-sh/WebKit/releases/download/llvm-${LLVM_VERSION}-debs/llvm-${LLVM_VERSION}-noble-amd64.tar.gz /tmp/llvm.tar.gz
RUN mkdir -p /tmp/llvm && tar xzf /tmp/llvm.tar.gz -C /tmp/llvm && \
apt-get update && apt-get install -y /tmp/llvm/*.deb && \
rm -rf /tmp/llvm /tmp/llvm.tar.gz /var/lib/apt/lists/* && \
for t in clang clang++ ld.lld lld llvm-ar llvm-ranlib; do \
ln -sf /usr/bin/${t}-${LLVM_VERSION} /usr/local/bin/${t}; \
done
ENV CC=clang-${LLVM_VERSION}
ENV CXX=clang++-${LLVM_VERSION}
ENV AR=llvm-ar-${LLVM_VERSION}
ENV RANLIB=llvm-ranlib-${LLVM_VERSION}
ENV LD=lld-${LLVM_VERSION}
# Android NDK — sysroot, libc++, compiler-rt only.
ARG NDK_SHA256
RUN wget -q https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip -O /tmp/ndk.zip \
&& echo "${NDK_SHA256} /tmp/ndk.zip" | sha256sum -c - \
&& unzip -q /tmp/ndk.zip -d /opt \
&& mv /opt/android-ndk-${NDK_VERSION} /opt/android-ndk \
&& rm /tmp/ndk.zip
ENV ANDROID_NDK_ROOT=/opt/android-ndk
ENV NDK_SYSROOT=/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot
# Symlink NDK compiler-rt builtins + libunwind into host clang's resource dir.
# clang's driver hardcodes the lookup path; apt.llvm.org's clang uses the
# old-style flat layout (lib/linux/libclang_rt.builtins-<arch>-android.a)
# while tarball builds use per-triple (lib/<triple>/libclang_rt.builtins.a),
# so populate BOTH. Both target arches done here so the base layer is
# arch-independent and cacheable.
ARG ANDROID_API
RUN set -eux; \
RES=$($CC -print-resource-dir); \
NDK_RT=/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/$(ls /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/)/lib/linux; \
mkdir -p $RES/lib/linux; \
for A in aarch64 x86_64; do \
ln -sf $NDK_RT/libclang_rt.builtins-${A}-android.a $RES/lib/linux/; \
mkdir -p $RES/lib/linux/${A}; \
ln -sf $NDK_RT/${A}/libunwind.a $RES/lib/linux/${A}/; \
DIR=$RES/lib/${A}-unknown-linux-android${ANDROID_API}; \
mkdir -p $DIR; \
ln -sf $NDK_RT/libclang_rt.builtins-${A}-android.a $DIR/libclang_rt.builtins.a; \
ln -sf $NDK_RT/${A}/libunwind.a $DIR/libunwind.a; \
done; \
echo 'int main(){return 0;}' | $CC --target=aarch64-unknown-linux-android${ANDROID_API} --sysroot=$NDK_SYSROOT --rtlib=compiler-rt -fuse-ld=lld -xc - -o /tmp/t && file /tmp/t
# Node runs the generators of Source/JavaScriptCore/aot (>=23.6 strips types by default). The one of Dockerfile.
ARG NODE_VERSION=24.22.1
ARG NODE_SHA256=6c172a9ab6718f7b801fb5a7bd486af2ee5e32758086a04b84fcce2aa77095e6
RUN wget -q "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -O /tmp/node.tar.xz && \
echo "${NODE_SHA256} /tmp/node.tar.xz" | sha256sum -c - && \
tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 && \
rm /tmp/node.tar.xz && \
node --version
# The zstd CLI, for icu/compress-data.ts (built from source: noble's apt has 1.5.5, 1.5.7 matches Bun's vendored decoder).
# Its lib/ sources stay, at /zstd/lib: the jsc shell builds the decoder from them to read that data
# (shell/CMakeLists.txt, BUN_ICU_ZSTD_SOURCE_DIR).
ARG ZSTD_VERSION=1.5.7
ARG ZSTD_SHA256=eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3
RUN wget -q "https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz" -O /tmp/zstd.tar.gz && \
echo "${ZSTD_SHA256} /tmp/zstd.tar.gz" | sha256sum -c - && \
tar xzf /tmp/zstd.tar.gz -C /tmp && \
make -C /tmp/zstd-${ZSTD_VERSION}/programs zstd -j$(nproc) CC=$CC && \
cp /tmp/zstd-${ZSTD_VERSION}/programs/zstd /usr/local/bin/ && \
mkdir /zstd && cp -r /tmp/zstd-${ZSTD_VERSION}/lib /zstd/lib && test -f /zstd/lib/zstd.h && \
rm -rf /tmp/zstd-${ZSTD_VERSION} /tmp/zstd.tar.gz && \
zstd --version
RUN mkdir -p /output/lib /output/include /output/include/JavaScriptCore /output/include/wtf /output/include/bmalloc /output/include/unicode
# ICU's sources and, for this container, its tools. ICU runs them while it builds (pkgdata, genrb, ...), so a cross
# build needs a host build first. Neither depends on the lane, so they are part of the toolchain: no lane downloads
# or rebuilds them.
# Which ICU: icu/source.json, by way of lanes.mjs.
ARG ICU_VERSION
ARG ICU_SHA256
ADD --checksum=sha256:${ICU_SHA256} https://github.com/unicode-org/icu/releases/download/release-${ICU_VERSION}/icu4c-${ICU_VERSION}-sources.tgz /icu.tgz
# Host build (tools only — no LTO, fast).
RUN mkdir -p /icu-host && cd /icu-host \
&& tar -xf /icu.tgz --strip-components=1 \
&& cd source \
&& CC=$CC CXX=$CXX CFLAGS="-Os" CXXFLAGS="-Os" \
./configure --disable-shared --enable-static --disable-samples --disable-tests \
&& make -j$(nproc)
# ───────────────────────────────────────────────────────────────────────────
# ICU — cross-compiled. ICU's autoconf build runs generated tools (gennorm2,
# etc.) at build time, so a host build is required first; the target build
# points at it via --with-cross-build.
# ───────────────────────────────────────────────────────────────────────────
FROM base AS build_icu
ARG ICU_VERSION
ARG MARCH_FLAG
ARG LTO_FLAG
ARG DEFAULT_CFLAGS
ARG ANDROID_API
ARG ANDROID_ARCH
# Target build.
#
# Before configure, filter data/in/icudt<major>l.dat (using the host icupkg) to drop
# converters/translit/stringprep/confusables/unames. Bun has zero
# ucnv_/utrans_/usprep_/uspoof_ consumers (TextCodecICU is removed in
# src/bun.js/bindings/TextEncodingRegistry.cpp). Cuts libicudata.a by ~7.4 MB.
# Most of rbnf/ goes too, but root/ja/zh/zh_Hant stay: ICU reaches those on its own
# through the algorithmic numbering systems in numberingSystems.res (see the note and
# the staleness guard in ./Dockerfile).
#
# udata.cpp gets the per-item decompression hook (a weak extern Bun defines; null in ICU's own tools), and at the end
# the filtered .dat is repacked with per-item zstd (icu/compress-data.ts), as in ./Dockerfile: 25.3 MB > 12.1 MB.
COPY icu/ /icu-bun/
RUN --mount=type=tmpfs,target=/icu \
export TARGET_TRIPLE="${ANDROID_ARCH}-unknown-linux-android${ANDROID_API}" && \
export CROSS_FLAGS="--target=${TARGET_TRIPLE} --sysroot=${NDK_SYSROOT}" && \
export G=$(if [ -n "${LTO_FLAG:-}" ]; then echo "-g1"; fi) && \
export CFLAGS="${CROSS_FLAGS} ${DEFAULT_CFLAGS} $G ${MARCH_FLAG} -Os -std=c17 ${LTO_FLAG}" && \
export CXXFLAGS="${CROSS_FLAGS} ${DEFAULT_CFLAGS} $G ${MARCH_FLAG} -Os -std=c++20 -fno-exceptions ${LTO_FLAG} -fno-c++-static-destructors" && \
export LDFLAGS="${CROSS_FLAGS} --rtlib=compiler-rt -fuse-ld=lld" && \
cd /icu && tar -xf /icu.tgz --strip-components=1 && rm /icu.tgz && \
patch -p1 < /icu-bun/udata-decompress-hook.patch && \
patch -p1 < /icu-bun/decnum-allocation-failure.patch && \
cd source && \
/icu-host/source/bin/icupkg -l data/in/icudt${ICU_VERSION%%.*}l.dat | grep -E '\.(cnv|spp|cfu)$|^cnvalias\.icu$|^translit/|^rbnf/|^unames\.icu$' | grep -vE '^rbnf/(root|res_index|ja|zh|zh_Hant)\.res$' > data/in/rm.lst && \
/icu-host/source/bin/icupkg --auto_toc_prefix -r data/in/rm.lst data/in/icudt${ICU_VERSION%%.*}l.dat data/in/icudt${ICU_VERSION%%.*}l_filtered.dat && \
mv -f data/in/icudt${ICU_VERSION%%.*}l_filtered.dat data/in/icudt${ICU_VERSION%%.*}l.dat && \
{ ./configure --host=${ANDROID_ARCH}-linux-android \
--with-cross-build=/icu-host/source \
--enable-static --disable-shared --with-data-packaging=static \
--disable-samples --disable-tests --disable-debug \
|| { cat config.log; exit 1; }; } && \
make -j$(nproc) && \
cp lib/*.a /output/lib && \
cp -r i18n/unicode/* common/unicode/* /output/include/unicode && \
node --experimental-strip-types /icu-bun/compress-data.ts data/in/icudt${ICU_VERSION%%.*}l.dat /output/lib/libicudata.a --skip /icu-bun/keep-raw.txt --icupkg /icu-host/source/bin/icupkg --cc "$CC --target=${TARGET_TRIPLE}" --ar llvm-ar
# ───────────────────────────────────────────────────────────────────────────
# WebKit (JSCOnly) — cross-compiled via CMake's built-in Android support.
# CMAKE_SYSTEM_NAME=Android + CMAKE_ANDROID_NDK lets CMake derive sysroot,
# libc++, and compiler-rt paths; we override CMAKE_<LANG>_COMPILER so the
# host clang ${LLVM_VERSION} is used instead of the NDK's bundled clang.
# ───────────────────────────────────────────────────────────────────────────
FROM base AS build_webkit
ARG MARCH_FLAG
ARG WEBKIT_RELEASE_TYPE
ARG LTO_FLAG
ARG DEFAULT_CFLAGS
ARG ANDROID_API
ARG ANDROID_ARCH
ARG USE_MIMALLOC
ARG USE_EXTERNAL_MIMALLOC
COPY . /webkit
WORKDIR /webkit
COPY --from=build_icu /output /icu
ENV WEBKIT_OUT_DIR=/webkitbuild
# NOTE: NOT using CMAKE_SYSTEM_NAME=Android — that module force-selects the
# NDK's bundled clang and silently overrides CMAKE_{C,CXX}_COMPILER. Instead,
# treat as a generic Linux cross-compile and pass --target/--sysroot in CFLAGS;
# WebKit's source detects Android via __ANDROID__ (set by --target=*-android*),
# and we set ANDROID=ON so cmake `if(ANDROID)` blocks fire.
#
#
# The programs ship without debug info: each of them would carry another copy of the library's.
#
# find-structures-decoded-behind-calls.py (Tools/Scripts/aot/README.md) reads the machine code of jsc in the optimized lanes: their code is what ships. Here it only prints its rows so far: the list of expected rows was made on Linux x86-64 with glibc.
RUN --mount=type=tmpfs,target=/webkitbuild \
export TARGET_TRIPLE="${ANDROID_ARCH}-unknown-linux-android${ANDROID_API}" && \
export CROSS="--target=${TARGET_TRIPLE} --sysroot=${NDK_SYSROOT}" && \
export G=$(if [ -n "${LTO_FLAG:-}" ]; then echo "-g1"; fi) && \
export CFLAGS="${CROSS} ${DEFAULT_CFLAGS} $G ${MARCH_FLAG} ${LTO_FLAG} -isystem /icu/include -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=." && \
export CXXFLAGS="${CROSS} -isystem ${NDK_SYSROOT}/usr/include/c++/v1 ${DEFAULT_CFLAGS} $G ${MARCH_FLAG} ${LTO_FLAG} -isystem /icu/include -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=." && \
cd /webkitbuild && \
cmake \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=${ANDROID_ARCH} \
-DCMAKE_SYSROOT=${NDK_SYSROOT} \
-DANDROID=ON \
-DCMAKE_C_COMPILER=$(which $CC) \
-DCMAKE_CXX_COMPILER=$(which $CXX) \
-DCMAKE_AR=$(which $AR) \
-DCMAKE_RANLIB=$(which $RANLIB) \
-DPORT=JSCOnly \
-DENABLE_STATIC_JSC=ON \
-DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=${WEBKIT_RELEASE_TYPE} \
-DUSE_THIN_ARCHIVES=OFF \
-DUSE_BUN_JSC_ADDITIONS=ON \
-DUSE_BUN_EVENT_LOOP=ON \
-DUSE_MIMALLOC="$USE_MIMALLOC" \
-DUSE_EXTERNAL_MIMALLOC="$USE_EXTERNAL_MIMALLOC" \
-DENABLE_FTL_JIT=ON \
-DENABLE_API_TESTS=OFF \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \
-DENABLE_REMOTE_INSPECTOR=ON \
-DCMAKE_EXE_LINKER_FLAGS="${CROSS} --rtlib=compiler-rt -fuse-ld=lld" \
-DCMAKE_C_FLAGS="$CFLAGS" \
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-DICU_ROOT=/icu \
-DICU_INCLUDE_DIR=/icu/include \
-DBUN_ICU_ZSTD_SOURCE_DIR=/zstd/lib \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH \
-G Ninja \
/webkit && \
cmake --build /webkitbuild --config ${WEBKIT_RELEASE_TYPE} --target jsc --target testFFI --target testaot && \
python3 /webkit/Tools/Scripts/check-classinfo-uniqueness.py $WEBKIT_OUT_DIR/bin/jsc && \
if [ "$USE_MIMALLOC" = ON ]; then \
PATH="$(dirname "$(readlink -f "$(command -v "$AR")")"):$PATH" python3 /webkit/Tools/Scripts/aot/find-structures-decoded-behind-calls.py $WEBKIT_OUT_DIR/bin/jsc --expected /webkit/Tools/Scripts/aot/structures-decoded-behind-calls-expected.txt || echo "find-structures-decoded-behind-calls.py: not yet fatal here"; \
fi && \
cp -r $WEBKIT_OUT_DIR/lib/*.a /output/lib && \
cp $WEBKIT_OUT_DIR/*.h /output/include && \
cp -r $WEBKIT_OUT_DIR/bin /output/bin && \
"$(echo "$AR" | sed s/llvm-ar/llvm-strip/)" --strip-debug /output/bin/jsc /output/bin/testaot /output/bin/testFFI && \
cp $WEBKIT_OUT_DIR/*.json /output && \
find $WEBKIT_OUT_DIR/JavaScriptCore/DerivedSources/ -name "*.h" -exec sh -c 'cp "$1" "/output/include/JavaScriptCore/$(basename "$1")"' sh {} \; && \
cp $WEBKIT_OUT_DIR/JavaScriptCore/Scripts/CombinedDomains.json /output && \
find $WEBKIT_OUT_DIR/JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} /output/include/JavaScriptCore/ \; && \
find $WEBKIT_OUT_DIR/JavaScriptCore/PrivateHeaders/JavaScriptCore/ \( -name "*.h" -o -name "*.def" -o -name "*.inc" \) -exec cp {} /output/include/JavaScriptCore/ \; && \
cp -r $WEBKIT_OUT_DIR/WTF/Headers/wtf/ /output/include && \
cp -r $WEBKIT_OUT_DIR/bmalloc/Headers/bmalloc/ /output/include && \
mkdir -p /output/Source/JavaScriptCore && \
cp -r /webkit/Source/JavaScriptCore/Scripts /output/Source/JavaScriptCore && \
cp /webkit/Source/JavaScriptCore/create_hash_table /output/Source/JavaScriptCore && \
mkdir -p /output/Source/JavaScriptCore/aot/ir /output/Source/JavaScriptCore/aot/builtins && \
cp /webkit/Source/JavaScriptCore/aot/ir/AOTSchema.def /output/Source/JavaScriptCore/aot/ir && \
cp -r /webkit/Source/JavaScriptCore/aot/ir/schema /output/Source/JavaScriptCore/aot/ir && \
cp -r /webkit/Source/JavaScriptCore/aot/ir/generator /output/Source/JavaScriptCore/aot/ir && \
cp -r /webkit/Source/JavaScriptCore/aot/builtins/generator /output/Source/JavaScriptCore/aot/builtins && \
cp -r $WEBKIT_OUT_DIR/JavaScriptCore/ReleasedSources/aot/builtins/generated /output/Source/JavaScriptCore/aot/builtins && \
mkdir -p /output/Tools/Scripts/aot && \
cp /webkit/Tools/Scripts/aot/find-structures-decoded-behind-calls.py /webkit/Tools/Scripts/aot/calls-that-never-collect.txt /webkit/Tools/Scripts/aot/structures-decoded-behind-calls-expected.txt /output/Tools/Scripts/aot && \
cp -r /webkit/Source/JavaScriptCore/aot/tests /output/Source/JavaScriptCore/aot/tests && \
find /output/Source/JavaScriptCore/aot/tests -type f ! -name '*.ir' -delete
FROM scratch AS artifact
COPY --from=build_icu /output /
COPY --from=build_webkit /output /