Projects: Compile Brave Browser in Ubuntu 19.04

Since I switched from Linux Mint 19.1 to Ubuntu 19.04 on my Dell XPS laptop a while ago, I’ve just been using Brave browser installed from packages. Today I decided to refresh the compiling Brave browser project and get fresh Brave version compiled in Ubuntu.

In mid-July 2019, the Brave browser version I compiled was 0.69.72.

Before We Start

Building a massive project like Brave browser from source is a lot of fun, but comes with a caveat: you need to install all sorts of libraries and build tools required to complete the build process.

Normally you wouldn’t need these installed on your laptop or desktop, so best approach is to build Brave on a virtual machine or dedicated build server.

Prepare Ubuntu 19.04 For Compiling Code

Just like the last time, I’m installing basic packages like this:

greys@xps:~$ sudo apt-get install build-essential libgnome-keyring-dev python-setuptools npm

Install Dependencies Required for Brave Browser

There’s lots of additional libraries that Brave browser might need as part of build process.

Turns out, an excellent script for installing dependencies comes with Brave source code, and it’s Ubuntu friendly so we’re in luck. Just run it with sudo privileges and it will install quite a bunch of packages that are needed and used by the browser:

greys@xps:/storage/proj/brave-browser $ sudo ./src/build/install-build-deps.sh
...
Finding missing packages...
Packages required: libasound2:i386 libcap2:i386 libelf-dev:i386 libfontconfig1:i386 libglib2.0-0:i386 libgpm2:i386 libn
curses5:i386 libnss3:i386 libpango1.0-0:i386 libpci3:i386 libssl1.1:i386 libssl-dev:i386 libtinfo-dev:i386 libudev1:i386
libuuid1:i386 libx11-xcb1:i386 libxcomposite1:i386 libxcursor1:i386 libxdamage1:i386 libxi6:i386 libxrandr2:i386 libxss
1:i386 libxtst6:i386 linux-libc-dev:i386 ant apache2-bin autoconf binutils binutils-aarch64-linux-gnu binutils-arm-linux
-gnueabihf binutils-mips64el-linux-gnuabi64 binutils-mipsel-linux-gnu bison bzip2 cdbs cmake curl dbus-x11 devscripts dp
kg-dev elfutils fakeroot flex g++ g++-8-multilib g++-9-multilib-arm-linux-gnueabihf g++-arm-linux-gnueabihf gawk gcc-9-m
ultilib-arm-linux-gnueabihf gcc-arm-linux-gnueabihf git-core git-svn g++-mingw-w64-i686 gperf intltool lib32gcc1 lib32nc
urses5-dev lib32stdc++6 lib32z1-dev libapache2-mod-php7.2 libappindicator3-1 libappindicator3-dev libasound2 libasound2-
dev libatk1.0-0 libatspi2.0-0 libatspi2.0-dev libbluetooth-dev libbrlapi0.6 libbrlapi-dev libbz2-1.0 libbz2-dev libc6 li
bc6-dev libc6-dev-armhf-cross libc6-i386 libcairo2 libcairo2-dev libcap2 libcap-dev libcups2 libcups2-dev libcurl4-gnutl
s-dev libdrm-dev libelf-dev libexpat1 libffi6 libffi-dev libfontconfig1 libfreetype6 libgbm-dev libglib2.0-0 libglib2.0-
dev libglu1-mesa-dev libgnome-keyring0 libgnome-keyring-dev libgtk-3-0 libgtk-3-dev libjpeg-dev libkrb5-dev libnspr4 lib
nspr4-dev libnss3 libnss3-dev libpam0g libpam0g-dev libpango1.0-0 libpci3 libpci-dev libpcre3 libpixman-1-0 libpng16-16
libpulse0 libpulse-dev libsctp-dev libspeechd2 libspeechd-dev libsqlite3-0 libsqlite3-dev libssl-dev libstdc++6 libtinfo
-dev libtool libudev1 libudev-dev libuuid1 libwayland-egl1-mesa libwww-perl libx11-6 libx11-xcb1 libxau6 libxcb1 libxcom
posite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxinerama1 libxkbcommon-dev libxrandr2 libxrender
1 libxslt1-dev libxss-dev libxt-dev libxtst6 libxtst-dev linux-libc-dev-armhf-cross locales openbox p7zip patch perl php
7.2-cgi pkg-config python python-cherrypy3 python-crypto python-dev python-numpy python-opencv python-openssl python-psu
til python-yaml rpm ruby subversion texinfo uuid-dev wdiff x11-utils xcompmgr xsltproc xutils-dev xvfb xz-utils zip zlib
...

