Skip to content

Commit

Permalink
Force LLVM 18 + Download glibc headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 1, 2024
1 parent 173edef commit 8bbd4ed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
54 changes: 36 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ 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="16"
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 "
ARG DEBIAN_VERSION="bullseye"
ARG DEBIAN_VERSION="bookworm"
ARG GLIBC_VERSION="2.27"

FROM bitnami/minideb:${DEBIAN_VERSION} as base

Expand All @@ -14,6 +15,8 @@ ARG CPU
ARG LTO_FLAG
ARG LLVM_VERSION
ARG DEFAULT_CFLAGS
ARG DEBIAN_VERSION
ARG GLIBC_VERSION

RUN install_packages ca-certificates curl wget lsb-release software-properties-common gnupg gnupg1 gnupg2

Expand Down Expand Up @@ -45,7 +48,30 @@ RUN install_packages \
pkg-config \
ruby-dev \
llvm-${LLVM_VERSION}-runtime \
llvm-${LLVM_VERSION}-dev
llvm-${LLVM_VERSION}-dev \
cmake \
gawk \
bison \
binutils \
gcc \
build-essential


ENV WEBKIT_OUT_DIR=/webkitbuild
RUN mkdir -p /output/lib /output/include /output/include/JavaScriptCore /output/include/glibc /output/include/wtf /output/include/bmalloc /output/include/unicode

ADD https://ftp.gnu.org/gnu/glibc/glibc-${GLIBC_VERSION}.tar.gz /glibc.tar.gz
RUN --mount=type=tmpfs,target=/glibc \
export CC=gcc && \
export CXX=g++ && \
cd /glibc && \
tar -xf /glibc.tar.gz --strip-components=1 && \
rm /glibc.tar.gz && \
mkdir -p build && cd build && \
../configure --prefix=/usr \
--with-headers=/usr/include \
--enable-kernel=3.2 && \
make install-headers prefix=/output/include/glibc

RUN for f in /usr/lib/llvm-${LLVM_VERSION}/bin/*; do ln -sf "$f" /usr/bin; done \
&& ln -sf /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang \
Expand All @@ -70,15 +96,16 @@ ENV RANLIB llvm-ranlib-${LLVM_VERSION}
ENV LD lld-${LLVM_VERSION}
ENV LTO_FLAG="${LTO_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 CFLAGS="${DEFAULT_CFLAGS} $CFLAGS -isystem /output/include/glibc -D__GLIBC__=2 -D__GLIBC_MINOR__=27 -D_GNU_SOURCE"
ENV CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS -isystem /output/include/glibc -D__GLIBC__=2 -D__GLIBC_MINOR__=27 -D_GNU_SOURCE"

# Debian repos may not have the latest ICU version, so we ensure build reliability by downloading
# the exact version we need. Unfortunately, aarch64 is not pre-built so we have to build it from source.
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 -Os -std=c17 $LTO_FLAG" && \
export CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS -Os -DUCONFIG_NO_LEGACY_CONVERSION=1 -std=c++20 -fno-exceptions $LTO_FLAG -fno-c++-static-destructors " && \
export CFLAGS="$CFLAGS -Os -std=c17 $LTO_FLAG" && \
export CXXFLAGS="$CXXFLAGS -Os -DUCONFIG_NO_LEGACY_CONVERSION=1 -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 && \
Expand All @@ -88,15 +115,6 @@ RUN --mount=type=tmpfs,target=/icu \
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

# WebKit has a minimum cmake version of 3.20
ADD https://github.com/Kitware/CMake/releases/download/v3.29.6/cmake-3.29.6.tar.gz /cmake.tar.gz
RUN --mount=type=tmpfs,target=/cmakebuild install_packages libssl-dev && tar -xf /cmake.tar.gz -C /cmakebuild && \
cd /cmakebuild/cmake-3.29.6 && \
./configure && \
make -j$(nproc) && \
make install && \
rm -rf /cmakebuild/cmake-3.29.6 /cmake.tar.gz


COPY . /webkit
WORKDIR /webkit
Expand All @@ -106,8 +124,8 @@ ENV MARCH_FLAG=${MARCH_FLAG}


RUN --mount=type=tmpfs,target=/webkitbuild \
export CFLAGS="${DEFAULT_CFLAGS} $CFLAGS $LTO_FLAG -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \
export CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS $LTO_FLAG -fno-c++-static-destructors -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \
export CFLAGS="$CFLAGS $LTO_FLAG -ffile-prefix-map=/webkit/Source=vendor/WebKit/Source -ffile-prefix-map=/webkitbuild/=. " && \
export CXXFLAGS="$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 \
Expand Down
16 changes: 8 additions & 8 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ if [ "$WEBKIT_RELEASE_TYPE" == "relwithdebuginfo" ]; then
CONTAINER_NAME=bun-webkit-linux-$BUILDKIT_ARCH-dbg
fi

# If LTO is not enabled, we still need to be able to do a local release build.
# We use bullseye for CI to support older versions of glibc, but that requires libc++.
if [[ "$WEBKIT_RELEASE_TYPE" == "Debug" || "$LTO_FLAG" == "" ]]; then
export DEBIAN_VERSION="bookworm"
else
export DEBIAN_VERSION="bullseye"
fi
export DEBIAN_VERSION="bookworm"

export temp=${temp:-"$(mktemp -d -t bun-webkit-linux-$BUILDKIT_ARCH-release-$(date +%s)-XXXX)"}

mkdir -p $temp
rm -rf $temp/bun-webkit

docker buildx build -f Dockerfile -t $CONTAINER_NAME --build-arg LTO_FLAG="$LTO_FLAG" --build-arg WEBKIT_RELEASE_TYPE=$WEBKIT_RELEASE_TYPE --build-arg DEBIAN_VERSION=$DEBIAN_VERSION --progress=plain --platform=linux/$BUILDKIT_ARCH --target=artifact --output type=local,dest=$temp/bun-webkit .
echo "Building $CONTAINER_NAME to $temp/bun-webkit"

docker buildx build -f Dockerfile -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 .

echo "Successfully built $CONTAINER_NAME to $temp/bun-webkit"

0 comments on commit 8bbd4ed

Please sign in to comment.