Porting/Chromium (New)

From RCS Wiki
Jump to navigation Jump to search

Chromium on POWER

The repository of all required patches for ppc64le is available here: https://github.com/shawnanastasio/chromium_power.

A source distribution of ungoogled-chromium with the patches incorporated is available here: https://github.com/leo-lb/ungoogled-chromium.

Additional patches required for ppc64 (Big Endian) are available here: Porting/Chromium/BE.

The old Chromium wiki page is available here: Porting/Chromium_(Old).

Introduction

Google's Chromium browser has been ported by the community to run on POWER systems. The base patch set targets CPUs running in Little Endian mode (ppc64le), but additional patches for Big Endian support exist as well.

There is an ongoing effort to get the patches upstreamed, but at the moment it is still required to apply some out-of-tree patches to get the browser to build. This page documents how to download and build Chromium for ppc64le.

Prerequisites

To build chromium, you'll need a ppc64le Linux environment with around 70GB of free disk space and at least 8GB of RAM. For parallel builds (recommended), the amount of RAM required will scale with the number of cores in your machine. Approximately 1GB per SMT thread seems to be reasonable.

Before beginning, you will need to install Chromium's dependencies from your distribution's package manager. For Ubuntu, the following should be sufficient:

# apt install git vim cmake python libcups2-dev pkg-config libnss3-dev libssl-dev libglib2.0-dev libgnome-keyring-dev libpango1.0-dev libdbus-1-dev libatk1.0-dev libatk-bridge2.0-dev libgtk-3-dev libkrb5-dev libpulse-dev libxss-dev re2c subversion curl libasound2-dev libpci-dev mesa-common-dev gperf bison nodejs uuid-dev clang-format ninja-build 

Next, you'll need some utilities that most likely aren't available in your distribution's repositories.

It is recommended to complete these steps in a new directory reserved for chromium and its dependencies, like ~/chromium_build. This directory will henceforth be referred to as $CHROMIUM_DIR.

GN

First is gn, the meta-build system:

$ cd $CHROMIUM_DIR
$ git clone https://gn.googlesource.com/gn
$ git checkout 81ee1967d3fcbc829bac1c005c3da59739c88df9 # Latest GN is broken with chromium...

$ export CC=gcc
$ export CXX=g++
$ export AR=ar

$ cd gn
$ python build/gen.py
$ ninja -C out

$ unset CXX
$ unset CC
$ unset AR 

depot_tools

Next is depot_tools, a collection of source code management tools used by Google.

$ cd $CHROMIUM_DIR
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 

In order to use the tools, they'll need to be in your path. It is recommended to place the following lines in a file named env.sh that you source, or in your .bashrc:

$ cd $CHROMIUM_DIR
$ echo 'export PATH="$PATH:${HOME}/ninja"' >> env.sh
$ echo 'export PATH="$PATH:${HOME}/depot_tools"' >> env.sh
$ echo 'export VPYTHON_BYPASS="manually managed python not supported by chrome operations"' >> env.sh
$ source env.sh 

LLVM/Clang

Chromium is only tested against specific revisions of the Clang compiler. As such, it is highly recommended to compile the specific version Chromium expects manually. The current version expected by Chromium may always be found here.

First, we must check out LLVM and Clang:

$ cd $CHROMIUM_DIR
$ export CLANG_SVN_REVISION=357692 # Check the above link for the current version
$ svn checkout --force https://llvm.org/svn/llvm-project/llvm/trunk@$CLANG_SVN_REVISION llvm
$ svn checkout --force https://llvm.org/svn/llvm-project/cfe/trunk@$CLANG_SVN_REVISION llvm/tools/clang
$ svn checkout --force https://llvm.org/svn/llvm-project/compiler-rt/trunk@$CLANG_SVN_REVISION llvm/compiler-rt 

Next, we'll create a build directory and build the compiler.

$ mkdir llvm_build && cd llvm_build
$ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="PowerPC" -G "Unix Makefiles" ../llvm
$ make -j64 # Replace with # of threads to compile with 

Downloading the source code

After completing the prerequisite steps, you can download the Chromium source code. Make sure that `depot_tools` is in your PATH by sourcing your env.sh and run the following:

$ cd $CHROMIUM_DIR
$ mkdir chromium && cd chromium
$ fetch --no-history --nohooks chromium 

To finish the source code checkout, we need to apply a single patch, disable NaCL, and replace the included GN binary with our own.

$ cd src
$ curl 'https://raw.githubusercontent.com/shawnanastasio/chromium_power/master/build_toolchain/Binutils-download.py-PPC.patch' | patch -p1
$ cp -f $CHROMIUM_DIR/gn/out/gn buildtools/linux64/gn
$ cd ..
$ sed -i 's/\"custom_vars\"\: {},/\"custom_vars\"\: { \"checkout_nacl\"\: False },/g' .gclient
$ gclient sync 

Patching Chromium

The patches required to build Chromium are maintained here. Included is a script which will apply all the patches to a Chromium source directory. To patch your local copy of the Chromium source, do the following:

$ cd $CHROMIUM_DIR
$ git clone https://github.com/shawnanastasio/chromium_power
$ cd chromium_power
$ python3 cpf.py $CHROMIUM_DIR/chromium/src 

This will attempt to apply all the patches. If an error is encountered, you can attempt to rebase the patch manually by following the prompts, or you can create a GitHub issue to notify the maintainers. Note that any errors about already applied patches can be safely ignored.

Pre-build

Now Chromium is almost ready to be built. First though, the ppc64le build files for ffmpeg and libvpx will need to be generated.

$ cd $CHROMIUM_DIR/chromium/src/third_party/ffmpeg
$ ./chromium/scripts/build_ffmpeg.py linux ppc64
$ ./chromium/scripts/generate_gn.py
$ ./chromium/scripts/copy_config.sh

$ cd ../libvpx
$ mkdir source/config/linux/ppc64
$ ./generate_gni.sh
$ cd ../../ 

Build

Now you're ready to build Chromium. First, the build parameters must be configured with gn. To do this, perform the following:

$ cd $CHROMIUM_DIR/chromium/src
$ gn args out/Default 

A text editor will open. Paste in the following configuration, modified to suit your needs if necessary:

# Release mode
is_component_build = false
is_debug = false

# Disable broken features
enable_nacl = false
treat_warnings_as_errors = false
enable_dav1d_decoder = false

# For clang, add the following lines:
is_clang = true
clang_base_path = "$CHROMIUM_DIR/llvm_build"
clang_use_chrome_plugins = false
use_lld = false 

Note that clang_base_path will have to be modified to contain the full path to your $CHROMIUM_DIR/llvm_build directory that was created earlier.

Close and save the text file and perform the following to build Chromium:

$ ninja -C out/Default chrome 

This will perform a parallel build of Chromium using all available threads. To limit the number of threads, append -jX where X is the number of threads you wish to use. If all goes well, you will have a compiled Chromium binary at $CHROMIUM_DIR/chromium/src/out/Default/chrome. If you encounter an error, please report an issue here.