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