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