Page Summary
-
These instructions guide Linux users through setting up a Cobalt development environment, cloning the Cobalt repository, and building a local Cobalt binary with a graphical client.
-
The setup requires installing specific libraries, ccache for build acceleration, Node.js, and GN, followed by cloning the Cobalt code repository and setting the
PYTHONPATHenvironment variable. -
Developers can set up a Python virtual environment and install pre-commit hooks to assist in development workflows after setting up their workstation and entering the
cobaltdirectory. -
Cobalt can be built and run using
gn.pyandninjacommands, specifying a platform, build type, and target name, with the binary run locally, and several optional command-line flags can be used to adjust the way it runs. -
Cobalt can be executed in Evergreen mode by downloading and configuring official Google-built Cobalt binaries from GitHub and building the partner-built Loader App and Crashpad Handler executables, then running it with
loader_app. -
NPLB (Starboard's platform verification test suite) can be built using Cobalt toolchain and launched via
elf_loader_sandboxto verify the Starboard implementation and detect potential issues with toolchain compatibility, with Gtest arguments also available.
These instructions explain how to set up a Cobalt development environment, clone the repository, and build a Cobalt binary on Linux. The binary includes a graphical client that you must run locally. For example, you cannot run the binary over an SSH connection.
These instructions are tested on a clean Ubuntu 22.04 environment. We recommend using Git version 2.51 or later (versions 2.25 and greater are known to work, but older versions may fail with gclient). Required libraries may vary depending on your Linux distribution.
Set up your workstation
Run the following command to install packages needed to build and run Cobalt on Linux:
sudo apt update && sudo apt install -qqy --no-install-recommends \ git curl python3-dev xz-utils lsb-release fileInstall
ccachefor build acceleration. Acceleration is enabled by default; you must disable it ifccacheis not installed.sudo apt install -qqy --no-install-recommends ccacheWe recommend adjusting the cache size as needed to increase cache hits:
ccache --max-size=20GTo explicitly configure
ccachefor your build, rungn argsafter initializing your build directory withgn.pyand append the wrapper configuration:gn args out/linux-x64x11_devel # Add a new line: cc_wrapper = "ccache"Clone Google's
depot_toolsrepository and add the directory toPATHfor this session:git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/depot_tools export PATH="$PATH:$HOME/depot_tools"Consider adding the
depot_toolsdirectory toPATHin.bashrcor.profileto make it permanent across sessions.
Get source code
To configure your local workspace, clone the Cobalt repository and use gclient to synchronize dependencies.
Create a working directory and clone the Cobalt repository into the
srcdirectory expected bygclient:mkdir ~/cobalt && cd ~/cobalt git clone --single-branch https://github.com/youtube/cobalt.git srcConfigure
gclientto track the Cobalt repository as the primary source and synchronize dependencies:gclient config --name=src https://github.com/youtube/cobalt.git cd src gclient sync --no-history -r $(git rev-parse @)Install system build dependencies and execute gclient hooks:
build/install-build-deps.sh gclient runhooks
Build and Run Cobalt
Build the code by running the following command in the top-level
srcdirectory. You must specify a platform. For Ubuntu Linux, the canonical platform islinux-x64x11.Use the
-cflag to specify abuild_type(debug,devel,qa, orgold). Specifying a build type speeds up the configuration step because only that type is configured; otherwise, all types are configured.cobalt/build/gn.py [-c <build_type>] -p <platform> --no-rbeCompile the code from the
srcdirectory:autoninja -C out/<platform>_<build_type> <target_name>The command contains three variables:
<platform>is the platform configuration that identifies the platform. As described in the Starboard porting guide, it contains afamily name(likelinux) and abinary variant(likex64x11), separated by a hyphen.<build_type>is the build you are compiling. Possible values aredebug,devel,qa, andgold.<target_name>is the name assigned to the compiled code and it is used to run the code compiled in this step. The most common names arecobalt,nplb, andall:cobaltbuilds the Cobalt app.nplbbuilds Starboard's platform verification test suite to ensure that your platform's code passes all tests for running Cobalt.allbuilds all targets.
For example:
cobalt/build/gn.py -p linux-x64x11 -c devel --no-rbe autoninja -C out/linux-x64x11_devel cobaltThis command configures the Cobalt
develconfiguration for thelinux-x64x11platform and compiles a target namedcobaltthat you can then use to run the compiled code.For additional tips on speeding up compilation, refer to Chromium's faster builds documentation.
Run the compiled code to launch the Cobalt client:
# Note that 'cobalt' was the <target_name> from the previous step. out/linux-x64x11_devel/cobalt [--url=<url>]The flags in the following table are frequently used, and the full set of flags that this command supports are in
cobalt/browser/switches.cc.Flags allow_httpIndicates that you want to use `http` instead of `https`. ignore_certificate_errorsIndicates that you want to connect to an httpshost that doesn't have a certificate that can be validated by our set of root CAs.urlDefines the startup URL that Cobalt will use. If no value is set, then Cobalt uses a default URL. This option lets you point at a different app than the YouTube app.
Debugging
Cobalt debug, devel, and qa configurations support thread callstack tracing. This is a powerful tool for debugging application performance and issues, and understanding Cobalt's overall execution flow.
To use this feature, build and run one of these configurations and monitor the terminal output.
Running in Evergreen Mode
Because Evergreen support is required for certification, you can also run Cobalt in Evergreen mode on Linux.
Initialize an Evergreen build directory for
evergreen-x64:cobalt/build/gn.py -p evergreen-x64 -c qa --no-rbeCompile the
cobalt_loadertarget, which packages the compressed Evergreen library:autoninja -C out/evergreen-x64_qa cobalt_loaderLaunch Cobalt in Evergreen mode by running the generated helper script:
out/evergreen-x64_qa/cobalt_loader.py [--url=<url>]
Running Tests
The No Platform Left Behind (NPLB) test suite verifies Starboard implementation and is mandatory for certification.
Compile the NPLB test suite in Evergreen mode:
cobalt/build/gn.py -p evergreen-x64 -c devel --no-rbe autoninja -C out/evergreen-x64_devel nplb_loaderExecute NPLB using the generated Python loader script, which invokes
elf_loader_sandboxunder the hood:out/evergreen-x64_devel/nplb_loader.pyTo pass standard Google Test filtering or output arguments:
# Run NPLB with a specific test filter and output results to an XML file out/evergreen-x64_devel/nplb_loader.py -- --gtest_filter=*Posix* --gtest_output=xml:/tmp/nplb_results.xml
Clean up or reset the environment
To reset your Linux build environment or purge cached toolchains:
To clean build artifacts and free up disk space without deleting your source repository:
# Purge all compiled object files and artifacts in the build directory gn clean out/linux-x64x11_develTo permanently delete the entire development environment, including all uncommitted local changes, branches, and the source repository:
rm -rf ~/cobalt