Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 1 | # Cross-compiling Chrome/win |
| 2 | |
Darwin Huang | fa70c7a | 2019-03-27 21:59:02 | [diff] [blame] | 3 | As many Chromium developers are on Linux/Mac, cross-compiling Chromium for |
| 4 | Windows targets facilitates development for Windows targets on non-Windows |
| 5 | machines. |
| 6 | |
Nico Weber | ce96b470 | 2017-12-14 18:52:31 | [diff] [blame] | 7 | It's possible to build most parts of the codebase on a Linux or Mac host while |
Darwin Huang | fa70c7a | 2019-03-27 21:59:02 | [diff] [blame] | 8 | targeting Windows. It's also possible to run the locally-built binaries on |
| 9 | swarming. This document describes how to set that up, and current restrictions. |
| 10 | |
| 11 | ## Limitations |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 12 | |
| 13 | What does *not* work: |
| 14 | |
Nico Weber | 3a54e6f | 2019-10-02 19:58:52 | [diff] [blame] | 15 | * `js2gtest` tests are omitted from the build ([bug](https://crbug.com/1010561)) |
dpapad | 97205b3d | 2023-07-28 06:11:39 | [diff] [blame] | 16 | Note that newer WebUI tests are not based on js2gtest |
| 17 | (see migration progress at [crbug.com/1457360](https://crbug.com/1457360)) and |
| 18 | are included in the build. |
Hans Wennborg | 193ddf4 | 2019-10-07 14:14:35 | [diff] [blame] | 19 | * on Mac hosts, 32-bit builds don't work ([bug](https://crbug.com/794838) has |
| 20 | more information, and this is unlikely to ever change) |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 21 | |
Nico Weber | 495e955 | 2017-10-23 20:03:07 | [diff] [blame] | 22 | All other targets build fine (including `chrome`, `browser_tests`, ...). |
| 23 | |
Nico Weber | 705836c | 2019-03-26 17:18:15 | [diff] [blame] | 24 | Uses of `.asm` files have been stubbed out. As a result, Crashpad cannot |
| 25 | report crashes, and NaCl defaults to disabled and cannot be enabled in cross |
| 26 | builds ([.asm bug](https://crbug.com/762167)). |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 27 | |
| 28 | ## .gclient setup |
| 29 | |
| 30 | 1. Tell gclient that you need Windows build dependencies by adding |
| 31 | `target_os = ['win']` to the end of your `.gclient`. (If you already |
Lei Zhang | 4d34c1fb | 2017-10-23 22:29:37 | [diff] [blame] | 32 | have a `target_os` line in there, just add `'win'` to the list.) e.g. |
| 33 | |
| 34 | solutions = [ |
| 35 | { |
| 36 | ... |
| 37 | } |
| 38 | ] |
| 39 | target_os = ['android', 'win'] |
| 40 | |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 41 | 1. `gclient sync`, follow instructions on screen. |
| 42 | |
Nigel Tao | c77ad1b | 2021-03-17 23:54:03 | [diff] [blame] | 43 | ### If you're at Google |
| 44 | |
| 45 | `gclient sync` should automatically download the Windows SDK for you. If this |
| 46 | fails with an error: |
Hans Wennborg | c6d904c | 2018-06-25 14:07:29 | [diff] [blame] | 47 | |
| 48 | Please follow the instructions at |
Wan-Teh Chang | ccad232a | 2020-12-07 23:35:16 | [diff] [blame] | 49 | https://chromium.googlesource.com/chromium/src/+/HEAD/docs/win_cross.md |
Hans Wennborg | c6d904c | 2018-06-25 14:07:29 | [diff] [blame] | 50 | |
Tom Sepez | 3e3f0ceda | 2017-10-23 21:18:02 | [diff] [blame] | 51 | then you may need to re-authenticate via: |
| 52 | |
| 53 | cd path/to/chrome/src |
| 54 | # Follow instructions, enter 0 as project id. |
| 55 | download_from_google_storage --config |
| 56 | |
Nigel Tao | c77ad1b | 2021-03-17 23:54:03 | [diff] [blame] | 57 | `gclient sync` should now succeed. Skip ahead to the [GN setup](#gn-setup) |
| 58 | section. |
| 59 | |
| 60 | ### If you're not at Google |
| 61 | |
Frédéric Wang | ee66b89 | 2021-11-24 09:22:28 | [diff] [blame] | 62 | After installing [Microsoft's development tools](windows_build_instructions.md#visual-studio), |
| 63 | you can package your Windows SDK installation into a zip file by running the following on a Windows machine: |
Henrique Ferreiro | a5be472 | 2018-06-25 11:49:45 | [diff] [blame] | 64 | |
| 65 | cd path/to/depot_tools/win_toolchain |
Frédéric Wang | b603481 | 2021-11-24 11:29:25 | [diff] [blame] | 66 | python package_from_installed.py <vs version> -w <win version> |
| 67 | |
| 68 | where `<vs version>` and `<win version>` correspond respectively to the |
| 69 | versions of Visual Studio (e.g. 2019) and of the Windows SDK (e.g. |
Henrique Ferreiro | 1a367a0 | 2022-02-09 12:59:22 | [diff] [blame] | 70 | 10.0.19041.0) installed on the Windows machine. Note that if you didn't |
| 71 | install the ARM64 components of the SDK as noted in the link above, you |
| 72 | should add `--noarm` to the parameter list. |
Henrique Ferreiro | a5be472 | 2018-06-25 11:49:45 | [diff] [blame] | 73 | |
Hans Wennborg | c6d904c | 2018-06-25 14:07:29 | [diff] [blame] | 74 | These commands create a zip file named `<hash value>.zip`. Then, to use the |
Henrique Ferreiro | a5be472 | 2018-06-25 11:49:45 | [diff] [blame] | 75 | generated file in a Linux or Mac host, the following environment variables |
| 76 | need to be set: |
| 77 | |
Frédéric Wang | b603481 | 2021-11-24 11:29:25 | [diff] [blame] | 78 | export DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL=<base url> |
Henrique Ferreiro | 37b2a54 | 2018-07-30 12:19:54 | [diff] [blame] | 79 | export GYP_MSVS_HASH_<toolchain hash>=<hash value> |
Henrique Ferreiro | a5be472 | 2018-06-25 11:49:45 | [diff] [blame] | 80 | |
Frédéric Wang | b603481 | 2021-11-24 11:29:25 | [diff] [blame] | 81 | `<base url>` is the path of the directory containing the zip file (note that |
| 82 | specifying scheme `file://` is not required). |
| 83 | |
Hans Wennborg | 900b6ac5 | 2018-06-25 14:42:00 | [diff] [blame] | 84 | `<toolchain hash>` is hardcoded in `src/build/vs_toolchain.py` and can be found by |
Henrique Ferreiro | a5be472 | 2018-06-25 11:49:45 | [diff] [blame] | 85 | setting `DEPOT_TOOLS_WIN_TOOLCHAIN_BASE_URL` and running `gclient sync`: |
| 86 | |
| 87 | gclient sync |
| 88 | ... |
| 89 | Running hooks: 17% (11/64) win_toolchain |
| 90 | ________ running '/usr/bin/python src/build/vs_toolchain.py update --force' in <chromium dir> |
| 91 | Windows toolchain out of date or doesn't exist, updating (Pro)... |
| 92 | current_hashes: |
| 93 | desired_hash: <toolchain hash> |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 94 | |
Nico Weber | a001bab | 2017-10-23 20:11:10 | [diff] [blame] | 95 | ## GN setup |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 96 | |
Nico Weber | e9464b6 | 2022-03-15 11:06:54 | [diff] [blame] | 97 | Add |
| 98 | |
| 99 | target_os = "win" |
| 100 | |
| 101 | to your args.gn. |
| 102 | |
| 103 | If you're building on an arm host (e.g. a Mac with an Apple Silicon chip), |
| 104 | you very likely also want to add |
| 105 | |
| 106 | target_cpu = "x64" |
| 107 | |
| 108 | lest you build an arm64 chrome/win binary. |
| 109 | |
| 110 | Then just build, e.g. |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 111 | |
| 112 | ninja -C out/gnwin base_unittests.exe |
| 113 | |
Tom Anderson | 497ff623 | 2019-02-20 21:11:41 | [diff] [blame] | 114 | ## Goma |
| 115 | |
Fumitoshi Ukai | 50efdea | 2021-03-14 23:23:47 | [diff] [blame] | 116 | This should be supported by the default (Goma RBE) backend. |
Fumitoshi Ukai | c2856df | 2019-11-29 03:06:42 | [diff] [blame] | 117 | |
Nico Weber | 1f05f16 | 2018-01-22 19:06:42 | [diff] [blame] | 118 | ## Copying and running chrome |
| 119 | |
| 120 | A convenient way to copy chrome over to a Windows box is to build the |
| 121 | `mini_installer` target. Then, copy just `mini_installer.exe` over |
| 122 | to the Windows box and run it to install the chrome you just built. |
| 123 | |
kylechar | 78c9077c | 2019-06-06 14:49:34 | [diff] [blame] | 124 | Note that the `mini_installer` doesn't include PDB files. PDB files are needed |
| 125 | to correctly symbolize stack traces (or if you want to attach a debugger). |
| 126 | |
Nico Weber | a001bab | 2017-10-23 20:11:10 | [diff] [blame] | 127 | ## Running tests on swarming |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 128 | |
| 129 | You can run the Windows binaries you built on swarming, like so: |
| 130 | |
Henrique Nakashima | 14cfed59 | 2021-11-10 19:35:07 | [diff] [blame] | 131 | tools/run-swarmed.py out/gnwin base_unittests -- [ --gtest_filter=... ] |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 132 | |
Hans Wennborg | f3adf863 | 2018-03-26 10:27:09 | [diff] [blame] | 133 | See the contents of run-swarmed.py for how to do this manually. |
Nico Weber | bf97a6d1 | 2017-10-13 17:40:02 | [diff] [blame] | 134 | |
Hans Wennborg | c6d904c | 2018-06-25 14:07:29 | [diff] [blame] | 135 | The |
Hans Wennborg | cc6e227 | 2023-06-09 12:52:30 | [diff] [blame] | 136 | [linux-win_cross-rel](https://ci.chromium.org/p/chromium/builders/ci/linux-win_cross-rel) |
Hans Wennborg | c6d904c | 2018-06-25 14:07:29 | [diff] [blame] | 137 | buildbot does 64-bit release cross builds, and also runs tests. You can look at |
| 138 | it to get an idea of which tests pass in the cross build. |