Skip to content

Commit

Permalink
Use ubuntu 18.04
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 7, 2024
1 parent 2776bf2 commit 180013b
Showing 1 changed file with 100 additions and 78 deletions.
178 changes: 100 additions & 78 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,93 @@ ARG LTO_FLAG="-flto=full -fwhole-program-vtables -fforce-emit-vtables "
ARG RELEASE_FLAGS="-O2 -DNDEBUG=1"
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="bookworm"
ARG GLIBC_VERSION="2.27"

FROM bitnami/minideb:${DEBIAN_VERSION} as base
FROM ubuntu:18.04

ARG MARCH_FLAG
ARG WEBKIT_RELEASE_TYPE
ARG CPU
ARG LTO_FLAG
ARG RELEASE_FLAGS
ARG LLVM_VERSION
ARG DEFAULT_CFLAGS
ARG RELEASE_FLAGS
ARG DEBIAN_VERSION
ARG GLIBC_VERSION

RUN install_packages ca-certificates curl wget lsb-release software-properties-common gnupg gnupg1 gnupg2
# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

RUN wget https://apt.llvm.org/llvm.sh && \
chmod +x llvm.sh && \
./llvm.sh ${LLVM_VERSION}

RUN install_packages \
# Install basic build dependencies
RUN apt-get update && apt-get install -y \
wget \
curl \
file \
git \
python3 \
python3-pip \
ninja-build \
software-properties-common \
apt-transport-https \
ca-certificates \
gnupg \
libc-dev \
libxml2 \
lsb-release \
&& rm -rf /var/lib/apt/lists/*

# Install modern CMake
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null \
&& apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' \
&& apt-get update \
&& apt-get install -y cmake \
&& rm -rf /var/lib/apt/lists/*

# Install GCC 13 toolchain
RUN add-apt-repository ppa:ubuntu-toolchain-r/test \
&& apt-get update \
&& apt-get install -y \
gcc-13 \
g++-13 \
libgcc-13-dev \
libstdc++-13-dev \
libasan6 \
libubsan1 \
libatomic1 \
libtsan0 \
liblsan0 \
libquadmath0 \
libgfortran5 \
lib32gcc-13-dev \
libc6-dev \
&& rm -rf /var/lib/apt/lists/*

# Ensure GCC 13 is the default
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 130 \
--slave /usr/bin/g++ g++ /usr/bin/g++-13 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-13 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-13 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-13

# Configure library paths
RUN mkdir -p /usr/lib/gcc/x86_64-linux-gnu/13 && \
ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/gcc/x86_64-linux-gnu/13/ && \
echo "/usr/lib/gcc/x86_64-linux-gnu/13" > /etc/ld.so.conf.d/gcc-13.conf && \
echo "/usr/lib/x86_64-linux-gnu" >> /etc/ld.so.conf.d/gcc-13.conf && \
ldconfig

# Install LLVM 18
RUN wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 18 all \
&& rm llvm.sh \
&& rm -rf /var/lib/apt/lists/*

# Install additional WebKit build dependencies
RUN apt-get update && apt-get install -y \
libxml2-dev \
make \
ninja-build \
perl \
python3 \
rsync \
ruby \
unzip \
bash tar gzip \
clang-${LLVM_VERSION} \
lld-${LLVM_VERSION} \
libc++-${LLVM_VERSION}-dev \
libc++abi-${LLVM_VERSION}-dev \
lldb-${LLVM_VERSION} \
pkg-config \
ruby-dev \
llvm-${LLVM_VERSION}-runtime \
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
gawk \
perl \
make \
&& rm -rf /var/lib/apt/lists/*

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 \
# Set up LLVM toolchain symlinks
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 \
&& ln -sf /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ \
&& ln -sf /usr/bin/lld-${LLVM_VERSION} /usr/bin/lld \
Expand All @@ -84,40 +100,48 @@ RUN for f in /usr/lib/llvm-${LLVM_VERSION}/bin/*; do ln -sf "$f" /usr/bin; done
&& ln -sf /usr/bin/llvm-ar-${LLVM_VERSION} /usr/bin/llvm-ar \
&& ln -sf /usr/bin/ld.lld /usr/bin/ld \
&& ln -sf /usr/bin/clang /usr/bin/cc \
&& ln -sf /usr/bin/clang /usr/bin/c89 \
&& ln -sf /usr/bin/clang /usr/bin/c99 \
&& ln -sf /usr/bin/clang++ /usr/bin/c++ \
&& ln -sf /usr/bin/clang++ /usr/bin/g++ \
&& ln -sf /usr/bin/llvm-ar /usr/bin/ar \
&& ln -sf /usr/bin/clang /usr/bin/gcc

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}
ENV LTO_FLAG="${LTO_FLAG}"
&& ln -sf /usr/bin/clang++ /usr/bin/c++

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

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.
# Set environment variables for toolchain
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}"
ENV LTO_FLAG="${LTO_FLAG}"
ENV LD_LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu/13:/usr/lib/x86_64-linux-gnu"
ENV LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu/13:/usr/lib/x86_64-linux-gnu"
ENV CPLUS_INCLUDE_PATH="/usr/include/c++/13:/usr/include/x86_64-linux-gnu/c++/13"
ENV C_INCLUDE_PATH="/usr/lib/gcc/x86_64-linux-gnu/13/include"

ENV CFLAGS="${DEFAULT_CFLAGS} $CFLAGS -stdlib=libstdc++"
ENV CXXFLAGS="${DEFAULT_CFLAGS} $CXXFLAGS -stdlib=libstdc++"
ENV LDFLAGS="-fuse-ld=lld -L/usr/lib/gcc/x86_64-linux-gnu/13 -L/usr/lib/x86_64-linux-gnu"

# Verify toolchain setup
RUN echo "#include <iostream>\n#include <numbers>\nint main() { std::cout << std::numbers::pi << std::endl; return 0; }" > test.cpp && \
${CXX} -std=c++20 test.cpp -o test && \
./test && \
rm test.cpp test

# Download and build ICU
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 \
RUN --mount=type=tmpfs,target=/icu \
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 && \
rm /icu.tgz && \
cd source && \
./configure --enable-static --disable-shared --disable-layoutex --disable-layout --with-data-packaging=static --disable-samples --disable-debug --disable-tests --disable-extras --disable-icuio && \
./configure --enable-static --disable-shared --disable-layoutex --disable-layout --with-data-packaging=static --disable-samples --disable-debug --disable-tests --disable-extras --disable-icuio && \
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


# Copy WebKit source and build
COPY . /webkit
WORKDIR /webkit

Expand Down Expand Up @@ -165,9 +189,7 @@ RUN --mount=type=tmpfs,target=/webkitbuild \
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 "";
cp /webkit/Source/JavaScriptCore/create_hash_table /output/Source/JavaScriptCore

FROM scratch as artifact

COPY --from=base /output /
COPY --from=0 /output /

0 comments on commit 180013b

Please sign in to comment.