Skip to content

Commit

Permalink
- completely rely on google's prebuilt rust/clang tools
Browse files Browse the repository at this point in the history
- cleanup of patches, build and docker files
  • Loading branch information
clickot committed Jan 28, 2024
1 parent 0504bf1 commit e815303
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 293 deletions.
65 changes: 31 additions & 34 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ build_dir="${root_dir}/build"
download_cache="${build_dir}/download_cache"
src_dir="${build_dir}/src"

# env vars
# ==================================================
export LLVM_VERSION=${LLVM_VERSION:=16}
export AR=${AR:=llvm-ar-${LLVM_VERSION}}
export NM=${NM:=llvm-nm-${LLVM_VERSION}}
export CC=${CC:=clang-${LLVM_VERSION}}
export CXX=${CXX:=clang++-${LLVM_VERSION}}
export LLVM_BIN=${LLVM_BIN:=/usr/lib/llvm-${LLVM_VERSION}/bin}

# clean
# ==================================================
echo "cleaning up directories"
Expand All @@ -37,46 +28,52 @@ mkdir -p "${src_dir}/out/Default" "${download_cache}"
"${main_repo}/utils/patches.py" apply "${src_dir}" "${main_repo}/patches"
"${main_repo}/utils/domain_substitution.py" apply -r "${main_repo}/domain_regex.list" -f "${main_repo}/domain_substitution.list" -c "${build_dir}/domsubcache.tar.gz" "${src_dir}"

## apply own patches needed for build
cd "${src_dir}"
# revert addition of check for a certain llvm package version (seems to be introduced in chromium 107.xx)
patch -Rp1 -i ${patches_dir}/REVERT-clang-version-check.patch
# hack to disable rust version check (introduced with chromium 115.xx)
patch -Np1 -i ${patches_dir}/rust-version-check.patch
# revert addition of compiler flag that needs newer clang (taken from ungoogled-chromium-archlinux)
patch -Rp1 -i ${patches_dir}/REVERT-disable-autoupgrading-debug-info.patch

## apply the patches from ungoogled-chromium-archlinux repo
# use the --oauth2-client-id= and --oauth2-client-secret= switches for setting GOOGLE_DEFAULT_CLIENT_ID
# and GOOGLE_DEFAULT_CLIENT_SECRET at runtime (taken from ungoogled-chromium-archlinux)
# and GOOGLE_DEFAULT_CLIENT_SECRET at runtime (taken from ungoogled-chromium-archlinux repo)
patch -Np1 -i ${patches_dir}/use-oauth2-client-switches-as-default.patch
# Disable kGlobalMediaControlsCastStartStop by default
# https://crbug.com/1314342
patch -Np1 -i ${patches_dir}/disable-GlobalMediaControlsCastStartStop.patch
# fix missing includes in av1_vaapi_video_encoder_delegate.cc
patch -Np1 -i ${patches_dir}/av1_vaapi_video_encoder_delegate.patch
# fix compile error concerning narrowing from/to int/long/unsigned in static initializer (new since latest clang-18 version)
patch -Np1 -i ${patches_dir}/add_casts_in_static_initializers.patch
# Fix build with ICU 74 (taken from ungoogled-chromium-archlinux repo)
patch -Np1 -i ${patches_dir}/icu-74.patch

# combine local and ungoogled-chromium gn flags
cat "${main_repo}/flags.gn" "${root_dir}/flags.gn" >"${src_dir}/out/Default/args.gn"

# adjust host name to download prebuilt tools below and sysroot files from
# (see e.g. https://github.com/ungoogled-software/ungoogled-chromium/issues/1846)
sed -i 's/commondatastorage.9oo91eapis.qjz9zk/commondatastorage.googleapis.com/g' ./build/linux/sysroot_scripts/sysroots.json
sed -i 's/commondatastorage.9oo91eapis.qjz9zk/commondatastorage.googleapis.com/g' ./tools/clang/scripts/update.py

## use prebuilt tools for rust and clang insetad of system libs
# use prebuilt rust
./tools/rust/update_rust.py
# to link to rust libraries we need to compile with prebuilt clang
./tools/clang/scripts/update.py
# install sysroot if according gn flag is present
if grep -q -F "use_sysroot=true" "${src_dir}/out/Default/args.gn"; then
./build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
fi

## Link to system tools required by the build
mkdir -p third_party/node/linux/node-linux-x64/bin && ln -s /usr/bin/node third_party/node/linux/node-linux-x64/bin

### build
# ==================================================
_clang_path="${src_dir}/third_party/llvm-build/Release+Asserts/bin"
## env vars
export CC=$_clang_path/clang
export CXX=$_clang_path/clang++
export AR=$_clang_path/llvm-ar
export NM=$_clang_path/llvm-nm
export LLVM_BIN=${_clang_path}
## flags
llvm_resource_dir=$("$CC" --print-resource-dir)
export CXXFLAGS+=" -resource-dir=${llvm_resource_dir} -B${LLVM_BIN}"
export CPPFLAGS+=" -resource-dir=${llvm_resource_dir} -B${LLVM_BIN}"
export CFLAGS+=" -resource-dir=${llvm_resource_dir} -B${LLVM_BIN}"
#
cat "${main_repo}/flags.gn" "${root_dir}/flags.gn" >"${src_dir}/out/Default/args.gn"

