dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 1 | # Checking out and Building Chromium for Windows |
| 2 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 3 | There are instructions for other platforms linked from the |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 4 | [get the code](get_the_code.md) page. |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 5 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 6 | ## Instructions for Google Employees |
| 7 | |
| 8 | Are you a Google employee? See |
scottmg | 292538ae | 2017-01-12 00:10:55 | [diff] [blame] | 9 | [go/building-chrome-win](https://goto.google.com/building-chrome-win) instead. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 10 | |
| 11 | [TOC] |
| 12 | |
| 13 | ## System requirements |
| 14 | |
| 15 | * A 64-bit Intel machine with at least 8GB of RAM. More than 16GB is highly |
| 16 | recommended. |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 17 | * At least 100GB of free disk space on an NTFS-formatted hard drive. FAT32 |
| 18 | will not work, as some of the Git packfiles are larger than 4GB. |
Bruce Dawson | 97367b7 | 2017-10-18 00:47:49 | [diff] [blame] | 19 | * An appropriate version of Visual Studio, as described below. |
Bruce Dawson | 52c749c | 2020-12-03 16:44:26 | [diff] [blame] | 20 | * Windows 10 or newer. |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 21 | |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 22 | ## Setting up Windows |
| 23 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 24 | ### Visual Studio |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 25 | |
Frédéric Wang | ee66b89 | 2021-11-24 09:22:28 | [diff] [blame] | 26 | Chromium requires [Visual Studio 2017](https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes) (>=15.7.2) |
| 27 | to build, but [Visual Studio 2019](https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes) (>=16.0.0) |
| 28 | is preferred. Visual Studio can also be used to debug Chromium, and version 2019 is |
Bruce Dawson | fa55110 | 2019-06-11 23:50:04 | [diff] [blame] | 29 | preferred for this as it handles Chromium's large debug information much better. |
Raul Tambre | 1bb5c1a | 2018-12-29 00:57:12 | [diff] [blame] | 30 | The clang-cl compiler is used but Visual Studio's header files, libraries, and |
| 31 | some tools are required. Visual Studio Community Edition should work if its |
| 32 | license is appropriate for you. You must install the "Desktop development with |
| 33 | C++" component and the "MFC/ATL support" sub-components. This can be done from |
| 34 | the command line by passing these arguments to the Visual Studio installer (see |
| 35 | below for ARM64 instructions): |
Bruce Dawson | 1c0979a6 | 2017-09-13 17:47:21 | [diff] [blame] | 36 | ```shell |
Bruce Dawson | e42d764 | 2018-12-10 23:50:00 | [diff] [blame] | 37 | $ PATH_TO_INSTALLER.EXE ^ |
| 38 | --add Microsoft.VisualStudio.Workload.NativeDesktop ^ |
| 39 | --add Microsoft.VisualStudio.Component.VC.ATLMFC ^ |
| 40 | --includeRecommended |
Bruce Dawson | 1c0979a6 | 2017-09-13 17:47:21 | [diff] [blame] | 41 | ``` |
pwnall | 43b43ba | 2016-08-22 19:29:29 | [diff] [blame] | 42 | |
Bruce Dawson | e42d764 | 2018-12-10 23:50:00 | [diff] [blame] | 43 | If you want to build for ARM64 Win32 then some extra arguments are needed. The |
| 44 | full set for that case is: |
| 45 | ```shell |
| 46 | $ PATH_TO_INSTALLER.EXE ^ |
| 47 | --add Microsoft.VisualStudio.Workload.NativeDesktop ^ |
| 48 | --add Microsoft.VisualStudio.Component.VC.ATLMFC ^ |
| 49 | --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^ |
| 50 | --add Microsoft.VisualStudio.Component.VC.MFC.ARM64 ^ |
| 51 | --includeRecommended |
| 52 | ``` |
| 53 | |
Frédéric Wang | ee66b89 | 2021-11-24 09:22:28 | [diff] [blame] | 54 | -You must have the version 10.0.19041 or higher [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/) |
| 55 | installed. This |
Bruce Dawson | e42d764 | 2018-12-10 23:50:00 | [diff] [blame] | 56 | can be installed separately or by checking the appropriate box in the Visual |
| 57 | Studio Installer. |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 58 | |
| 59 | The SDK Debugging Tools must also be installed. If the Windows 10 SDK was |
| 60 | installed via the Visual Studio installer, then they can be installed by going |
| 61 | to: Control Panel → Programs → Programs and Features → Select the "Windows |
| 62 | Software Development Kit" → Change → Change → Check "Debugging Tools For |
| 63 | Windows" → Change. Or, you can download the standalone SDK installer and use it |
| 64 | to install the Debugging Tools. |
Robert Sesek | c8ffa1b | 2017-08-04 19:55:22 | [diff] [blame] | 65 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 66 | ## Install `depot_tools` |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 67 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 68 | Download the [depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip) |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 69 | and extract it somewhere. |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 70 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 71 | *** note |
| 72 | **Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer, |
| 73 | this will not extract the hidden “.git” folder which is necessary for |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 74 | depot_tools to autoupdate itself. You can use “Extract all…” from the |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 75 | context menu though. |
| 76 | *** |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 77 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 78 | Add depot_tools to the start of your PATH (must be ahead of any installs of |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 79 | Python). Assuming you unzipped the bundle to C:\src\depot_tools, open: |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 80 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 81 | Control Panel → System and Security → System → Advanced system settings |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 82 | |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 83 | If you have Administrator access, Modify the PATH system variable and |
| 84 | put `C:\src\depot_tools` at the front (or at least in front of any directory |
| 85 | that might already have a copy of Python or Git). |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 86 | |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 87 | If you don't have Administrator access, you can add a user-level PATH |
| 88 | environment variable and put `C:\src\depot_tools` at the front, but |
| 89 | if your system PATH has a Python in it, you will be out of luck. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 90 | |
| 91 | Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set |
| 92 | it to 0. This tells depot_tools to use your locally installed version of Visual |
Aaron Gable | dad9e0f | 2020-01-09 19:38:52 | [diff] [blame] | 93 | Studio (by default, depot_tools will try to use a google-internal version). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 94 | |
Bruce Dawson | 6f7d6fa | 2021-12-21 16:19:32 | [diff] [blame] | 95 | You may also have to set variable `vs2017_install` or `vs2019_install` or |
| 96 | `vs2022_install` to your installation path of Visual Studio 2017 or 19 or 22, like |
Andreas Papacharalampous | 1d22c961 | 2020-06-13 23:11:17 | [diff] [blame] | 97 | `set vs2019_install=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional` |
Bruce Dawson | 6f7d6fa | 2021-12-21 16:19:32 | [diff] [blame] | 98 | for Visual Studio 2019, or |
| 99 | `set vs2022_install=C:\Program Files\Microsoft Visual Studio\2022\Professional` |
| 100 | for Visual Studio 2022. |
Andreas Papacharalampous | 1d22c961 | 2020-06-13 23:11:17 | [diff] [blame] | 101 | |
Reilly Grant | 07ff22e | 2021-10-19 19:21:20 | [diff] [blame] | 102 | From a cmd.exe shell, run: |
| 103 | |
| 104 | ```shell |
| 105 | $ gclient |
| 106 | ``` |
| 107 | |
| 108 | On first run, gclient will install all the Windows-specific bits needed to work |
| 109 | with the code, including msysgit and python. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 110 | |
| 111 | * If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell), |
| 112 | it may appear to run properly, but msysgit, python, and other tools |
| 113 | may not get installed correctly. |
| 114 | * If you see strange errors with the file system on the first run of gclient, |
Yuma Takai | d4809d55 | 2022-02-15 03:48:19 | [diff] [blame^] | 115 | you may want to [disable Windows Indexing](https://tortoisesvn.net/faq.html#cantmove2). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 116 | |
Will Harris | 1c8f89c | 2021-03-08 22:53:43 | [diff] [blame] | 117 | ## Check python install |
| 118 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 119 | After running gclient open a command prompt and type `where python` and |
| 120 | confirm that the depot_tools `python.bat` comes ahead of any copies of |
| 121 | python.exe. Failing to ensure this can lead to overbuilding when |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 122 | using gn - see [crbug.com/611087](https://crbug.com/611087). |
| 123 | |
Will Harris | 1c8f89c | 2021-03-08 22:53:43 | [diff] [blame] | 124 | [App Execution Aliases](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#alias) |
| 125 | can conflict with other installations of python on the system so disable |
| 126 | these for 'python.exe' and 'python3.exe' by opening 'App execution aliases' |
| 127 | section of Control Panel and unticking the boxes next to both of these |
| 128 | that point to 'App Installer'. |
| 129 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 130 | ## Get the code |
| 131 | |
Leonard Mosescu | 718c9ac | 2017-06-20 18:06:32 | [diff] [blame] | 132 | First, configure Git: |
| 133 | |
| 134 | ```shell |
| 135 | $ git config --global user.name "My Name" |
| 136 | $ git config --global user.email "[email protected]" |
| 137 | $ git config --global core.autocrlf false |
| 138 | $ git config --global core.filemode false |
| 139 | $ git config --global branch.autosetuprebase always |
| 140 | ``` |
| 141 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 142 | Create a `chromium` directory for the checkout and change to it (you can call |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 143 | this whatever you like and put it wherever you like, as |
| 144 | long as the full path has no spaces): |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 145 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 146 | ```shell |
| 147 | $ mkdir chromium && cd chromium |
| 148 | ``` |
| 149 | |
| 150 | Run the `fetch` tool from `depot_tools` to check out the code and its |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 151 | dependencies. |
| 152 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 153 | ```shell |
xiaoyin.l | 802e4b3e | 2016-12-04 22:17:30 | [diff] [blame] | 154 | $ fetch chromium |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 155 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 156 | |
| 157 | If you don't want the full repo history, you can save a lot of time by |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 158 | adding the `--no-history` flag to `fetch`. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 159 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 160 | Expect the command to take 30 minutes on even a fast connection, and many |
| 161 | hours on slower ones. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 162 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 163 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 164 | directory called `src` in the working directory. The remaining instructions |
| 165 | assume you have switched to the `src` directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 166 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 167 | ```shell |
| 168 | $ cd src |
| 169 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 170 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 171 | *Optional*: You can also [install API |
| 172 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 173 | build to talk to some Google services, but this is not necessary for most |
| 174 | development and testing purposes. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 175 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 176 | ## Setting up the build |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 177 | |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 178 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 179 | a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md) |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 180 | to generate `.ninja` files. You can create any number of *build directories* |
| 181 | with different configurations. To create a build directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 182 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 183 | ```shell |
| 184 | $ gn gen out/Default |
| 185 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 186 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 187 | * You only have to run this once for each new build directory, Ninja will |
| 188 | update the build files as needed. |
| 189 | * You can replace `Default` with another name, but |
| 190 | it should be a subdirectory of `out`. |
Aaron Gable | dad9e0f | 2020-01-09 19:38:52 | [diff] [blame] | 191 | * For other build arguments, including release settings or using an alternate |
| 192 | version of Visual Studio, see [GN build |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 193 | configuration](https://www.chromium.org/developers/gn-build-configuration). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 194 | The default will be a debug component build matching the current host |
| 195 | operating system and CPU. |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 196 | * For more info on GN, run `gn help` on the command line or read the [quick |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 197 | start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md). |
Juan Cruz Viotti | 9c7622d | 2021-06-30 00:27:23 | [diff] [blame] | 198 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 199 | ### Faster builds |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 200 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 201 | * Reduce file system overhead by excluding build directories from |
| 202 | antivirus and indexing software. |
| 203 | * Store the build tree on a fast disk (preferably SSD). |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 204 | * The more cores the better (20+ is not excessive) and lots of RAM is needed |
| 205 | (64 GB is not excessive). |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 206 | |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 207 | There are some gn flags that can improve build speeds. You can specify these |
| 208 | in the editor that appears when you create your output directory |
| 209 | (`gn args out/Default`) or on the gn gen command line |
| 210 | (`gn gen out/Default --args="is_component_build = true is_debug = true"`). |
| 211 | Some helpful settings to consider using include: |
| 212 | * `is_component_build = true` - this uses more, smaller DLLs, and incremental |
| 213 | linking. |
Bruce Dawson | fcd3deb1 | 2017-07-28 17:12:20 | [diff] [blame] | 214 | * `enable_nacl = false` - this disables Native Client which is usually not |
| 215 | needed for local builds. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 216 | * `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and |
| 217 | support incremental linking for more targets. Note that if you set this but |
Bruce Dawson | fcd3deb1 | 2017-07-28 17:12:20 | [diff] [blame] | 218 | don't' set enable_nacl = false then build times may get worse. |
James Cook | 26699a9 | 2019-03-12 22:23:10 | [diff] [blame] | 219 | * `blink_symbol_level = 0` - turn off source-level debugging for |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 220 | blink to reduce build times, appropriate if you don't plan to debug blink. |
Bruce Dawson | 63e0be7 | 2021-11-29 20:34:41 | [diff] [blame] | 221 | * `v8_symbol_level = 0` - turn off source-level debugging for v8 to reduce |
| 222 | build times, appropriate if you don't plan to debug v8. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 223 | |
Bruce Dawson | 817f47fb | 2020-05-01 22:29:08 | [diff] [blame] | 224 | In order to speed up linking you can set `symbol_level = 1` or |
| 225 | `symbol_level = 0` - these options reduce the work the compiler and linker have |
| 226 | to do. With `symbol_level = 1` the compiler emits file name and line number |
| 227 | information so you can still do source-level debugging but there will be no |
| 228 | local variable or type information. With `symbol_level = 0` there is no |
| 229 | source-level debugging but call stacks still have function names. Changing |
| 230 | `symbol_level` requires recompiling everything. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 231 | |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 232 | In addition, Google employees should use goma, a distributed compilation system. |
| 233 | Detailed information is available internally but the relevant gn arg is: |
| 234 | * `use_goma = true` |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 235 | |
| 236 | To get any benefit from goma it is important to pass a large -j value to ninja. |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 237 | A good default is 10\*numCores to 20\*numCores. If you run autoninja then it |
| 238 | will automatically pass an appropriate -j value to ninja for goma or not. |
| 239 | |
| 240 | ```shell |
| 241 | $ autoninja -C out\Default chrome |
| 242 | ``` |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 243 | |
| 244 | When invoking ninja specify 'chrome' as the target to avoid building all test |
| 245 | binaries as well. |
| 246 | |
| 247 | Still, builds will take many hours on many machines. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 248 | |
Juan Cruz Viotti | 9c7622d | 2021-06-30 00:27:23 | [diff] [blame] | 249 | #### Use SCCACHE |
| 250 | |
| 251 | You might be able to use [sccache](https://github.com/mozilla/sccache) for the |
| 252 | build process by enabling the following arguments: |
| 253 | |
| 254 | * `cc_wrapper = "sccache"` - assuming the `sccache` binary is in your `%PATH%` |
| 255 | * `chrome_pgo_phase = 0` |
| 256 | |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 257 | ### Why is my build slow? |
| 258 | |
| 259 | Many things can make builds slow, with Windows Defender slowing process startups |
| 260 | being a frequent culprit. Have you ensured that the entire Chromium src |
Bruce Dawson | 0bbe2d4 | 2018-03-06 19:45:55 | [diff] [blame] | 261 | directory is excluded from antivirus scanning (on Google machines this means |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 262 | putting it in a ``src`` directory in the root of a drive)? Have you tried the |
| 263 | different settings listed above, including different link settings and -j |
| 264 | values? Have you asked on the chromium-dev mailing list to see if your build is |
| 265 | slower than expected for your machine's specifications? |
| 266 | |
Bruce Dawson | 8939017 | 2019-05-08 09:51:18 | [diff] [blame] | 267 | The next step is to gather some data. If you set the ``NINJA_SUMMARIZE_BUILD`` |
Bruce Dawson | b9988e9 | 2019-09-16 17:01:10 | [diff] [blame] | 268 | environment variable to 1 then ``autoninja`` will do three things. First, it |
| 269 | will set the [NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables) |
Bruce Dawson | 8939017 | 2019-05-08 09:51:18 | [diff] [blame] | 270 | environment variable so that ninja will print additional information while |
| 271 | building Chrome. It will show how many build processes are running at any given |
| 272 | time, how many build steps have completed, how many build steps have completed |
| 273 | per second, and how long the build has been running, as shown here: |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 274 | |
| 275 | ```shell |
Bruce Dawson | 8939017 | 2019-05-08 09:51:18 | [diff] [blame] | 276 | $ set NINJA_SUMMARIZE_BUILD=1 |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 277 | $ autoninja -C out\Default base |
| 278 | ninja: Entering directory `out\Default' |
| 279 | [1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb |
| 280 | ``` |
| 281 | |
Bruce Dawson | 8939017 | 2019-05-08 09:51:18 | [diff] [blame] | 282 | This makes slow process creation immediately obvious and lets you tell quickly |
| 283 | if a build is running more slowly than normal. |
| 284 | |
| 285 | In addition, setting ``NINJA_SUMMARIZE_BUILD=1`` tells ``autoninja`` to print a |
| 286 | build performance summary when the build completes, showing the slowest build |
| 287 | steps and slowest build-step types, as shown here: |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 288 | |
| 289 | ```shell |
| 290 | $ set NINJA_SUMMARIZE_BUILD=1 |
| 291 | $ autoninja -C out\Default base |
Bruce Dawson | 2721f0b | 2019-11-08 18:41:27 | [diff] [blame] | 292 | Longest build steps: |
| 293 | 0.1 weighted s to build obj/base/base/trace_log.obj (6.7 s elapsed time) |
| 294 | 0.2 weighted s to build nasm.exe, nasm.exe.pdb (0.2 s elapsed time) |
| 295 | 0.3 weighted s to build obj/base/base/win_util.obj (12.4 s elapsed time) |
| 296 | 1.2 weighted s to build base.dll, base.dll.lib (1.2 s elapsed time) |
| 297 | Time by build-step type: |
| 298 | 0.0 s weighted time to generate 6 .lib files (0.3 s elapsed time sum) |
| 299 | 0.1 s weighted time to generate 25 .stamp files (1.2 s elapsed time sum) |
| 300 | 0.2 s weighted time to generate 20 .o files (2.8 s elapsed time sum) |
| 301 | 1.7 s weighted time to generate 4 PEFile (linking) files (2.0 s elapsed |
| 302 | time sum) |
| 303 | 23.9 s weighted time to generate 770 .obj files (974.8 s elapsed time sum) |
| 304 | 26.1 s weighted time (982.9 s elapsed time sum, 37.7x parallelism) |
| 305 | 839 build steps completed, average of 32.17/s |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 306 | ``` |
| 307 | |
Bruce Dawson | 2721f0b | 2019-11-08 18:41:27 | [diff] [blame] | 308 | The "weighted" time is the elapsed time of each build step divided by the number |
| 309 | of tasks that were running in parallel. This makes it an excellent approximation |
| 310 | of how "important" a slow step was. A link that is entirely or mostly serialized |
| 311 | will have a weighted time that is the same or similar to its elapsed time. A |
| 312 | compile that runs in parallel with 999 other compiles will have a weighted time |
| 313 | that is tiny. |
| 314 | |
Bruce Dawson | 0bbe2d4 | 2018-03-06 19:45:55 | [diff] [blame] | 315 | You can also generate these reports by manually running the script after a build: |
| 316 | |
| 317 | ```shell |
| 318 | $ python depot_tools\post_build_ninja_summary.py -C out\Default |
| 319 | ``` |
| 320 | |
Bruce Dawson | b9988e9 | 2019-09-16 17:01:10 | [diff] [blame] | 321 | Finally, setting ``NINJA_SUMMARIZE_BUILD=1`` tells autoninja to tell Ninja to |
| 322 | report on its own overhead by passing "-d stats". This can be helpful if, for |
| 323 | instance, process creation (which shows up in the StartEdge metric) is making |
| 324 | builds slow, perhaps due to antivirus interference due to clang-cl not being in |
| 325 | an excluded directory: |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 326 | |
| 327 | ```shell |
Bruce Dawson | b9988e9 | 2019-09-16 17:01:10 | [diff] [blame] | 328 | $ set NINJA_SUMMARIZE_BUILD=1 |
| 329 | $ autoninja -C out\Default base |
| 330 | "c:\src\depot_tools\ninja.exe" -C out\Default base -j 10 -d stats |
Bruce Dawson | e9f20fff | 2018-03-03 01:58:38 | [diff] [blame] | 331 | metric count avg (us) total (ms) |
| 332 | .ninja parse 3555 1539.4 5472.6 |
| 333 | canonicalize str 1383032 0.0 12.7 |
| 334 | canonicalize path 1402349 0.0 11.2 |
| 335 | lookup node 1398245 0.0 8.1 |
| 336 | .ninja_log load 2 118.0 0.2 |
| 337 | .ninja_deps load 2 67.5 0.1 |
| 338 | node stat 2516 29.6 74.4 |
| 339 | depfile load 2 1132.0 2.3 |
| 340 | StartEdge 88 3508.1 308.7 |
| 341 | FinishCommand 87 1670.9 145.4 |
| 342 | CLParser::Parse 45 1889.1 85.0 |
| 343 | ``` |
| 344 | |
Bruce Dawson | b9988e9 | 2019-09-16 17:01:10 | [diff] [blame] | 345 | You can also get a visual report of the build performance with |
| 346 | [ninjatracing](https://github.com/nico/ninjatracing). This converts the |
| 347 | .ninja_log file into a .json file which can be loaded into chrome://tracing: |
| 348 | |
| 349 | ```shell |
| 350 | $ python ninjatracing out\Default\.ninja_log >build.json |
| 351 | ``` |
| 352 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 353 | ## Build Chromium |
| 354 | |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 355 | Build Chromium (the "chrome" target) with Ninja using the command: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 356 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 357 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 358 | $ autoninja -C out\Default chrome |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 359 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 360 | |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 361 | `autoninja` is a wrapper that automatically provides optimal values for the |
| 362 | arguments passed to `ninja`. |
| 363 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 364 | You can get a list of all of the other build targets from GN by running |
| 365 | `gn ls out/Default` from the command line. To compile one, pass to Ninja |
| 366 | the GN label with no preceding "//" (so for `//chrome/test:unit_tests` |
| 367 | use ninja -C out/Default chrome/test:unit_tests`). |
| 368 | |
| 369 | ## Run Chromium |
| 370 | |
| 371 | Once it is built, you can simply run the browser: |
| 372 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 373 | ```shell |
| 374 | $ out\Default\chrome.exe |
| 375 | ``` |
| 376 | |
| 377 | (The ".exe" suffix in the command is actually optional). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 378 | |
| 379 | ## Running test targets |
| 380 | |
| 381 | You can run the tests in the same way. You can also limit which tests are |
| 382 | run using the `--gtest_filter` arg, e.g.: |
| 383 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 384 | ```shell |
| 385 | $ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*" |
| 386 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 387 | |
| 388 | You can find out more about GoogleTest at its |
| 389 | [GitHub page](https://github.com/google/googletest). |
| 390 | |
| 391 | ## Update your checkout |
| 392 | |
| 393 | To update an existing checkout, you can run |
| 394 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 395 | ```shell |
| 396 | $ git rebase-update |
Bruce Dawson | ef0b545 | 2020-10-03 00:13:09 | [diff] [blame] | 397 | $ gclient sync -D |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 398 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 399 | |
| 400 | The first command updates the primary Chromium source repository and rebases |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 401 | any of your local branches on top of tip-of-tree (aka the Git branch |
| 402 | `origin/main`). If you don't want to use this script, you can also just use |
| 403 | `git pull` or other common Git commands to update the repo. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 404 | |
Bruce Dawson | ef0b545 | 2020-10-03 00:13:09 | [diff] [blame] | 405 | The second command syncs the subrepositories to the appropriate versions, |
| 406 | deleting those that are no longer needed, and re-runs the hooks as needed. |
| 407 | |
| 408 | ### Editing and Debugging With the Visual Studio IDE |
| 409 | |
| 410 | You can use the Visual Studio IDE to edit and debug Chrome, with or without |
| 411 | Intellisense support. |
| 412 | |
| 413 | #### Using Visual Studio Intellisense |
| 414 | |
| 415 | If you want to use Visual Studio Intellisense when developing Chromium, use the |
| 416 | `--ide` command line argument to `gn gen` when you generate your output |
| 417 | directory (as described on the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code) |
| 418 | page): |
| 419 | |
| 420 | ```shell |
| 421 | $ gn gen --ide=vs out\Default |
| 422 | $ devenv out\Default\all.sln |
| 423 | ``` |
| 424 | |
| 425 | GN will produce a file `all.sln` in your build directory. It will internally |
| 426 | use Ninja to compile while still allowing most IDE functions to work (there is |
| 427 | no native Visual Studio compilation mode). If you manually run "gen" again you |
| 428 | will need to resupply this argument, but normally GN will keep the build and |
| 429 | IDE files up to date automatically when you build. |
| 430 | |
| 431 | The generated solution will contain several thousand projects and will be very |
| 432 | slow to load. Use the `--filters` argument to restrict generating project files |
| 433 | for only the code you're interested in. Although this will also limit what |
| 434 | files appear in the project explorer, debugging will still work and you can |
| 435 | set breakpoints in files that you open manually. A minimal solution that will |
| 436 | let you compile and run Chrome in the IDE but will not show any source files |
| 437 | is: |
| 438 | |
| 439 | ``` |
| 440 | $ gn gen --ide=vs --filters=//chrome --no-deps out\Default |
| 441 | ``` |
| 442 | |
| 443 | You can selectively add other directories you care about to the filter like so: |
| 444 | `--filters=//chrome;//third_party/WebKit/*;//gpu/*`. |
| 445 | |
| 446 | There are other options for controlling how the solution is generated, run `gn |
| 447 | help gen` for the current documentation. |
| 448 | |
| 449 | #### Using Visual Studio without Intellisense |
| 450 | |
| 451 | It is also possible to debug and develop Chrome in Visual Studio without the |
| 452 | overhead of a multi-project solution file. Simply "open" your chrome.exe binary |
| 453 | with `File->Open->Project/Solution`, or from a Visual Studio command prompt like |
| 454 | so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual |
| 455 | Studio's code exploration features will not work in this configuration, but by |
| 456 | installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/) |
| 457 | you can get the source code to appear in the solution explorer window along |
| 458 | with other useful features such as code search. You can add multiple executables |
| 459 | of interest (base_unittests.exe, browser_tests.exe) to your solution with |
| 460 | `File->Add->Existing Project...` and change which one will be debugged by |
| 461 | right-clicking on them in `Solution Explorer` and selecting `Set as Startup |
| 462 | Project`. You can also change their properties, including command line |
| 463 | arguments, by right-clicking on them in `Solution Explorer` and selecting |
| 464 | `Properties`. |
| 465 | |
| 466 | By default when you start debugging in Visual Studio the debugger will only |
| 467 | attach to the main browser process. To debug all of Chrome, install |
| 468 | [Microsoft's Child Process Debugging Power Tool](https://blogs.msdn.microsoft.com/devops/2014/11/24/introducing-the-child-process-debugging-power-tool/). |
| 469 | You will also need to run Visual Studio as administrator, or it will silently |
| 470 | fail to attach to some of Chrome's child processes. |
| 471 | |