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