# install sysroot if according gn flag is present
if grep -q -F "use_sysroot=true" "${src_dir}/out/Default/args.gn"; then
# adjust host name to download sysroot files from (see e.g. https://github.com/ungoogled-software/ungoogled-chromium/issues/1846)
sed -i 's/commondatastorage.9oo91eapis.qjz9zk/commondatastorage.googleapis.com/g' ./build/linux/sysroot_scripts/sysroots.json
./build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
fi

## execute build
# execute build
./tools/gn/bootstrap/bootstrap.py -o out/Default/gn --skip-generate-buildfiles
./out/Default/gn gen out/Default --fail-on-unused-args

Expand Down
11 changes: 5 additions & 6 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
GIT_SUBMODULE="ungoogled-chromium"

RELEASE=${1:-'bullseye'}
LLVM_VERSION=${2:-'18'}
REPO_POSTFIX="-$LLVM_VERSION"
[ "$LLVM_VERSION" -lt "18" ] || REPO_POSTFIX=""
NODE_VERSION=${2:-'18'}
LLVM_VERSION=${3:-'18'}

IMAGE="chromium-builder-${RELEASE}:llvm-${LLVM_VERSION}"
IMAGE="chromium-builder:${RELEASE}"

echo "==============================================================="
echo " build docker image '${IMAGE}'"
echo "==============================================================="

(cd $BASE_DIR/docker && docker buildx build -t ${IMAGE} -f ./build.Dockerfile --build-arg RELEASE=${RELEASE} --build-arg LLVM_VERSION=${LLVM_VERSION} --build-arg REPO_POSTFIX=${REPO_POSTFIX} .)
(cd $BASE_DIR/docker && docker buildx build -t ${IMAGE} -f ./build.Dockerfile --build-arg RELEASE=${RELEASE} --build-arg NODE_VERSION=${NODE_VERSION} .)

[ -n "$(ls -A ${BASE_DIR}/${GIT_SUBMODULE})" ] || git submodule update --init --recursive

Expand All @@ -23,7 +22,7 @@ echo "==============================================================="
echo " docker build start at ${BUILD_START}"
echo "==============================================================="

cd ${BASE_DIR} && docker run -it -v ${BASE_DIR}:/repo ${IMAGE} /bin/bash -c "/repo/build.sh"
cd ${BASE_DIR} && docker run -it -v ${BASE_DIR}:/repo ${IMAGE} /bin/bash -c "LLVM_VERSION=${LLVM_VERSION} /repo/build.sh"

BUILD_END=$(date)
echo "==============================================================="
Expand Down
48 changes: 6 additions & 42 deletions docker/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,22 @@ ARG RELEASE="bullseye"
FROM debian:${RELEASE}

ARG RELEASE
ARG LLVM_VERSION="17"
ARG NODE_VERSION="18"
ARG REPO_POSTFIX="-${LLVM_VERSION}"

# set llvm version as env var to make it available for containers building chromium
ENV LLVM_VERSION ${LLVM_VERSION}

# set deb to non-interactive mode and upgrade packages
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && export DEBIAN_FRONTEND=noninteractive
RUN apt -y update && apt -y upgrade
RUN apt-get -y update && apt-get -y upgrade

# install the needed base packages to add repos
RUN apt -y install lsb-release wget software-properties-common gnupg
# add node repo (needed for bullseye)
RUN apt-get -y install lsb-release wget software-properties-common gnupg

# add node repo (needed for bullseye to install nodejs > 12)
RUN wget -qO - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | tee /etc/apt/trusted.gpg.d/deb.nodesource.com.asc \
&& add-apt-repository "deb https://deb.nodesource.com/node_${NODE_VERSION}.x ${RELEASE} main"
# add lvm repo
RUN wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
&& add-apt-repository "deb http://apt.llvm.org/${RELEASE} llvm-toolchain-${RELEASE}${REPO_POSTFIX} main"
RUN apt -y update
RUN apt-get -y update && apt-get -y install nodejs && npm update -g npm

