Repository navigation
Expand file tree
/
Copy pathDockerfile.macos
More file actions
296 lines (278 loc) · 17 KB
/
Copy pathDockerfile.macos
File metadata and controls
296 lines (278 loc) · 17 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Cross-compiles JavaScriptCore (PORT=JSCOnly) for macOS on a Linux host:
# clang --target=<arch>-apple-macosx against a pinned macOS SDK, linked with
# ld64.lld.
#
# Differences from a build on a Mac:
# - The linker is ld64.lld instead of Apple's ld (required: there is no
# Apple ld for Linux). Only executables (LLIntOffsetsExtractor, jsc) are
# linked; the shipped artifacts are static archives.
# - `mig` is Apple's migcom rebuilt as a Linux host tool (see macos-cross/).
# - libc++ headers come from the SDK (Apple's libc++), forced via
# -nostdinc++ so the host LLVM's libc++ can never leak in.
# - ICU resolves to the SDK's libicucore.tbd + WebKit's bundled headers
# (USE_APPLE_ICU), same as the native build. No ICU is built or bundled.
ARG MACOS_ARCH="arm64"
# The SDK version + the Command Line Tools release that contains it, as served
# by Apple's software-update catalog (`bun macos-cross/xmac.mjs list`). The
# deployment target — not the SDK — controls the oldest macOS the artifacts
# run on, so this tracks the newest SDK Apple serves. Apple's catalog is a
# rolling window: when this release stops being served, run `list` and bump
# the pins. The sha256 is of the .pkg that `download` leaves in the cache.
ARG MACOS_SDK_VERSION="26.5"
ARG MACOS_SDK_CLT_RELEASE="26.5"
ARG MACOS_SDK_PKG_SHA256="5f044578cd78a3a9b9c965a42d56bad609ee5d252e1d4e6aa7c42fc3f35fee7b"
ARG MACOS_DEPLOYMENT_TARGET="13.0"
# Bun runs the vendored xmac tool that fetches the SDK from Apple.
ARG BUN_VERSION="1.4.4"
ARG BUN_SHA256="bf8ccbfb2b0b80159e0f9a6d15c55317add8077534dbc6130a3edb52fccb395c"
ARG WEBKIT_RELEASE_TYPE=Release
ARG LTO_FLAG=""
ARG MARCH_FLAG="-mcpu=apple-m1"
ARG LLVM_VERSION="23"
ARG LLVM_DEBS_SHA256="993eba8b8ca23ea4d6074643d52ff9397b411e6ac5af6b7b2ca09dca2b351011"
ARG BOOTSTRAP_CMDS_TAG="bootstrap_cmds-138"
ARG BOOTSTRAP_CMDS_COMMIT="c71d2d72f48995baaea76148f61002e5299841de"
# What every variant is compiled with. Cross-only additions live in the build stage.
# -fno-standalone-debug is clang's default on Linux: a type is fully described only in the translation units that need its definition.
ARG DEFAULT_CFLAGS="-fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -O3 -g -fno-standalone-debug -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -faddrsig "
# Per-variant extras (CPP_FLAGS in .github/scripts/lanes.mjs), e.g.
# -D_LIBCXX_ENABLE_ASSERTIONS=1 for Debug.
ARG CPP_FLAGS=""
ARG ENABLE_MALLOC_HEAP_BREAKDOWN="OFF"
# "address,undefined" for the -asan variants. Linking sanitized executables
# for a darwin target needs the darwin sanitizer runtime dylibs, which a
# Linux LLVM install doesn't ship — they're extracted from the mirrored
# compiler-rt tarball below into clang's resource dir. arm64-only (the
# official LLVM macOS release is arm64-only), so x86_64 ASAN variants would
# fail to link.
ARG ENABLE_SANITIZERS=""
ARG USE_MIMALLOC="OFF"
ARG USE_EXTERNAL_MIMALLOC="OFF"
ARG COMPILER_RT_DARWIN_TAG="compiler-rt-darwin-23.1.1"
ARG COMPILER_RT_DARWIN_SHA256="35241a2d4cff6119b78279ace69cf89c9a190bd5ec7d2baa8d9d7f2a45d9957b"
FROM ubuntu:24.04@sha256:68ee22004a9109b44973313b02ff7b1de250f1de0f5ecb628d73f579aaff33ac AS base
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ARG LLVM_VERSION
ARG LLVM_DEBS_SHA256
ARG MACOS_ARCH
ARG MACOS_SDK_VERSION
ARG MACOS_SDK_CLT_RELEASE
ARG MACOS_SDK_PKG_SHA256
ARG MACOS_DEPLOYMENT_TARGET
ARG BUN_VERSION
ARG BUN_SHA256
ARG COMPILER_RT_DARWIN_TAG
ARG COMPILER_RT_DARWIN_SHA256
RUN apt-get update && apt-get install -y --no-install-recommends \
wget unzip xz-utils ca-certificates \
cmake ninja-build make git \
ruby ruby-getoptlong perl python3 rsync file cpio \
flex bison \
lsb-release software-properties-common gnupg \
&& rm -rf /var/lib/apt/lists/*
# Host clang (same version Bun uses) — we cross-compile via --target/-isysroot
# and link with ld64.lld (lld's Mach-O port). 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 it.
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++ ld64.lld lld llvm-ar llvm-ranlib llvm-nm llvm-cxxfilt; 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}
# Bun — only used to run the vendored xmac tool below.
RUN wget -q "https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/bun-linux-x64.zip" -O /tmp/bun.zip && \
echo "${BUN_SHA256} /tmp/bun.zip" | sha256sum -c - && \
unzip -q /tmp/bun.zip -d /tmp && \
install -m 0755 /tmp/bun-linux-x64/bun /usr/local/bin/bun && \
rm -rf /tmp/bun.zip /tmp/bun-linux-x64 && \
bun --version
# macOS SDK — headers, libc++, framework headers, and the .tbd linker stubs
# for libSystem/libicucore/etc. Downloaded directly from Apple's public
# software-update CDN (the Command Line Tools SDK sub-package) by xmac — the
# same tool Bun's own macOS cross-compile uses (scripts/build/macos-sdk.ts) and
# the same model xwin uses for the Windows SDK: every build downloads from
# Apple itself, nothing is redistributed. Integrity is verified against the
# SHA-1 checksums in the package's signed xar table of contents.
COPY macos-cross/xmac.mjs /xmac.mjs
RUN bun /xmac.mjs download --accept-license \
--release "${MACOS_SDK_CLT_RELEASE}" --sdk "${MACOS_SDK_VERSION}" \
--cache-dir /tmp/xmac-cache && \
echo "${MACOS_SDK_PKG_SHA256} $(echo /tmp/xmac-cache/dl/*/*.pkg)" | sha256sum -c - && \
bun /xmac.mjs splat --offline --accept-license --sdk-only \
--release "${MACOS_SDK_CLT_RELEASE}" --sdk "${MACOS_SDK_VERSION}" \
--output /tmp/xmac-out --cache-dir /tmp/xmac-cache && \
mkdir -p /opt && \
mv /tmp/xmac-out/SDKs/MacOSX${MACOS_SDK_VERSION}.sdk /opt/MacOSX${MACOS_SDK_VERSION}.sdk && \
rm -rf /tmp/xmac-out /tmp/xmac-cache && \
test -f /opt/MacOSX${MACOS_SDK_VERSION}.sdk/usr/include/sys/syscall.h
ENV MACOS_SDK=/opt/MacOSX${MACOS_SDK_VERSION}.sdk
# Darwin compiler-rt runtimes (sanitizers + builtins), needed to link
# -fsanitize=address executables for the target. Extracted from the official
# LLVM macOS release and mirrored to a GitHub release so the build doesn't
# pull the full 1.5 GB LLVM distribution (same pattern as gcc-13-focal-debs
# in Dockerfile). Installed into clang's resource dir where the darwin
# driver looks for libclang_rt.*_osx*.
ADD --checksum=sha256:${COMPILER_RT_DARWIN_SHA256} \
https://github.com/oven-sh/WebKit/releases/download/${COMPILER_RT_DARWIN_TAG}/compiler-rt-darwin-23.1.1-arm64.tar.gz /compiler-rt-darwin.tar.gz
RUN tar -xzf /compiler-rt-darwin.tar.gz -C /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}/lib/ && \
rm /compiler-rt-darwin.tar.gz && \
test -f /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
# Sanity check: compile + link a Mach-O executable for the target.
RUN echo 'int main(void){return 0;}' | \
$CC --target=${MACOS_ARCH}-apple-macosx -isysroot $MACOS_SDK \
-mmacosx-version-min=${MACOS_DEPLOYMENT_TARGET} \
--ld-path=$(which ld64.lld) -mlinker-version=705 -xc - -o /tmp/t && \
file /tmp/t | grep -q Mach-O && rm /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
RUN mkdir -p /output/lib /output/include /output/include/JavaScriptCore /output/include/wtf /output/include/bmalloc
# ───────────────────────────────────────────────────────────────────────────
# mig — the Mach Interface Generator. WTF's APPLE branch runs it on
# MachExceptions.defs to generate the mach_exc RPC stubs its Mach-exception
# signal handling (Wasm OOB trapping, VM watchdog traps) compiles in.
# Apple's migcom is a plain flex/bison program; build it as a host tool
# against the minimal mach type stubs in macos-cross/. See
# macos-cross/README.md for why this is sound.
# ───────────────────────────────────────────────────────────────────────────
# Part of `base`: it is the same for every lane.
ARG BOOTSTRAP_CMDS_TAG
ARG BOOTSTRAP_CMDS_COMMIT
COPY macos-cross/ /macos-cross/
RUN git clone --depth=1 --branch ${BOOTSTRAP_CMDS_TAG} \
https://github.com/apple-oss-distributions/bootstrap_cmds.git /bootstrap_cmds && \
test "$(git -C /bootstrap_cmds rev-parse HEAD)" = "${BOOTSTRAP_CMDS_COMMIT}" && \
cd /bootstrap_cmds/migcom.tproj && \
flex -o lexxer.c lexxer.l && \
bison -d -o parser.c parser.y && \
cp parser.h y.tab.h && \
$CC -O2 -w -I. -I/macos-cross "-D__private_extern__=" -Ulinux \
"-DMIG_VERSION=\"${BOOTSTRAP_CMDS_TAG}-linux\"" \
-o /usr/local/bin/migcom \
error.c global.c header.c mig.c routine.c server.c statement.c \
string.c type.c user.c utils.c lexxer.c parser.c && \
install -m 0755 /macos-cross/mig /usr/local/bin/mig && \
migcom -version && \
rm -rf /bootstrap_cmds
# ───────────────────────────────────────────────────────────────────────────
# WebKit (JSCOnly)
# ───────────────────────────────────────────────────────────────────────────
FROM base AS build_webkit
ARG MACOS_ARCH
ARG MACOS_DEPLOYMENT_TARGET
ARG WEBKIT_RELEASE_TYPE
ARG LTO_FLAG
ARG MARCH_FLAG
ARG DEFAULT_CFLAGS
ARG CPP_FLAGS
ARG ENABLE_MALLOC_HEAP_BREAKDOWN
ARG ENABLE_SANITIZERS
ARG USE_MIMALLOC
ARG USE_EXTERNAL_MIMALLOC
COPY . /webkit
WORKDIR /webkit
ENV WEBKIT_OUT_DIR=/webkitbuild
# MIGCC/MIGCOM drive macos-cross/mig (the cmake rule just invokes `mig`).
# CMAKE_SYSTEM_NAME=Darwin puts cmake in cross mode and makes APPLE true, so
# WebKit takes the same branches the native macOS build does (USE_APPLE_ICU,
# U_DISABLE_RENAMING, MachExceptions, cocoa/MemoryFootprintCocoa.cpp).
# CMAKE_OSX_SYSROOT/-DEPLOYMENT_TARGET add -isysroot/-mmacosx-version-min.
#
#
# 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 CROSS="--target=${MACOS_ARCH}-apple-macosx" && \
export MIGCC="$(which $CC) -E ${CROSS} -isysroot ${MACOS_SDK}" && \
export MIGCOM="$(which migcom)" && \
export ENABLE_ASSERTS="AUTO" && \
if [ -n "${ENABLE_SANITIZERS}" ]; then export ENABLE_ASSERTS="ON"; fi && \
export SANITIZER_RPATH=$(if [ -n "${ENABLE_SANITIZERS}" ]; then echo "-Wl,-rpath,@executable_path"; fi) && \
export G=$(if [ -n "${LTO_FLAG:-}" ]; then echo "-g1"; fi) && \
export CFLAGS="${CROSS} ${DEFAULT_CFLAGS} $G ${CPP_FLAGS} ${MARCH_FLAG} ${LTO_FLAG} -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=." && \
export CXXFLAGS="${CROSS} -nostdinc++ -isystem ${MACOS_SDK}/usr/include/c++/v1 ${DEFAULT_CFLAGS} $G ${CPP_FLAGS} ${MARCH_FLAG} ${LTO_FLAG} -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=." && \
cd /webkitbuild && \
cmake \
-DCMAKE_SYSTEM_NAME=Darwin \
-DCMAKE_SYSTEM_PROCESSOR=${MACOS_ARCH} \
-DCMAKE_OSX_SYSROOT=${MACOS_SDK} \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_DEPLOYMENT_TARGET} \
-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 \
-DENABLE_MALLOC_HEAP_BREAKDOWN=${ENABLE_MALLOC_HEAP_BREAKDOWN} \
-DENABLE_SANITIZERS="${ENABLE_SANITIZERS}" \
-DENABLE_ASSERTS="${ENABLE_ASSERTS}" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \
-DENABLE_REMOTE_INSPECTOR=ON \
-DCMAKE_EXE_LINKER_FLAGS="${CROSS} --ld-path=$(which ld64.lld) -mlinker-version=705 ${SANITIZER_RPATH}" \
-DCMAKE_C_FLAGS="$CFLAGS" \
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
-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 && \
# -L everywhere: WebKit's cmake stages the WTF/bmalloc framework headers
# as *symlinks* into the source tree when the host filesystem supports
# them. Copied verbatim they'd dangle outside this container (pointing at
# /webkit/...), so dereference every copy into /output.
cp -rL $WEBKIT_OUT_DIR/lib/*.a /output/lib && \
cp -L $WEBKIT_OUT_DIR/cmakeconfig.h /output/include/cmakeconfig.h && \
cp -rL $WEBKIT_OUT_DIR/WTF/Headers/wtf /output/include && \
cp -rL $WEBKIT_OUT_DIR/ICU/Headers/* /output/include && \
mkdir -p /output/include/wtf/include && \
cp -rL /webkit/Source/WTF/icu/unicode /output/include/wtf/include && \
cp -rL $WEBKIT_OUT_DIR/bmalloc/Headers/bmalloc /output/include && \
cp -fL $WEBKIT_OUT_DIR/JavaScriptCore/Headers/JavaScriptCore/* /output/include/JavaScriptCore/ && \
cp -fL $WEBKIT_OUT_DIR/JavaScriptCore/PrivateHeaders/JavaScriptCore/* /output/include/JavaScriptCore/ && \
cp -fL $WEBKIT_OUT_DIR/JavaScriptCore/DerivedSources/*.h /output/include/JavaScriptCore/ && \
cp -fL $WEBKIT_OUT_DIR/JavaScriptCore/DerivedSources/*/*.h /output/include/JavaScriptCore/ && \
mkdir -p /output/Source/JavaScriptCore && \
cp -rL /webkit/Source/JavaScriptCore/Scripts /output/Source/JavaScriptCore && \
cp -L /webkit/Source/JavaScriptCore/create_hash_table /output/Source/JavaScriptCore && \
mkdir -p /output/Source/JavaScriptCore/aot/ir /output/Source/JavaScriptCore/aot/builtins && \
cp -L /webkit/Source/JavaScriptCore/aot/ir/AOTSchema.def /output/Source/JavaScriptCore/aot/ir && \
cp -rL /webkit/Source/JavaScriptCore/aot/ir/schema /output/Source/JavaScriptCore/aot/ir && \
cp -rL /webkit/Source/JavaScriptCore/aot/ir/generator /output/Source/JavaScriptCore/aot/ir && \
cp -rL /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 -rL /webkit/Source/JavaScriptCore/aot/tests /output/Source/JavaScriptCore/aot/tests && \
find /output/Source/JavaScriptCore/aot/tests -type f ! -name '*.ir' -delete && \
cp -rL $WEBKIT_OUT_DIR/bin /output/bin && \
# The sanitizer runtime is a dylib the executables name as @rpath/libclang_rt.asan_osx_dynamic.dylib, and the rpath
# clang adds is this container's resource directory. So it ships next to them, and @executable_path is an rpath.
if [ -n "${ENABLE_SANITIZERS}" ]; then \
cp "$($CC -print-resource-dir)/lib/darwin/libclang_rt.asan_osx_dynamic.dylib" /output/bin/; \
fi && \
test -z "$(find /output/include -type l -print -quit)" || { echo "ERROR: dangling symlinks in /output/include"; find /output/include -type l | head; exit 1; }
FROM scratch AS artifact
COPY --from=build_webkit /output /