forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from oven-sh/musl
add musl build [v2]
- Loading branch information
Showing
3 changed files
with
261 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,122 @@ | ||
FROM alpine:3.15 as base | ||
ARG MARCH_FLAG="" | ||
ARG WEBKIT_RELEASE_TYPE=Release | ||
ARG CPU=native | ||
ARG LTO_FLAG="-flto=full -fwhole-program-vtables -fforce-emit-vtables " | ||
ARG LLVM_VERSION="18" | ||
ARG DEFAULT_CFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -ffunction-sections -fdata-sections -faddrsig -fno-unwind-tables -fno-asynchronous-unwind-tables -DU_STATIC_IMPLEMENTATION=1 " | ||
|
||
FROM alpine:edge 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 clang clang-static clang-dev llvm12-dev llvm12-static musl-dev git lld libgcc gcc g++ libstdc++ build-base lld-dev lld-static llvm12-libs libc-dev xz zlib zlib-dev libxml2 libxml2-dev | ||
RUN apk add --no-cache cmake make clang18 clang18-static clang18-dev llvm18-dev llvm18-static musl-dev git lld18 libgcc gcc g++ libstdc++ build-base lld18-dev llvm18-libs libc-dev xz zlib zlib-dev libxml2 libxml2-dev | ||
|
||
ENV CXX=clang++-18 | ||
ENV CC=clang-18 | ||
ENV LDFLAGS='-L/usr/include -L/usr/include/llvm18' | ||
ENV CXXFLAGS="-I/usr/include -I/usr/include/llvm18" | ||
ENV PATH="/usr/bin:/usr/local/bin:/zig/bin:/usr/lib/llvm18/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}" | ||
|
||
ENV CXX=clang++ | ||
ENV CC=clang | ||
ENV LDFLAGS='-L/usr/include -L/usr/include/llvm12' | ||
ENV CXXFLAGS="-I/usr/include -I/usr/include/llvm12" | ||
ENV PATH="/usr/bin:/usr/local/bin:/zig/bin:$PATH" | ||
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 icu-dev tar | ||
|
||
ADD https://github.com/unicode-org/icu/releases/download/release-75-1/icu4c-75_1-src.tgz /icu.tgz | ||
RUN --mount=type=tmpfs,target=/icu \ | ||
export CFLAGS="${DEFAULT_CFLAGS} $CFLAGS -O3 -std=c17 $LTO_FLAG" && \ | ||
export CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS -O3 -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 && \ | ||
cd source && \ | ||
./configure --enable-static --disable-shared --with-data-packaging=static --disable-samples --disable-debug --disable-tests && \ | ||
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 | ||
|
||
FROM base as build_webkit | ||
|
||
RUN apk add --no-cache cpio curl file gnupg icu-dev ninja ruby unzip rsync perl python2 openssl-dev openssl linux-headers | ||
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 file gnupg icu-dev ninja ruby unzip rsync perl python3 openssl-dev openssl linux-headers | ||
|
||
ENV WEBKIT_OUT_DIR=/webkit | ||
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 | ||
|
||
WORKDIR /webkit-build | ||
|
||
COPY . /webkit-src | ||
COPY --from=build_icu /output /icu | ||
|
||
RUN --mount=type=tmpfs,target=/webkit-build; \ | ||
RUN --mount=type=tmpfs,target=/webkitbuild \ | ||
export CFLAGS="${DEFAULT_CFLAGS} $CFLAGS $LTO_FLAG -ffile-prefix-map=/webkit/Source=src/bun.js/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \ | ||
export CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS $LTO_FLAG -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=src/bun.js/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \ | ||
export LDFLAGS="-fuse-ld=lld $LDFLAGS " && \ | ||
cd /webkitbuild && \ | ||
cmake \ | ||
-DPORT="JSCOnly" \ | ||
-DENABLE_STATIC_JSC=ON \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON \ | ||
-DCMAKE_BUILD_TYPE=${WEBKIT_RELEASE_TYPE} \ | ||
-DUSE_THIN_ARCHIVES=OFF \ | ||
-DUSE_BUN_JSC_ADDITIONS=ON \ | ||
-DENABLE_FTL_JIT=ON \ | ||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ | ||
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \ | ||
-DENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE=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 \ | ||
-DCMAKE_CXX_COMPILER=clang++ \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
/webkit-src && \ | ||
cd /webkit-build && \ | ||
cmake --build /webkit-build --config release -- "jsc" && \ | ||
mkdir -p ${WEBKIT_OUT_DIR}/lib ${WEBKIT_OUT_DIR}/include/JavaScriptCore && \ | ||
cp -r /webkit-build/lib/*.a $WEBKIT_OUT_DIR/lib && \ | ||
cp /webkit-build/*.h $WEBKIT_OUT_DIR/include && \ | ||
find /webkit-build/JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} $WEBKIT_OUT_DIR/include/JavaScriptCore/ \; && \ | ||
find /webkit-build/JavaScriptCore/PrivateHeaders/JavaScriptCore/ -name "*.h" -exec cp {} $WEBKIT_OUT_DIR/include/JavaScriptCore/ \; && \ | ||
cp -r /webkit-build/WTF/Headers/wtf/ $WEBKIT_OUT_DIR/include && \ | ||
cp -r /webkit-build/bmalloc/Headers/bmalloc/ $WEBKIT_OUT_DIR/include && echo "Done"; | ||
|
||
|
||
FROM base as build_icu | ||
|
||
RUN apk add --no-cache cpio curl icu-dev tar | ||
|
||
|
||
WORKDIR /icu-src | ||
RUN --mount=type=tmpfs,target=/icu-src; curl -L https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.tgz > icu4c-66_1-src.tgz && \ | ||
tar -xzf icu4c-66_1-src.tgz && \ | ||
rm icu4c-66_1-src.tgz && \ | ||
cd icu/source && \ | ||
./configure --enable-static --disable-shared && \ | ||
make -j$(nproc) && \ | ||
mkdir -p /icu && \ | ||
cp -r lib/*.a /icu | ||
|
||
|
||
FROM alpine:3.15 as webkit | ||
|
||
COPY --from=build_webkit /webkit /webkit | ||
COPY --from=build_icu /icu/*.a /webkit/lib | ||
/webkit && \ | ||
cd /webkitbuild && \ | ||
cmake --build /webkitbuild --config ${WEBKIT_RELEASE_TYPE} --target "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/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_webkit /output / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
set -euxo pipefail | ||
|
||
export DOCKER_BUILDKIT=1 | ||
|
||
export BUILDKIT_ARCH=$(uname -m) | ||
export ARCH=${BUILDKIT_ARCH} | ||
export LTO_FLAG="${LTO_FLAG:-""}" | ||
if [ "$BUILDKIT_ARCH" == "amd64" ]; then | ||
export BUILDKIT_ARCH="amd64" | ||
export ARCH=x64 | ||
fi | ||
|
||
if [ "$BUILDKIT_ARCH" == "x86_64" ]; then | ||
export BUILDKIT_ARCH="amd64" | ||
export ARCH=x64 | ||
fi | ||
|
||
if [ "$BUILDKIT_ARCH" == "arm64" ]; then | ||
export BUILDKIT_ARCH="arm64" | ||
export ARCH=aarch64 | ||
fi | ||
|
||
if [ "$BUILDKIT_ARCH" == "aarch64" ]; then | ||
export BUILDKIT_ARCH="arm64" | ||
export ARCH=aarch64 | ||
fi | ||
|
||
if [ "$BUILDKIT_ARCH" == "armv7l" ]; then | ||
echo "Unsupported platform: $BUILDKIT_ARCH" | ||
exit 1 | ||
fi | ||
|
||
export WEBKIT_RELEASE_TYPE=${WEBKIT_RELEASE_TYPE:-"Release"} | ||
|
||
export CONTAINER_NAME=bun-webkit-linux-$BUILDKIT_ARCH | ||
|
||
if [ "$WEBKIT_RELEASE_TYPE" == "relwithdebuginfo" ]; then | ||
CONTAINER_NAME=bun-webkit-linux-$BUILDKIT_ARCH-dbg | ||
fi | ||
|
||
mkdir -p $temp | ||
rm -rf $temp/bun-webkit | ||
|
||
docker buildx build -f Dockerfile.musl -t $CONTAINER_NAME --build-arg LTO_FLAG="$LTO_FLAG" --build-arg WEBKIT_RELEASE_TYPE=$WEBKIT_RELEASE_TYPE --progress=plain --platform=linux/$BUILDKIT_ARCH --target=artifact --output type=local,dest=$temp/bun-webkit . |