Cross-Compiling Thorium for Windows on Linux

As many Thorium developers are on Linux/Mac, cross-compiling Thorium for Windows targets facilitates development for Windows targets on non-Windows machines.

It's possible to build most parts of the codebase on a Linux or Mac host while targeting Windows. It's also possible to run the locally-built binaries on swarming. This document describes how to set that up, and current restrictions.

Limitations

What does not work:

  • js2gtest tests are omitted from the build (bug)
  • on Mac hosts, 32-bit builds don't work (bug has more information, and this is unlikely to ever change)

All other targets build fine (including chrome, thorium_shell, etc...).

Uses of .asm files have been stubbed out. As a result, Crashpad cannot report crashes, and NaCl defaults to disabled and cannot be enabled in cross builds ( .asm bug).

Setup

First make sure you've followed the instructions for getting the Chromium and Thorium code from HERE.
Also make sure you have run setup.sh to copy the Thorium code over the Chromium tree.

.gclient setup

  1. Tell gclient that you need Windows build dependencies by adding target_os = ['win'] to the end of your .gclient file present in ~/chromium/. (If you already have a target_os line in there, just add 'win' to the list.) e.g.

    solutions = [
      {
        ...
      }
    ]
    target_os = ['linux', 'win']
    
                                
  2. Run a trunk.sh, and follow instructions on screen.

Installing the MSVS Artifacts Archive

Download the latest MSVS Artifacts Archive from HERE.
Then, make a subdir in chromium called win, i.e. mkdir ~/chromium/win, and then place the .zip file in there.

Then, to use the generated file on a Linux or Mac host, the following environment variables need to be set, so add these lines to your .bashrc or .zshrc.

export DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL=<base url>
export GYP_MSVS_HASH_<toolchain hash>=<hash value>

                    

<base url> is the full path of the directory containing the .zip file, i.e. /home/alex/chromium/win/80909eccbb.zip

<toolchain hash> is hardcoded in src/build/vs_toolchain.py and can be found by setting DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL and running gclient runhooks:

gclient runhooks
...
Running hooks:  17% (11/64) win_toolchain
________ running '/usr/bin/python src/build/vs_toolchain.py update --force' in <chromium dir>
Windows toolchain out of date or doesn't exist, updating (Pro)...
current_hashes:
desired_hash: <toolchain hash>

                    

<hash value> is the name of the .zip, without .zip at the end, i.e. 80909eccbb

Generating a MSVS Artifacts Archive yourself

After installing Microsoft's development tools, you can package your Windows SDK installation into a zip file by running the following on a Windows machine in cmd.exe:

    cd path/to/depot_tools/win_toolchain
    python3 package_from_installed.py <vs version> -w <win version>

Where "path/to/depot_tools/win_toolchain" would usually be C:\src\depot_tools\win_toolchain and where <vs version> and <win version> correspond respectively to the versions of Visual Studio (e.g. 2019) and of the Windows SDK (e.g. 10.0.20348.0) installed on the Windows machine. Note that if you didn't install the ARM64 components of the SDK as noted in the link above, you should add --noarm to the parameter list.

NOTE: The -w flag takes the raw internal version of the SDK, not the actual patch version. This caused me and I'm sure other people some confusion. So for example, the latest version of the Win 10 SDK is 10.1.20348.1, but its internal version doesn't change from when it was released, and this is what you would use, e.g. 10.0.20348.0

These commands create a zip file named <hash value>.zip, which can be used with the instructions above ^.

Building

Follow Setting up the build, except instead of using the args.gn from the root of the Thorium repo, use the win_args.gn, from ~/Thorium/infra/

Then, to build, run build_win.sh, instead of build.sh. See > Here.

Happy Thorium Building!