forked from oven-sh/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.musl
More file actions
164 lines (146 loc) · 7.48 KB
/
Copy pathDockerfile.musl
File metadata and controls
164 lines (146 loc) · 7.48 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
ARG MARCH_FLAG=""
ARG WEBKIT_RELEASE_TYPE=Release
ARG CPU=native
ARG LTO_FLAG="-flto=thin -fno-split-lto-unit -fwhole-program-vtables -fforce-emit-vtables "
ARG LLVM_VERSION="21"
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 alpine:3.23 as base
ARG MARCH_FLAG
ARG WEBKIT_RELEASE_TYPE
ARG CPU
ARG LTO_FLAG
ARG LLVM_VERSION
ARG DEFAULT_CFLAGS
RUN apk update
RUN apk add --no-cache cmake make clang21 clang21-static clang21-dev llvm21-dev llvm21-static musl-dev git lld libgcc gcc g++ libstdc++ build-base lld-dev llvm21-libs libc-dev xz zlib zlib-dev libxml2 libxml2-dev
ENV CXX=clang++-21
ENV CC=clang-21
ENV LDFLAGS='-L/usr/include -L/usr/include/llvm21'
ENV CXXFLAGS="-I/usr/include -I/usr/include/llvm21"
ENV PATH="/usr/bin:/usr/local/bin:/zig/bin:/usr/lib/llvm21/bin:$PATH"
ENV CPU=${CPU}
ENV MARCH_FLAG=${MARCH_FLAG}
ENV WEBKIT_OUT_DIR=/webkitbuild
RUN mkdir -p /output/lib /output/include /output/include/JavaScriptCore /output/include/wtf /output/include/bmalloc /output/include/unicode
ENV AR llvm-ar
ENV RANLIB llvm-ranlib
ENV LD lld
ENV LTO_FLAG="${LTO_FLAG}"
ENV WEBKIT_RELEASE_TYPE="${WEBKIT_RELEASE_TYPE}"
FROM base as build_icu
ARG MARCH_FLAG
ARG WEBKIT_RELEASE_TYPE
ARG CPU
ARG LTO_FLAG
ARG LLVM_VERSION
ARG DEFAULT_CFLAGS
RUN apk add --no-cache cpio curl tar nodejs patch
# Install zstd (for icu/compress-data.ts). Pinned to match Bun's vendored
# decoder so glibc/musl prebuilts compress identically.
ARG ZSTD_VERSION=1.5.7
RUN curl -fsSL "https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz" | tar xz -C /tmp \
&& make -C /tmp/zstd-${ZSTD_VERSION}/programs zstd -j$(nproc) \
&& cp /tmp/zstd-${ZSTD_VERSION}/programs/zstd /usr/local/bin/ \
&& rm -rf /tmp/zstd-${ZSTD_VERSION} \
&& zstd --version
# After tar, patch udata.cpp with a per-item decompression hook (a weak extern
# Bun defines; null in ICU's own tools).
#
# After the first `make` (which produces bin/icupkg), filter data/in/icudt78l.dat
# to drop converters/translit/stringprep/confusables/unames — Bun has zero
# ucnv_/utrans_/usprep_/uspoof_ consumers — then rebuild.
#
# 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).
#
# Finally, repack the filtered .dat with per-item zstd (icu/compress-data.ts).
# Items matching icu/keep-raw.txt stay uncompressed (too expensive to decode lazily).
# The repacked libicudata.a also embeds the trained zstd dictionary.
COPY icu/ /icu-bun/
ADD --checksum=sha256:3a2e7a47604ba702f345878308e6fefeca612ee895cf4a5f222e7955fabfe0c0 https://github.com/unicode-org/icu/releases/download/release-78.3/icu4c-78.3-sources.tgz /icu.tgz
RUN --mount=type=tmpfs,target=/icu \
export G=$(if [ -n "${LTO_FLAG:-}" ]; then echo "-g1"; fi) && \
export CFLAGS="${DEFAULT_CFLAGS} $G ${MARCH_FLAG} $CFLAGS -Os -std=c17 $LTO_FLAG" && \
export CXXFLAGS="${DEFAULT_CFLAGS} $G ${MARCH_FLAG} $CXXFLAGS -Os -std=c++20 -fno-exceptions $LTO_FLAG -fno-c++-static-destructors " && \
export LDFLAGS="-fuse-ld=lld " && \
cd /icu && \
tar -xf /icu.tgz --strip-components=1 && \
rm /icu.tgz && \
patch -p1 < /icu-bun/udata-decompress-hook.patch && \
cd source && \
./configure --enable-static --disable-shared --with-data-packaging=static --disable-samples --disable-debug --disable-tests && \
make -j$(nproc) && \
bin/icupkg -l data/in/icudt78l.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 && \
bin/icupkg --auto_toc_prefix -r data/in/rm.lst data/in/icudt78l.dat data/in/icudt78l_filtered.dat && \
mv -f data/in/icudt78l_filtered.dat data/in/icudt78l.dat && \
rm -rf data/out lib/libicudata.a && make -j$(nproc) && \
make install && cp -r /icu/source/lib/* /output/lib && cp -r /icu/source/i18n/unicode/* /icu/source/common/unicode/* /output/include/unicode && \
node --experimental-strip-types /icu-bun/compress-data.ts data/in/icudt78l.dat /output/lib/libicudata.a --skip /icu-bun/keep-raw.txt --icupkg bin/icupkg
FROM base as build_webkit
ARG MARCH_FLAG
ARG WEBKIT_RELEASE_TYPE
ARG CPU
ARG LTO_FLAG
ARG LLVM_VERSION
ARG DEFAULT_CFLAGS
ARG USE_MIMALLOC
ARG USE_EXTERNAL_MIMALLOC
RUN apk add --no-cache cpio curl file gnupg ninja ruby ruby-getoptlong unzip rsync perl python3 openssl-dev openssl linux-headers
ENV WEBKIT_OUT_DIR=/webkitbuild
# These are unnecessary on musl
# ENV CFLAGS="$CFLAGS -ffat-lto-objects"
# ENV CXXFLAGS="$CXXFLAGS -ffat-lto-objects"
COPY . /webkit
WORKDIR /webkit
COPY --from=build_icu /output /icu
RUN --mount=type=tmpfs,target=/webkitbuild \
export G=$(if [ -n "${LTO_FLAG:-}" ]; then echo "-g1"; fi) && \
export CFLAGS="${DEFAULT_CFLAGS} $G ${MARCH_FLAG} $CFLAGS $LTO_FLAG -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \
export CXXFLAGS="${DEFAULT_CFLAGS} $G ${MARCH_FLAG} $CXXFLAGS $LTO_FLAG -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \
export LDFLAGS="-fuse-ld=lld $LDFLAGS " && \
cd /webkitbuild && \
cmake \
-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 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \
-DENABLE_REMOTE_INSPECTOR=ON \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_AR=$(which llvm-ar) \
-DCMAKE_RANLIB=$(which llvm-ranlib) \
-DCMAKE_C_FLAGS="$CFLAGS" \
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-DICU_ROOT=/icu \
-G Ninja \
/webkit && \
cd /webkitbuild && \
cmake --build /webkitbuild --config ${WEBKIT_RELEASE_TYPE} --target "jsc" --target "testFFI" && \
python3 /webkit/Tools/Scripts/check-classinfo-uniqueness.py $WEBKIT_OUT_DIR/bin/jsc && \
cp -r $WEBKIT_OUT_DIR/lib/*.a /output/lib && \
cp $WEBKIT_OUT_DIR/*.h /output/include && \
cp -r $WEBKIT_OUT_DIR/bin /output/bin && \
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 {} \; && \
find $WEBKIT_OUT_DIR/JavaScriptCore/DerivedSources/ -name "*.json" -exec sh -c 'cp "$1" "/output/$(basename "$1")"' sh {} \; && \
find $WEBKIT_OUT_DIR/JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} /output/include/JavaScriptCore/ \; && \
find $WEBKIT_OUT_DIR/JavaScriptCore/PrivateHeaders/JavaScriptCore/ -name "*.h" -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 && \
echo "";
FROM scratch as artifact
COPY --from=build_icu /output /
COPY --from=build_webkit /output /