# install node and llvm toolchain
#RUN apt -y install nodejs npm clang-${LLVM_VERSION} lldb-${LLVM_VERSION} lld-${LLVM_VERSION} clangd-${LLVM_VERSION}
RUN apt -y install nodejs clang-${LLVM_VERSION} lldb-${LLVM_VERSION} lld-${LLVM_VERSION} clangd-${LLVM_VERSION}
# install all remaining needed distro packages
RUN apt -y install bison debhelper desktop-file-utils flex gperf gsettings-desktop-schemas-dev imagemagick libasound2-dev libavcodec-dev libavformat-dev libavutil-dev libcap-dev libcups2-dev libcurl4-openssl-dev libdrm-dev libegl1-mesa-dev libelf-dev libevent-dev libexif-dev libflac-dev libgbm-dev libgcrypt20-dev libgl1-mesa-dev libgles2-mesa-dev libglew-dev libglib2.0-dev libglu1-mesa-dev libgtk-3-dev libhunspell-dev libjpeg-dev libjs-jquery-flot libjsoncpp-dev libkrb5-dev liblcms2-dev libminizip-dev libmodpbase64-dev libnspr4-dev libnss3-dev libopenjp2-7-dev libopus-dev libpam0g-dev libpci-dev libpipewire-0.3-dev libpng-dev libpulse-dev libre2-dev libsnappy-dev libspeechd-dev libudev-dev libusb-1.0-0-dev libva-dev libvpx-dev libwebp-dev libx11-xcb-dev libxcb-dri3-dev libxshmfence-dev libxslt1-dev libxss-dev libxt-dev libxtst-dev mesa-common-dev ninja-build pkg-config python3-jinja2 python3-setuptools python3-xcbgen python-is-python3 qtbase5-dev uuid-dev valgrind wdiff x11-apps xcb-proto xfonts-base xvfb xz-utils yasm
# update npm
RUN npm update -g npm

# setup alternatives
RUN <<EOF
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} 800
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 800
update-alternatives --install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${LLVM_VERSION} 800
update-alternatives --install /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-${LLVM_VERSION} 800
EOF
# force correct linker versions 'by hand'
RUN <<EOF
rm -f /usr/bin/lld && ln -s /usr/bin/lld-${LLVM_VERSION} /usr/bin/lld
rm -f /usr/bin/ld.lld && ln -s /usr/bin/ld.lld-${LLVM_VERSION} /usr/bin/ld.lld
rm -f /usr/bin/lld-link && ln -s /usr/bin/lld-link-${LLVM_VERSION} /usr/bin/lld-link
EOF
# ensure additional 'share' links for llvm resource dir
RUN <<EOF
_llvm_package_version_="$(apt list llvm-${LLVM_VERSION}-dev | grep -Po "\d+\.\d+\.\d+")" || _llvm_package_version_="${LLVM_VERSION}.0.0"
if [ ! -e /usr/lib/clang/${_llvm_package_version_}/share ] ; then
(cd /usr/lib/clang/${_llvm_package_version_} && ln -s ../../llvm-${LLVM_VERSION}/lib/clang/${_llvm_package_version}/share)
fi
if [ ! -e /usr/lib/clang/${LLVM_VERSION}/share ] ; then
(cd /usr/lib/clang/${LLVM_VERSION} && ln -s ../../llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}/share)
fi
EOF
RUN apt-get -y install bison debhelper desktop-file-utils flex gperf gsettings-desktop-schemas-dev imagemagick libasound2-dev libavcodec-dev libavformat-dev libavutil-dev libcap-dev libcups2-dev libcurl4-openssl-dev libdrm-dev libegl1-mesa-dev libelf-dev libevent-dev libexif-dev libflac-dev libgbm-dev libgcrypt20-dev libgl1-mesa-dev libgles2-mesa-dev libglew-dev libglib2.0-dev libglu1-mesa-dev libgtk-3-dev libhunspell-dev libjpeg-dev libjs-jquery-flot libjsoncpp-dev libkrb5-dev liblcms2-dev libminizip-dev libmodpbase64-dev libnspr4-dev libnss3-dev libopenjp2-7-dev libopus-dev libpam0g-dev libpci-dev libpipewire-0.3-dev libpng-dev libpulse-dev libre2-dev libsnappy-dev libspeechd-dev libudev-dev libusb-1.0-0-dev libva-dev libvpx-dev libwebp-dev libx11-xcb-dev libxcb-dri3-dev libxshmfence-dev libxslt1-dev libxss-dev libxt-dev libxtst-dev mesa-common-dev ninja-build pkg-config python3-jinja2 python3-setuptools python3-xcbgen python-is-python3 qtbase5-dev uuid-dev valgrind wdiff x11-apps xcb-proto xfonts-base xvfb xz-utils yasm

# create and set workdir to mount in docker build
RUN mkdir /repo
Expand Down
4 changes: 2 additions & 2 deletions flags.gn
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
custom_toolchain="//build/toolchain/linux/unbundle:default"
host_toolchain="//build/toolchain/linux/unbundle:default"
clang_base_path="/usr"
is_official_build=true
symbol_level=0
disable_fieldtrial_testing_config=true
Expand All @@ -12,12 +11,13 @@ fatal_linker_warnings=false
rtc_use_pipewire=true
is_clang=true
is_debug=false
enable_rust=false
use_kerberos=false
use_sysroot=true
use_vaapi=true
use_system_libffi=false

#clang_base_path="/usr"
#enable_rust=false
#enable_hevc_parser_and_hw_decoder=true
#enable_iterator_debugging=false
#enable_platform_hevc=true
Expand Down
16 changes: 0 additions & 16 deletions patches/REVERT-clang-version-check.patch

This file was deleted.

48 changes: 0 additions & 48 deletions patches/REVERT-disable-autoupgrading-debug-info.patch

This file was deleted.

Loading

0 comments on commit e815303

Please sign in to comment.