2022-08-08 03:56:00 -04:00
# Checking out and Building Thorium for Windows <img src="https://github.com/Alex313031/Thorium/blob/main/logos/NEW/build_light.svg#gh-dark-mode-only" width="48"> <img src="https://github.com/Alex313031/Thorium/blob/main/logos/NEW/build_dark.svg#gh-light-mode-only" width="48">
2022-08-03 13:51:42 -04:00
2022-08-23 15:14:45 -04:00
## System Requirements
2022-08-03 13:51:42 -04:00
* A 64-bit machine with at least 8GB of RAM. More than 16GB is highly
recommended.
* At least 75GB of free disk space on an NTFS-formatted hard drive. FAT32
will not work, as some of the Git packfiles are larger than 4GB.
* An appropriate version of Visual Studio, as described below.
* Windows 10 1709 or newer.
## Setting up Windows
### Visual Studio
Chromium requires [Visual Studio 2019 ](https://visualstudio.microsoft.com/vs/older-downloads/ ) (>=16.0.0)
to build, but [Visual Studio 2022 ](https://visualstudio.microsoft.com/vs/ ) (>=17.0.0)
is preferred. Visual Studio can also be used to debug Chromium, and version 2022 is
preferred for this as it handles Chromium's large debug information much better.
2022-08-03 14:10:59 -04:00
The *clang-cl* compiler is used, but Visual Studio's header files, libraries, and
2022-08-03 13:54:40 -04:00
some tools are required. Visual Studio Community Edition will work. You must install the "Desktop development with
2022-08-03 13:51:42 -04:00
C++" component and the "MFC/ATL support" sub-components. This can be done from
the command line by passing these arguments to the Visual Studio installer (see
below for ARM64 instructions):
```shell
2022-08-03 13:54:40 -04:00
VisualStudioSetup.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.ATLMFC --includeRecommended
2022-08-03 13:51:42 -04:00
```
If you want to build for Windows on ARM64 then some extra arguments are needed. The
full set for that case is:
```shell
2022-08-03 13:54:40 -04:00
VisualStudioSetup.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.ATLMFC --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.Component.VC.MFC.ARM64 --includeRecommended
2022-08-03 13:51:42 -04:00
```
2023-02-27 06:40:16 -03:00
- You must have the version 10.0.22621.755 [Windows 11 SDK ](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/ )
2022-08-03 13:51:42 -04:00
installed. This can be installed separately or by checking the appropriate box
2023-02-27 06:40:16 -03:00
in the Visual Studio Installer (Note that MSVS 2022 will try to install the 22000 version by default, uncheck this and check the 22621 version).
2022-08-03 13:51:42 -04:00
There is also experimental support for the Windows 11 10.1.22000.0 version.
The SDK Debugging Tools must also be installed. If the Windows 10 SDK was
installed via the Visual Studio installer, then they can be installed by going
to: Control Panel → Programs → Programs and Features → Select the "Windows
Software Development Kit" → Change → Change → Check "Debugging Tools For
Windows" → Change. Or, you can download the standalone SDK installer and use it
to install the Debugging Tools.
## Install `depot_tools`
Download the [depot_tools bundle ](https://storage.googleapis.com/chrome-infra/depot_tools.zip )
2022-08-03 14:10:59 -04:00
and extract it to *C:\src\depot_tools* .
2022-08-03 13:51:42 -04:00
2022-08-03 14:10:59 -04:00
***note
__Warning:__ __ *DO NOT*__ use drag-n-drop or copy-n-paste extract from Explorer,
2022-08-03 13:51:42 -04:00
this will not extract the hidden “.git” folder which is necessary for
depot_tools to autoupdate itself. You can use “Extract all…” from the
2022-08-03 14:10:59 -04:00
context menu, or 7-Zip though.
2022-08-03 13:51:42 -04:00
***
Add depot_tools to the start of your PATH (must be ahead of any installs of
2022-08-03 14:10:59 -04:00
Python). Note that environment variable names are case insensitive.
2022-08-03 13:51:42 -04:00
Assuming you unzipped the bundle to *C:\src\depot_tools* , open:
Control Panel → System and Security → System → Advanced system settings
If you have Administrator access, Modify the PATH system variable and
2022-08-03 14:10:59 -04:00
put `C:\src\depot_tools` at the front, by clicking "Move Up". (Or at least in front of any directory
2022-08-03 13:51:42 -04:00
that might already have a copy of Python or Git).
If you don't have Administrator access, you can add a user-level PATH
environment variable by opening:
Control Panel → System and Security → System → Search for "Edit environment variables for your account"
Add `C:\src\depot_tools` at the front. Note: If your system PATH has a Python in it, you will be out of luck.
Also, add a `DEPOT_TOOLS_WIN_TOOLCHAIN` environment variable in the same way, and set
it to __0__ . This tells depot_tools to use your locally installed version of Visual
Studio (by default, depot_tools will try to use a google-internal version).
You should also set the variable `vs2019_install` or
`vs2022_install` to your installation path of Visual Studio 19 or 22, like
`vs2019_install` = __C:\Program Files (x86)\Microsoft Visual Studio\2019\Community__
for Visual Studio 2019, or
`vs2022_install` = __C:\Program Files\Microsoft Visual Studio\2022\Community__
for Visual Studio 2022.
2022-08-03 14:10:59 -04:00
Once all of this is done, we will download some infra archives using `gclient` . \
2022-08-03 13:51:42 -04:00
From a cmd.exe shell, run:
```shell
2022-08-03 13:54:40 -04:00
gclient
2022-08-03 13:51:42 -04:00
```
On first run, gclient will install all the Windows-specific bits needed to work
with the code, including msysgit and Python.
* If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell),
it may appear to run properly, but msysgit, python, and other tools
may not get installed correctly.
* If you see strange errors with the file system on the first run of gclient,
you may want to [disable Windows Indexing ](https://tortoisesvn.net/faq.html#cantmove2 ).
## Check Python install
After running gclient open a command prompt and type `where python` and
confirm that the depot_tools `python.bat` comes ahead of any copies of
python.exe. Failing to ensure this can lead to overbuilding when
using gn - see [crbug.com/611087 ](https://crbug.com/611087 ).
[App Execution Aliases ](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#alias ) in Windows 10/11
can conflict with other installations of python on the system so disable
these for 'python.exe' and 'python3.exe' by opening 'App execution aliases'
section of Control Panel and unticking the boxes next to both of these
that point to 'App Installer'.
2022-08-23 15:14:45 -04:00
## Downloading the Chromium code
2022-08-03 13:51:42 -04:00
First, configure Git:
```shell
2022-08-03 13:54:40 -04:00
git config --global user.name "My Name"
git config --global user.email "my-name@chromium.org"
git config --global core.autocrlf false
git config --global core.filemode false
git config --global branch.autosetuprebase always
2022-08-03 13:51:42 -04:00
```
Create a `chromium` directory in *C:\src* for the checkout and change to it.
```shell
2022-08-03 13:54:40 -04:00
cd / & & cd src & & mkdir chromium & & cd chromium
2022-08-03 13:51:42 -04:00
```
Run the `fetch` tool from `depot_tools` to check out the code and its
dependencies.
```shell
2022-08-03 13:54:40 -04:00
fetch chromium
2022-08-03 13:51:42 -04:00
```
If you don't want the full repo history, you can save a lot of time by
adding the `--no-history` flag to `fetch` .
Expect the command to take 30 minutes on even a fast connection, and many
hours on slower ones.
When `fetch` completes, it will have created a hidden `.gclient` file and a
directory called `src` in the working directory. The remaining instructions
assume you have switched to this directory (i.e. *C:\src\chromium\src* ):
```shell
2022-08-03 13:54:40 -04:00
cd src
2022-08-03 13:51:42 -04:00
```
2022-08-23 15:14:45 -04:00
*Optional*: You can also [build with API
keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
build to talk to some Google services like Google Sync, Translate, and GeoLocation. < img src = "https://github.com/Alex313031/Thorium/blob/main/logos/NEW/Key_Light.svg#gh-dark-mode-only" width = "26" > < img src = "https://github.com/Alex313031/Thorium/blob/main/logos/NEW/Key_Dark.svg#gh-light-mode-only" width = "26" > Thorium has its own keys in a private repository, if you are a builder or would like access to them, contact me. Otherwise, for personal or development builds,
you can create your own keys and add yourself to [google-browser-signin-testaccounts ](https://groups.google.com/u/1/a/chromium.org/g/google-browser-signin-testaccounts )
to enable Sync.
2022-08-03 13:51:42 -04:00
## Downloading the Thorium code
2022-08-03 14:10:59 -04:00
You can either use git clone, or download a .zip from the repo. It should be placed side by side with the Chromium directory in *C:\src* . \
2022-08-03 13:51:42 -04:00
Using Git:
```shell
2022-08-03 13:54:40 -04:00
git clone https://github.com/Alex313031/Thorium.git
2022-08-03 13:51:42 -04:00
```
Or download the .zip (Make sure to rename the extracted dir to just Thorium, not Thorium-main).
[https://github.com/Alex313031/Thorium/archive/refs/heads/main.zip ](https://github.com/Alex313031/Thorium/archive/refs/heads/main.zip )
## Setting up the build
First, we need to copy the Thorium source files over the Chromium tree.
Run the `setup.bat` script in *Thorium\win_scripts* to automate this.
```shell
2022-08-03 13:54:40 -04:00
cd C:\src\Thorium\win_scripts && setup.bat
2022-08-03 13:51:42 -04:00
```
It will drop you back to *C:\src\chromium\src* , which is where the rest of the commands will be carried out.
Next, we will download the PGO profile for Thorium, which changes with every revision. Run:
```shell
2022-08-03 13:54:40 -04:00
python3 tools\update_pgo_profiles.py --target=win64 update --gs-url-base=chromium-optimization-profiles/pgo_profiles
2022-08-03 13:51:42 -04:00
```
2022-08-03 14:10:59 -04:00
This will download a *.profdata file, looking something like `chrome-win64-main-1659409120-058034bd778fed227d12a29fd0edd0942810dbf8.profdata` . \
2022-08-03 13:51:42 -04:00
Take note of this, as we will be using it in the `args.gn` below.
### Creating the build directory
Chromium & Thorium use [Ninja ](https://ninja-build.org ) as its main build tool along with
a tool called [GN ](https://gn.googlesource.com/gn/+/main/docs/quick_start.md ) to generate `.ninja` files. Create the build directory by running:
```shell
2022-08-03 13:54:40 -04:00
gn args out\thorium
2022-08-03 13:51:42 -04:00
```
This will open up notepad.exe, and this is where we will specify build arguments ("args") which direct Ninja on how to lay out the build directory tree.
2022-08-03 14:10:59 -04:00
We will be copy/pasting the contents of the [win_args.gn ](https://github.com/Alex313031/Thorium/blob/main/infra/win_args.gn ) file (from *C:\src\Thorium\infra\win_args.gn* ) into notepad.
Notice the three lines at the top, related to API Keys. It is fine to leave them blank, or add the ones you have made. \
2022-08-03 13:51:42 -04:00
__At the bottom__, though, notice the line that says *pgo_data_path = ""* . This is where we will put the full path to the PGO profile data file we downloaded earlier.
That line should look something like:
`pgo_data_path = "C:\src\chromium\src\chrome\build\pgo_profiles\chrome-win64-main-1659409120-058034bd778fed227d12a29fd0edd0942810dbf8.profdata"`
* For other build arguments, and what the ones that Thorium uses do, see [ABOUT_GN_ARGS.md ](https://github.com/Alex313031/Thorium/blob/main/infra/DEBUG/ABOUT_GN_ARGS.md ) & [win_args.list ](https://github.com/Alex313031/Thorium/blob/main/infra/win_args.list )
* For more info on GN, run `gn help` on the command line or read the [quick
start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
## Build Thorium
2022-08-03 14:10:59 -04:00
Build Thorium, and the other things like [chromedriver ](https://chromedriver.chromium.org/home ) and [thorium_shell ](https://github.com/Alex313031/Thorium/tree/main/thorium_shell#readme ) with Ninja using the command:
2022-08-03 13:51:42 -04:00
```shell
2022-08-03 13:54:40 -04:00
autoninja -C out\thorium chrome chromedriver thorium_shell setup mini_installer -j8
2022-08-03 13:51:42 -04:00
```
2022-08-03 14:10:59 -04:00
(Where -j# can be any number, and should generally be set to the number of cores on your CPU).
2022-08-03 13:51:42 -04:00
`autoninja` is a wrapper that automatically provides optimal values for the
arguments passed to `ninja` .
You can get a list of all of the other build targets from GN by running
2022-08-03 14:10:59 -04:00
`gn ls out\thorium` from the command line. To compile one, pass to Ninja
2022-08-03 13:51:42 -04:00
the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
use autoninja -C out/Default chrome/test:unit_tests).
## Install/Run Thorium
Once it is built, you can simply install the browser.
```shell
2022-08-03 13:54:40 -04:00
out\thorium\mini_installer.exe
2022-08-03 13:51:42 -04:00
```
## Update your checkout
To update an existing Chromium checkout, you should run the `trunk.bat` script in win_scripts:
```shell
2022-08-03 13:54:40 -04:00
cd C:\src\Thorium\win_scripts && trunk.bat
2022-08-03 13:51:42 -04:00
```
2022-08-03 14:10:59 -04:00
(This script will also download the latest PGO profile data file at the end; useful when making fresh builds.)
2022-08-03 13:51:42 -04:00
This syncs the subrepositories to the appropriate versions,
deleting those that are no longer needed, and re-runs the hooks as needed.
To update an existing Thorium checkout, just download the latest .zip, or do a git pull:
```shell
2022-08-03 14:10:59 -04:00
git pull origin main
2022-08-03 13:51:42 -04:00
```
*Happy Thorium Building!*
2022-08-04 16:01:29 -04:00
< img src = "https://github.com/Alex313031/Thorium/blob/main/logos/STAGING/Thorium90_504.jpg" width = "200" >