I believe quite a bit of this is installed due to cross-platform compatibility – so the script brings your system to a level capable of compiling Brave browser not only on your Ubuntu OS and platform but also for other hardware systems like 32-bit (i386 ones) and ARM based systems.

I also ended up installing Java (JDK) because it was needed by one of the npm build stages:

greys@xps:~$ sudo apt-get install openjdk-12-jdk-headless

Prepare Lots of Disk Space

In Linux Mint I had the directory of about 67GB, but in my Ubuntu 19.04 experiments this time my Brave browser source code directory went up to as much as 85GB (the size goes down towards the later stage of build process).

Download Brave browser and Chromium code from GitHub

First, we create new directory and go into it, /storage/proj in my case:

greys@xps:~$ mkdir -p /storage/proj
greys@xps:~$ cd /storage/proj

… now we download Brave code from GitHub. As you can see, and this stage it’s a modest codebase:

greys@xps:/storage/proj $ git clone git@github.com:brave/brave-browser.git
Cloning into 'brave-browser'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (48/48), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 11554 (delta 25), reused 29 (delta 13), pack-reused 11506
Receiving objects: 100% (11554/11554), 2.26 MiB | 4.73 MiB/s, done.
Resolving deltas: 100% (7852/7852), done.
greys@xps:/storage/proj $ ls
brave-browser
greys@xps:/storage/proj $ du -sh brave-browser/
3.5M brave-browser/

It’s time to install npm dependencies:

greys@xps:/storage/proj/brave-browser $ npm install                                                                     
npm WARN npm npm does not support Node.js v10.15.2                                                                      
npm WARN npm You should probably upgrade to a newer version of node as we                                              
npm WARN npm can't make any promises that npm will work with this version.                                             
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.                                    
npm WARN npm You can find the latest version at https://nodejs.org/                                                    
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):                                
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"an$"} (current: {"os":"linux","arch":"x64"})

added 499 packages from 347 contributors in 4.119s

And, finally, the biggest download in the procedure – download Chromium codebase:

greys@xps:/storage/proj/brave-browser $ npm run init                                                                                                                                                
npm WARN npm npm does not support Node.js v10.15.2                                                                                                                                                  
npm WARN npm You should probably upgrade to a newer version of node as we                                                                                                                           
npm WARN npm can't make any promises that npm will work with this version.                                                                                                                          
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.                                                                                                                 
npm WARN npm You can find the latest version at https://nodejs.org/

> brave@0.69.72 init /storage/proj/brave-browser
> node ./scripts/sync.js --init

