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. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 19 | * Visual Studio 2015 Update 3, see below (no other version is supported). |
| 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 | |
Bruce Dawson | 9195839 | 2017-09-28 21:03:58 | [diff] [blame] | 26 | As of September, 2017 Chromium requires Visual Studio 2017 update 3.2 with the |
| 27 | 15063 (Creators Update) Windows SDK or later to build. Visual Studio Community |
| 28 | Edition should work if its license is appropriate for you. You must install the |
Bruce Dawson | 1c0979a6 | 2017-09-13 17:47:21 | [diff] [blame] | 29 | VC++ toolchain and MFC. This can be done from the command line like this: |
| 30 | ```shell |
| 31 | vs_professional.exe --add Microsoft.VisualStudio.Workload.NativeDesktop |
| 32 | --add Microsoft.VisualStudio.Component.VC.ATLMFC --includeRecommended |
| 33 | ``` |
Bruce Dawson | 9195839 | 2017-09-28 21:03:58 | [diff] [blame] | 34 | You must have the Windows 10 SDK installed, version 10.0.15063 or later. |
| 35 | The 10.0.15063 SDK initially had errors but the 10.0.15063.468 version works |
| 36 | well. Most of this will be installed by Visual Studio. |
pwnall | 43b43ba | 2016-08-22 19:29:29 | [diff] [blame] | 37 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 38 | If the Windows 10 SDK was installed via the Visual Studio installer, the Debugging |
Robert Sesek | c8ffa1b | 2017-08-04 19:55:22 | [diff] [blame] | 39 | Tools can be installed by going to: Control Panel → Programs → |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 40 | Programs and Features → Select the "Windows Software Development Kit" → |
Bruce Dawson | 1c0979a6 | 2017-09-13 17:47:21 | [diff] [blame] | 41 | Change → Change → Check "Debugging Tools For Windows" → Change. Or, you can |
Bruce Dawson | 9195839 | 2017-09-28 21:03:58 | [diff] [blame] | 42 | download the standalone SDK installer and use it to install the Debugging Tools. |
Robert Sesek | c8ffa1b | 2017-08-04 19:55:22 | [diff] [blame] | 43 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 44 | ## Install `depot_tools` |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 45 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 46 | Download the [depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip) |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 47 | and extract it somewhere. |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 48 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 49 | *** note |
| 50 | **Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer, |
| 51 | this will not extract the hidden “.git” folder which is necessary for |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 52 | depot_tools to autoupdate itself. You can use “Extract all…” from the |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 53 | context menu though. |
| 54 | *** |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 55 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 56 | 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] | 57 | Python). Assuming you unzipped the bundle to C:\src\depot_tools, open: |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 58 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 59 | Control Panel → System and Security → System → Advanced system settings |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 60 | |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 61 | If you have Administrator access, Modify the PATH system variable and |
| 62 | put `C:\src\depot_tools` at the front (or at least in front of any directory |
| 63 | that might already have a copy of Python or Git). |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 64 | |
dpranke | 4b470c5b | 2017-01-19 17:38:04 | [diff] [blame] | 65 | If you don't have Administrator access, you can add a user-level PATH |
| 66 | environment variable and put `C:\src\depot_tools` at the front, but |
| 67 | 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] | 68 | |
| 69 | Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set |
| 70 | it to 0. This tells depot_tools to use your locally installed version of Visual |
| 71 | Studio (by default, depot_tools will try to use a google-internal version). |
| 72 | |
| 73 | From a cmd.exe shell, run the command gclient (without arguments). On first |
| 74 | run, gclient will install all the Windows-specific bits needed to work with |
| 75 | the code, including msysgit and python. |
| 76 | |
| 77 | * If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell), |
| 78 | it may appear to run properly, but msysgit, python, and other tools |
| 79 | may not get installed correctly. |
| 80 | * If you see strange errors with the file system on the first run of gclient, |
| 81 | you may want to [disable Windows Indexing](http://tortoisesvn.tigris.org/faq.html#cantmove2). |
| 82 | |
Bruce Dawson | 4d1de59 | 2017-09-08 00:24:00 | [diff] [blame] | 83 | After running gclient open a command prompt and type `where python` and |
| 84 | confirm that the depot_tools `python.bat` comes ahead of any copies of |
| 85 | python.exe. Failing to ensure this can lead to overbuilding when |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 86 | using gn - see [crbug.com/611087](https://crbug.com/611087). |
| 87 | |
| 88 | ## Get the code |
| 89 | |
Leonard Mosescu | 718c9ac | 2017-06-20 18:06:32 | [diff] [blame] | 90 | First, configure Git: |
| 91 | |
| 92 | ```shell |
| 93 | $ git config --global user.name "My Name" |
| 94 | $ git config --global user.email "[email protected]" |
| 95 | $ git config --global core.autocrlf false |
| 96 | $ git config --global core.filemode false |
| 97 | $ git config --global branch.autosetuprebase always |
| 98 | ``` |
| 99 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 100 | Create a `chromium` directory for the checkout and change to it (you can call |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 101 | this whatever you like and put it wherever you like, as |
| 102 | long as the full path has no spaces): |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 103 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 104 | ```shell |
| 105 | $ mkdir chromium && cd chromium |
| 106 | ``` |
| 107 | |
| 108 | Run the `fetch` tool from `depot_tools` to check out the code and its |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 109 | dependencies. |
| 110 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 111 | ```shell |
xiaoyin.l | 802e4b3e | 2016-12-04 22:17:30 | [diff] [blame] | 112 | $ fetch chromium |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 113 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 114 | |
| 115 | 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] | 116 | adding the `--no-history` flag to `fetch`. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 117 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 118 | Expect the command to take 30 minutes on even a fast connection, and many |
| 119 | hours on slower ones. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 120 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 121 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 122 | directory called `src` in the working directory. The remaining instructions |
| 123 | assume you have switched to the `src` directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 124 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 125 | ```shell |
| 126 | $ cd src |
| 127 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 128 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 129 | *Optional*: You can also [install API |
| 130 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 131 | build to talk to some Google services, but this is not necessary for most |
| 132 | development and testing purposes. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 133 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 134 | ## Setting up the build |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 135 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 136 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along |
| 137 | with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja` |
| 138 | files. You can create any number of *build directories* with different |
| 139 | configurations. To create a build directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 140 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 141 | ```shell |
| 142 | $ gn gen out/Default |
| 143 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 144 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 145 | * You only have to run this once for each new build directory, Ninja will |
| 146 | update the build files as needed. |
| 147 | * You can replace `Default` with another name, but |
| 148 | it should be a subdirectory of `out`. |
| 149 | * For other build arguments, including release settings, see [GN build |
| 150 | configuration](https://www.chromium.org/developers/gn-build-configuration). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 151 | The default will be a debug component build matching the current host |
| 152 | operating system and CPU. |
| 153 | * For more info on GN, run `gn help` on the command line or read the |
| 154 | [quick start guide](../tools/gn/docs/quick_start.md). |
| 155 | |
| 156 | ### Using the Visual Studio IDE |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 157 | |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 158 | If you want to use the Visual Studio IDE, use the `--ide` command line |
| 159 | argument to `gn gen` when you generate your output directory (as described on |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 160 | the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code) |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 161 | page): |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 162 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 163 | ```shell |
| 164 | $ gn gen --ide=vs out\Default |
| 165 | $ devenv out\Default\all.sln |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 166 | ``` |
| 167 | |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 168 | GN will produce a file `all.sln` in your build directory. It will internally |
| 169 | use Ninja to compile while still allowing most IDE functions to work (there is |
| 170 | no native Visual Studio compilation mode). If you manually run "gen" again you |
| 171 | will need to resupply this argument, but normally GN will keep the build and |
thakis | 3e861de | 2016-06-14 14:24:01 | [diff] [blame] | 172 | IDE files up to date automatically when you build. |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 173 | |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 174 | The generated solution will contain several thousand projects and will be very |
| 175 | slow to load. Use the `--filters` argument to restrict generating project files |
| 176 | for only the code you're interested in, although this will also limit what |
| 177 | files appear in the project explorer. A minimal solution that will let you |
| 178 | compile and run Chrome in the IDE but will not show any source files is: |
| 179 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 180 | ``` |
| 181 | $ gn gen --ide=vs --filters=//chrome out\Default |
| 182 | ``` |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 183 | |
| 184 | There are other options for controlling how the solution is generated, run `gn |
| 185 | help gen` for the current documentation. |
| 186 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 187 | ### Faster builds |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 188 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 189 | * Reduce file system overhead by excluding build directories from |
| 190 | antivirus and indexing software. |
| 191 | * Store the build tree on a fast disk (preferably SSD). |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 192 | * The more cores the better (20+ is not excessive) and lots of RAM is needed |
| 193 | (64 GB is not excessive). |
tfarina | 502f388 | 2016-03-23 12:48:10 | [diff] [blame] | 194 | |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 195 | There are some gn flags that can improve build speeds. You can specify these |
| 196 | in the editor that appears when you create your output directory |
| 197 | (`gn args out/Default`) or on the gn gen command line |
| 198 | (`gn gen out/Default --args="is_component_build = true is_debug = true"`). |
| 199 | Some helpful settings to consider using include: |
Bruce Dawson | fcd3deb1 | 2017-07-28 17:12:20 | [diff] [blame] | 200 | * `use_jumbo_build = true` - *Experimental* [Jumbo/unity](jumbo.md) builds. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 201 | * `is_component_build = true` - this uses more, smaller DLLs, and incremental |
| 202 | linking. |
Bruce Dawson | fcd3deb1 | 2017-07-28 17:12:20 | [diff] [blame] | 203 | * `enable_nacl = false` - this disables Native Client which is usually not |
| 204 | needed for local builds. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 205 | * `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and |
| 206 | support incremental linking for more targets. Note that if you set this but |
Bruce Dawson | fcd3deb1 | 2017-07-28 17:12:20 | [diff] [blame] | 207 | don't' set enable_nacl = false then build times may get worse. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 208 | * `remove_webcore_debug_symbols = true` - turn off source-level debugging for |
| 209 | blink to reduce build times, appropriate if you don't plan to debug blink. |
brucedawson | cfc7fd5 | 2017-07-06 18:41:01 | [diff] [blame] | 210 | * `win_linker_timing = true` - this should not generally be set but can be |
| 211 | helpful when trying to understand build times or incremental linking failures. |
| 212 | |
| 213 | In addition, Google employees should consider using goma, a distributed |
| 214 | compilation system. Detailed information is available internally but the |
| 215 | relevant gn args are: |
| 216 | * `use_goma = true` |
| 217 | * `symbol_level = 2` - by default goma builds change symbol_level from 2 to 1 |
| 218 | which disables source-level debugging. This turns it back on. This actually |
| 219 | makes builds slower, but it makes goma more usable. |
| 220 | * `is_win_fastlink = true` - this is required if you have goma enabled and |
| 221 | symbol_level set to 2. |
| 222 | |
| 223 | Note that debugging of is_win_fastlink built binaries is unreliable prior to |
| 224 | VS 2017 Update 3 and may crash Visual Studio. |
| 225 | |
| 226 | To get any benefit from goma it is important to pass a large -j value to ninja. |
| 227 | A good default is 10\*numCores to 20\*numCores. If you run autoninja.bat then it |
| 228 | will pass an appropriate -j value to ninja for goma or not, automatically. |
| 229 | |
| 230 | When invoking ninja specify 'chrome' as the target to avoid building all test |
| 231 | binaries as well. |
| 232 | |
| 233 | Still, builds will take many hours on many machines. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 234 | |
| 235 | ## Build Chromium |
| 236 | |
| 237 | Build Chromium (the "chrome" target) with Ninja using the command: |
| 238 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 239 | ```shell |
| 240 | $ ninja -C out\Default chrome |
| 241 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 242 | |
| 243 | You can get a list of all of the other build targets from GN by running |
| 244 | `gn ls out/Default` from the command line. To compile one, pass to Ninja |
| 245 | the GN label with no preceding "//" (so for `//chrome/test:unit_tests` |
| 246 | use ninja -C out/Default chrome/test:unit_tests`). |
| 247 | |
| 248 | ## Run Chromium |
| 249 | |
| 250 | Once it is built, you can simply run the browser: |
| 251 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 252 | ```shell |
| 253 | $ out\Default\chrome.exe |
| 254 | ``` |
| 255 | |
| 256 | (The ".exe" suffix in the command is actually optional). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 257 | |
| 258 | ## Running test targets |
| 259 | |
| 260 | You can run the tests in the same way. You can also limit which tests are |
| 261 | run using the `--gtest_filter` arg, e.g.: |
| 262 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 263 | ```shell |
| 264 | $ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*" |
| 265 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 266 | |
| 267 | You can find out more about GoogleTest at its |
| 268 | [GitHub page](https://github.com/google/googletest). |
| 269 | |
| 270 | ## Update your checkout |
| 271 | |
| 272 | To update an existing checkout, you can run |
| 273 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 274 | ```shell |
| 275 | $ git rebase-update |
| 276 | $ gclient sync |
| 277 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 278 | |
| 279 | The first command updates the primary Chromium source repository and rebases |
| 280 | 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] | 281 | 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] | 282 | other common Git commands to update the repo. |
| 283 | |
| 284 | The second command syncs the subrepositories to the appropriate versions and |
| 285 | re-runs the hooks as needed. |