These instructions explain how Windows users can set up their Cobalt development environment, clone a copy of the Cobalt code repository, and build a Cobalt binary. Note that the binary has a graphical client and must be run locally on the machine that you are using to view the client. For example, you cannot SSH into another machine and run the binary on that machine.
Set up your workstation
Install the following required packages:
- git
(see the
Installing on Windows
instructions) - ninja (see the
Getting Ninja
instructions) - nodejs
- python3
- The following VS2022 components:
- Microsoft.VisualStudio.Component.VC.14.34.17.4.x86.x64
- Microsoft.VisualStudio.Component.VC.Llvm.Clang
- Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset
- Microsoft.VisualStudio.Component.Windows10SDK.18362
- Microsoft.VisualStudio.Workload.NativeDesktop
- winflexbison
- git
(see the
Install GN, which we use for our build system code. There are a few ways to get the binary, follow the instructions for whichever way you prefer here.
(Optional) Install Sccache to support build acceleration.
Make sure all of the above installed packages are on your Path environment variable.
"C:\Program Files\Git" "C:\Program Files\Ninja" "C:\Program Files\nodejs" "C:\python_38" # Python 3.8 is the oldest supported python version. You may have a newer version installed. "C:\python_38\Scripts" "C:\winflexbison" # Or wherever you chose to unpack the zip file "C:\gn" "C:\sccache"
Clone the Cobalt code repository. The following
git
command creates acobalt
directory that contains the repository:$ git clone https://github.com/youtube/cobalt.git
Set the
PYTHONPATH
environment variable to include the full path to the top-levelcobalt
directory from the previous step.
Set up Developer Tools
Enter your new
cobalt
directory:$ cd cobalt
Create a virtual evnrionment by running the following in cmd:
py -3 -m venv "%HOME%/.virtualenvs/cobalt_dev" "%HOME%/.virtualenvs/cobalt_dev/Scripts/activate.bat" pip install -r requirements.txt
Or the following in Powershell:
py -3 -m venv $env:HOME/.virtualenvs/cobalt_dev $env:HOME/.virtualenvs/cobalt_dev/Scripts/activate.ps1 pip install -r requirements.txt
Or the following in Git Bash:
py -3 -m venv ~/.virtualenvs/cobalt_dev source ~/.virtualenvs/cobalt_dev/Scripts/activate pip install -r requirements.txt
Install the pre-commit hooks:
$ pre-commit install -t post-checkout -t pre-commit -t pre-push --allow-missing-config $ git checkout -b <my-branch-name> origin/main
Build and Run Cobalt
Build the code running the following command in the top-level
cobalt
directory. You must specify a platform when running this command. On Windows the canonical platform iswin-win32
.You can also use the
-c
command-line flag to specify abuild_type
. Valid build types aredebug
,devel
,qa
, andgold
. If you specify a build type, the command finishes sooner. Otherwise, all types are built.$ python cobalt/build/gn.py [-c <build_type>] -p <platform>
Compile the code from the
cobalt/
directory:$ ninja -C out/<platform>_<build_type> <target_name>
The previous 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. For Windows builds use win-win32. -
<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
:-
cobalt
builds the Cobalt app. -
nplb
builds Starboard's platform verification test suite to ensure that your platform's code passes all tests for running Cobalt. -
all
builds all targets.
-
For example:
ninja -C out/win-win32_debug cobalt
This command compiles the Cobalt
debug
configuration for thewin-win32
platform and creates a target namedcobalt
that you can then use to run the compiled code.-
Run the compiled code to launch the Cobalt client:
# Note that 'cobalt' was the <target_name> from the previous step. $ out/win-win32_debug/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_http
Indicates that you want to use http
instead ofhttps
.ignore_certificate_errors
Indicates that you want to connect to an https
host that doesn't have a certificate that can be validated by our set of root CAs.url
Defines 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
configs of Cobalt expose a feature enabling
developers to trace Cobalt's callstacks per-thread. This is not only a great way
to debug application performance, but also a great way to debug issues and
better understand Cobalt's execution flow in general.
Simply build and run one of these configs and observe the terminal output.
Cobalt on Xbox One
In order to build Cobalt for Xbox One, you will need access to Microsoft's XDK. In order to sideload and run custom apps on Xbox you will need either an Xbox devkit or the ability to put an Xbox into developer mode. Those steps are outside the scope of this document.
AppxManifest Settings
Cobalt makes use of several template files and a settings file to generate an
AppxManifest.xml during the ninja step. The settings can be found in
starboard/xb1/appx_product_settings.py
. Most of the default values are stubs
and intended to be overwritten by developers creating their own app with Cobalt,
but they should work for local testing.
Build Cobalt
To build Cobalt for the Xbox One, set the platform to xb1
in the gn step:
$ python cobalt/build/gn.py [-c <build_type>] -p xb1
Then specify the cobalt_install
build target in the ninja step:
ninja -C out/xb1_devel cobalt_install
Package an Appx
There's a convenience script at starboard/xb1/tools/packager.py
for packaging
the compiled code into an appx and then signing the appx with the pfx file
located at starboard/xb1/cert/cobalt.pfx
. The source, output, and product
flags must be specified, and the only valid product for an external build is
cobalt
. Here's an example usage:
python starboard/xb1/tools/packager.py -s out/xb1_devel/ -o out/xb1_devel/package -p cobalt
Alternatively, you can use the MakeAppx and SignTool PowerShell commands to manually perform those steps.
Once the appx has been created and signed, it can be deployed to an Xbox using the WinAppDeployCmd PowerShell command.