Brave Browser Sync starting
Updating submodules...
/storage/proj/brave-browser: git submodule sync
/storage/proj/brave-browser: git submodule update --init --recursive
Submodule 'vendor/depot_tools' (https://chromium.googlesource.com/chromium/tools/depot_tools.git) registered for path 'vendor/depot_tools'                                                         
Submodule 'vendor/gn-project-generators' (git://github.com/brave/gn-project-generators) registered for path 'vendor/gn-project-generators'                                                         
Submodule 'vendor/jinja' (git://github.com/pallets/jinja.git) registered for path 'vendor/jinja'
Cloning into '/storage/proj/brave-browser/vendor/depot_tools'...
Cloning into '/storage/proj/brave-browser/vendor/gn-project-generators'...
Cloning into '/storage/proj/brave-browser/vendor/jinja'...
Submodule path 'vendor/depot_tools': checked out 'e5e44404584674e4407107cf3c1e7e6df1438a56'
Submodule path 'vendor/gn-project-generators': checked out 'b76e14b162aa0ce40f11920ec94bfc12da29e5d0'                                                                                              
Submodule path 'vendor/jinja': checked out '209fd39b2750400d51bf571740fe5ba23008c20e'
/storage/proj/brave-browser: git -C /storage/proj/brave-browser/vendor/depot_tools clean -fxd
/storage/proj/brave-browser: git -C /storage/proj/brave-browser/vendor/depot_tools reset --hard HEAD                                                                                               
HEAD is now at e5e44404 Roll recipe dependencies (trivial).
Done updating submodules...
Syncing Gclient (with reset)
/storage/proj/brave-browser: gclient sync --force --nohooks --with_branch_heads --with_tags --upstream                                                                                             
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
1>________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://chromium.googlesource.com/chromium/src.git /storage/proj/brave-browser/_gclient_src_BZmzm8' in '/storage/proj/brave-browser'
1>Cloning into '/storage/proj/brave-browser/_gclient_src_BZmzm8'...
1>remote: Sending approximately 16.19 GiB ...
Objects: 182668
[0:01:00] Still working on:
[0:01:00]   src
1>remote: Counting objects: 203981, done
1>remote: Finding sources: 100% (1947/1947)
1>Receiving objects:   0% (90463/12683546), 53.05 MiB | 9.69 MiB/s
[0:01:10] Still working on:
[0:01:10]   src
1>Receiving objects:   2% (300676/12683546), 157.64 MiB | 9.64 MiB/s
...

This step downloads 16GB+ of data, so will take some time.

Compile Brave browser in Ubuntu 19.04

Here we go! This took hours on my Dell XPS, so I had to leave the system building Brave browser overnight.

I also had to create additional swap space just so that compilation would work.

There’s about 37894 source code files to be processed/compiled:

greys@xps:/storage/proj/brave-browser $ npm run build Release 

> brave@0.69.62 build /storage/proj/brave-browser 
> node ./scripts/commands.js build "Release" 

Version files do not match! 
src/chrome/VERSION: 0.69.63 
brave-browser package.json version: 0.69.62 
touch original files overridden by chromium_src... 
touch original vector icon files overridden by brave/vector_icons... 
update branding... 
building brave... 
/storage/proj/brave-browser/src: gn gen /storage/proj/brave-browser/src/out/Release --args="fieldtrial_testing_like_offi
cial_build=true safe_browsing_mode=1 root_extra_deps=[\"//brave\"] is_component_build=false proprietary_codecs=true ffmp
eg_branding=\"Chrome\" enable_nacl=false enable_widevine=true target_cpu=\"x64\" target_apk_base=\"classic\" is_official
_build=true is_debug=false dcheck_always_on=false brave_channel=\"\" google_api_key=\"AIzaSyAH90V94EcZBP5oH7oc-mXQrSKgAS
VxER8\" brave_google_api_key=\"AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q\" brave_google_api_endpoint=\"https://www.googlea
pis.com/geolocation/v1/geolocate?key=\" brave_product_name=\"Brave\" brave_project_name=\"brave\" brave_version_major=\"
0\" brave_version_minor=\"69\" brave_version_build=\"62\" chrome_version_string=\"76.0.3809.62\" chrome_version_major=\"
76\" safebrowsing_api_endpoint=\"safebrowsing.brave.com\" brave_referrals_api_key=\"\" enable_hangout_services_extension
=true enable_cdm_host_verification=false cc_wrapper=\"/storage/proj/brave-browser/src/brave/script/redirect-cc.py\" " 
Done. Made 11948 targets from 2064 files in 3505ms 
/storage/proj/brave-browser/src: ninja -C /storage/proj/brave-browser/src/out/Release brave -k 1 
ninja: Entering directory `/storage/proj/brave-browser/src/out/Release' 
[26120/26121] LINK ./chrome

Start the Brave Browser We’ve Just Compiled

That’s the easiest part! Start your freshly compiled browser from the src/out/Release directory:

greys@xps:/storage/proj/brave-browser $ cd src/out/Release
greys@xps:/storage/proj/brave-browser/src/out/Release $ ./brave

About page confirms it’s the new version of the Brave browser, the one that we have just compiled:

That’s it, hope you enjoyed this tutorial! By the way, if you would like to see some of these tutorials as Youtube videos – please let me know!

See Also