blob: f7741e62f52869dc9bc06e860589f905061a0fff [file] [log] [blame] [view]
dpranke1a70d0c2016-12-01 02:42:291# Checking out and Building Chromium for Windows
2
Bruce Dawson4d1de592017-09-08 00:24:003There are instructions for other platforms linked from the
dpranke1a70d0c2016-12-01 02:42:294[get the code](get_the_code.md) page.
tfarina502f3882016-03-23 12:48:105
dpranke1a70d0c2016-12-01 02:42:296## Instructions for Google Employees
7
8Are you a Google employee? See
scottmg292538ae2017-01-12 00:10:559[go/building-chrome-win](https://goto.google.com/building-chrome-win) instead.
dpranke0ae7cad2016-11-30 07:47:5810
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.
dpranke4b470c5b2017-01-19 17:38:0417* 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 Dawson97367b72017-10-18 00:47:4919* An appropriate version of Visual Studio, as described below.
dpranke0ae7cad2016-11-30 07:47:5820* Windows 7 or newer.
brettwc25693b32016-05-26 01:11:5221
tfarina502f3882016-03-23 12:48:1022## Setting up Windows
23
dpranke0ae7cad2016-11-30 07:47:5824### Visual Studio
tfarina502f3882016-03-23 12:48:1025
Raul Tambre1bb5c1a2018-12-29 00:57:1226Chromium requires Visual Studio 2017 (>=15.7.2) or 2019 (>=16.0.0) to build.
Bruce Dawsonfa551102019-06-11 23:50:0427Visual Studio can also be used to debug Chromium and Visual Studio 2019 is
28preferred for this as it handles Chromium's large debug information much better.
Raul Tambre1bb5c1a2018-12-29 00:57:1229The clang-cl compiler is used but Visual Studio's header files, libraries, and
30some tools are required. Visual Studio Community Edition should work if its
31license is appropriate for you. You must install the "Desktop development with
32C++" component and the "MFC/ATL support" sub-components. This can be done from
33the command line by passing these arguments to the Visual Studio installer (see
34below for ARM64 instructions):
Bruce Dawson1c0979a62017-09-13 17:47:2135```shell
Bruce Dawsone42d7642018-12-10 23:50:0036$ PATH_TO_INSTALLER.EXE ^
37--add Microsoft.VisualStudio.Workload.NativeDesktop ^
38--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
39--includeRecommended
Bruce Dawson1c0979a62017-09-13 17:47:2140```
pwnall43b43ba2016-08-22 19:29:2941
Bruce Dawsone42d7642018-12-10 23:50:0042If you want to build for ARM64 Win32 then some extra arguments are needed. The
43full 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
Bruce Dawson7222f5cf2019-04-25 17:40:4153You must have the version 10.0.17763 or higher Windows 10 SDK installed. This
Bruce Dawsone42d7642018-12-10 23:50:0054can be installed separately or by checking the appropriate box in the Visual
55Studio Installer.
Bruce Dawsone9f20fff2018-03-03 01:58:3856
57The SDK Debugging Tools must also be installed. If the Windows 10 SDK was
58installed via the Visual Studio installer, then they can be installed by going
59to: Control Panel → Programs → Programs and Features → Select the "Windows
60Software Development Kit" → Change → Change → Check "Debugging Tools For
61Windows" → Change. Or, you can download the standalone SDK installer and use it
62to install the Debugging Tools.
Robert Sesekc8ffa1b2017-08-04 19:55:2263
dpranke0ae7cad2016-11-30 07:47:5864## Install `depot_tools`
tfarina502f3882016-03-23 12:48:1065
dpranke1a70d0c2016-12-01 02:42:2966Download the [depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
dpranke0ae7cad2016-11-30 07:47:5867and extract it somewhere.
tfarina502f3882016-03-23 12:48:1068
dpranke0ae7cad2016-11-30 07:47:5869*** note
70**Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer,
71this will not extract the hidden “.git” folder which is necessary for
Bruce Dawson4d1de592017-09-08 00:24:0072depot_tools to autoupdate itself. You can use “Extract all…” from the
dpranke0ae7cad2016-11-30 07:47:5873context menu though.
74***
tfarina502f3882016-03-23 12:48:1075
Bruce Dawson4d1de592017-09-08 00:24:0076Add depot_tools to the start of your PATH (must be ahead of any installs of
dpranke4b470c5b2017-01-19 17:38:0477Python). Assuming you unzipped the bundle to C:\src\depot_tools, open:
tfarina502f3882016-03-23 12:48:1078
dpranke0ae7cad2016-11-30 07:47:5879Control Panel → System and Security → System → Advanced system settings
tfarina502f3882016-03-23 12:48:1080
dpranke4b470c5b2017-01-19 17:38:0481If you have Administrator access, Modify the PATH system variable and
82put `C:\src\depot_tools` at the front (or at least in front of any directory
83that might already have a copy of Python or Git).
tfarina502f3882016-03-23 12:48:1084
dpranke4b470c5b2017-01-19 17:38:0485If you don't have Administrator access, you can add a user-level PATH
86environment variable and put `C:\src\depot_tools` at the front, but
87if your system PATH has a Python in it, you will be out of luck.
dpranke0ae7cad2016-11-30 07:47:5888
89Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set
90it to 0. This tells depot_tools to use your locally installed version of Visual
Bruce Dawsonfa551102019-06-11 23:50:0491Studio (by default, depot_tools will try to use a google-internal version). If
92you want to build with Visual Studio 2019 instead of Visual Studio 2017 (the
93default) then set the GYP_MSVS_VERSION environment variable to 2019.
dpranke0ae7cad2016-11-30 07:47:5894
95From a cmd.exe shell, run the command gclient (without arguments). On first
96run, gclient will install all the Windows-specific bits needed to work with
97the 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 Dawson4d1de592017-09-08 00:24:00105After running gclient open a command prompt and type `where python` and
106confirm that the depot_tools `python.bat` comes ahead of any copies of
107python.exe. Failing to ensure this can lead to overbuilding when
dpranke0ae7cad2016-11-30 07:47:58108using gn - see [crbug.com/611087](https://crbug.com/611087).
109
110## Get the code
111
Leonard Mosescu718c9ac2017-06-20 18:06:32112First, 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
sdy93387fa2016-12-01 01:03:44122Create a `chromium` directory for the checkout and change to it (you can call
dpranke0ae7cad2016-11-30 07:47:58123this whatever you like and put it wherever you like, as
124long as the full path has no spaces):
dpranke0ae7cad2016-11-30 07:47:58125
sdy93387fa2016-12-01 01:03:44126```shell
127$ mkdir chromium && cd chromium
128```
129
130Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:58131dependencies.
132
sdy93387fa2016-12-01 01:03:44133```shell
xiaoyin.l802e4b3e2016-12-04 22:17:30134$ fetch chromium
sdy93387fa2016-12-01 01:03:44135```
dpranke0ae7cad2016-11-30 07:47:58136
137If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:44138adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:58139
sdy93387fa2016-12-01 01:03:44140Expect the command to take 30 minutes on even a fast connection, and many
141hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:58142
sdy93387fa2016-12-01 01:03:44143When `fetch` completes, it will have created a hidden `.gclient` file and a
144directory called `src` in the working directory. The remaining instructions
145assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:58146
sdy93387fa2016-12-01 01:03:44147```shell
148$ cd src
149```
dpranke0ae7cad2016-11-30 07:47:58150
sdy93387fa2016-12-01 01:03:44151*Optional*: You can also [install API
152keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
153build to talk to some Google services, but this is not necessary for most
154development and testing purposes.
dpranke0ae7cad2016-11-30 07:47:58155
dpranke1a70d0c2016-12-01 02:42:29156## Setting up the build
dpranke0ae7cad2016-11-30 07:47:58157
Tom Bridgwatereef401542018-08-17 00:54:43158Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
159a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
160to generate `.ninja` files. You can create any number of *build directories*
161with different configurations. To create a build directory:
dpranke0ae7cad2016-11-30 07:47:58162
sdy93387fa2016-12-01 01:03:44163```shell
164$ gn gen out/Default
165```
dpranke0ae7cad2016-11-30 07:47:58166
sdy93387fa2016-12-01 01:03:44167* 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).
dpranke0ae7cad2016-11-30 07:47:58173 The default will be a debug component build matching the current host
174 operating system and CPU.
Tom Bridgwatereef401542018-08-17 00:54:43175* 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).
dpranke0ae7cad2016-11-30 07:47:58177
178### Using the Visual Studio IDE
tfarina502f3882016-03-23 12:48:10179
brettwc25693b32016-05-26 01:11:52180If you want to use the Visual Studio IDE, use the `--ide` command line
181argument to `gn gen` when you generate your output directory (as described on
xiaoyin.l1003c0b2016-12-06 02:51:17182the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code)
brettwc25693b32016-05-26 01:11:52183page):
tfarina502f3882016-03-23 12:48:10184
dpranke1a70d0c2016-12-01 02:42:29185```shell
186$ gn gen --ide=vs out\Default
187$ devenv out\Default\all.sln
tfarina502f3882016-03-23 12:48:10188```
189
brettwc25693b32016-05-26 01:11:52190GN will produce a file `all.sln` in your build directory. It will internally
191use Ninja to compile while still allowing most IDE functions to work (there is
192no native Visual Studio compilation mode). If you manually run "gen" again you
193will need to resupply this argument, but normally GN will keep the build and
thakis3e861de2016-06-14 14:24:01194IDE files up to date automatically when you build.
tfarina502f3882016-03-23 12:48:10195
brettwc25693b32016-05-26 01:11:52196The generated solution will contain several thousand projects and will be very
197slow to load. Use the `--filters` argument to restrict generating project files
James Darpiniandde42b52018-04-05 23:06:56198for only the code you're interested in. Although this will also limit what
199files appear in the project explorer, debugging will still work and you can
200set breakpoints in files that you open manually. A minimal solution that will
201let you compile and run Chrome in the IDE but will not show any source files
202is:
brettwc25693b32016-05-26 01:11:52203
dpranke1a70d0c2016-12-01 02:42:29204```
James Darpiniandde42b52018-04-05 23:06:56205$ gn gen --ide=vs --filters=//chrome --no-deps out\Default
dpranke1a70d0c2016-12-01 02:42:29206```
brettwc25693b32016-05-26 01:11:52207
James Darpiniandde42b52018-04-05 23:06:56208You can selectively add other directories you care about to the filter like so:
209`--filters=//chrome;//third_party/WebKit/*;//gpu/*`.
210
brettwc25693b32016-05-26 01:11:52211There are other options for controlling how the solution is generated, run `gn
212help gen` for the current documentation.
213
James Darpiniandde42b52018-04-05 23:06:56214By default when you start debugging in Visual Studio the debugger will only
215attach 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/).
217You will also need to run Visual Studio as administrator, or it will silently
218fail to attach to some of Chrome's child processes.
219
220It is also possible to debug and develop Chrome in Visual Studio without a
221solution file. Simply "open" your chrome.exe binary with
222`File->Open->Project/Solution`, or from a Visual Studio command prompt like
223so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual
224Studio's code editing features will not work in this configuration, but by
225installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/)
226you can get the source code to appear in the solution explorer window along
227with other useful features such as code search.
228
dpranke0ae7cad2016-11-30 07:47:58229### Faster builds
tfarina502f3882016-03-23 12:48:10230
dpranke0ae7cad2016-11-30 07:47:58231* 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).
brucedawsoncfc7fd52017-07-06 18:41:01234* The more cores the better (20+ is not excessive) and lots of RAM is needed
235(64 GB is not excessive).
tfarina502f3882016-03-23 12:48:10236
brucedawsoncfc7fd52017-07-06 18:41:01237There are some gn flags that can improve build speeds. You can specify these
238in 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"`).
241Some helpful settings to consider using include:
Daniel Bratell5a5292e2018-11-19 09:58:32242* `use_jumbo_build = true` - [Jumbo/unity](jumbo.md) builds.
brucedawsoncfc7fd52017-07-06 18:41:01243* `is_component_build = true` - this uses more, smaller DLLs, and incremental
244linking.
Bruce Dawsonfcd3deb12017-07-28 17:12:20245* `enable_nacl = false` - this disables Native Client which is usually not
246needed for local builds.
brucedawsoncfc7fd52017-07-06 18:41:01247* `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and
248support incremental linking for more targets. Note that if you set this but
Bruce Dawsonfcd3deb12017-07-28 17:12:20249don't' set enable_nacl = false then build times may get worse.
James Cook26699a92019-03-12 22:23:10250* `blink_symbol_level = 0` - turn off source-level debugging for
brucedawsoncfc7fd52017-07-06 18:41:01251blink to reduce build times, appropriate if you don't plan to debug blink.
brucedawsoncfc7fd52017-07-06 18:41:01252
Bruce Dawson7ff1fe932018-06-14 19:57:12253In order to speed up linking you can set `symbol_level = 1` - this option
254reduces the work the linker has to do but when this option is set you cannot do
255source-level debugging. Switching from `symbol_level = 2` (the default) to
256`symbol_level = 1` requires recompiling everything.
brucedawsoncfc7fd52017-07-06 18:41:01257
Bruce Dawsone9f20fff2018-03-03 01:58:38258In addition, Google employees should use goma, a distributed compilation system.
259Detailed information is available internally but the relevant gn arg is:
260* `use_goma = true`
brucedawsoncfc7fd52017-07-06 18:41:01261
262To get any benefit from goma it is important to pass a large -j value to ninja.
Bruce Dawsone9f20fff2018-03-03 01:58:38263A good default is 10\*numCores to 20\*numCores. If you run autoninja then it
264will automatically pass an appropriate -j value to ninja for goma or not.
265
266```shell
267$ autoninja -C out\Default chrome
268```
brucedawsoncfc7fd52017-07-06 18:41:01269
270When invoking ninja specify 'chrome' as the target to avoid building all test
271binaries as well.
272
273Still, builds will take many hours on many machines.
dpranke0ae7cad2016-11-30 07:47:58274
Bruce Dawsone9f20fff2018-03-03 01:58:38275### Why is my build slow?
276
277Many things can make builds slow, with Windows Defender slowing process startups
278being a frequent culprit. Have you ensured that the entire Chromium src
Bruce Dawson0bbe2d42018-03-06 19:45:55279directory is excluded from antivirus scanning (on Google machines this means
Bruce Dawsone9f20fff2018-03-03 01:58:38280putting it in a ``src`` directory in the root of a drive)? Have you tried the
281different settings listed above, including different link settings and -j
282values? Have you asked on the chromium-dev mailing list to see if your build is
283slower than expected for your machine's specifications?
284
Bruce Dawson89390172019-05-08 09:51:18285The next step is to gather some data. If you set the ``NINJA_SUMMARIZE_BUILD``
286environment variable to 1 then ``autoninja`` will do a couple of things. First,
287it will set the [NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables)
288environment variable so that ninja will print additional information while
289building Chrome. It will show how many build processes are running at any given
290time, how many build steps have completed, how many build steps have completed
291per second, and how long the build has been running, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38292
293```shell
Bruce Dawson89390172019-05-08 09:51:18294$ set NINJA_SUMMARIZE_BUILD=1
Bruce Dawsone9f20fff2018-03-03 01:58:38295$ autoninja -C out\Default base
296ninja: Entering directory `out\Default'
297[1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb
298```
299
Bruce Dawson89390172019-05-08 09:51:18300This makes slow process creation immediately obvious and lets you tell quickly
301if a build is running more slowly than normal.
302
303In addition, setting ``NINJA_SUMMARIZE_BUILD=1`` tells ``autoninja`` to print a
304build performance summary when the build completes, showing the slowest build
305steps and slowest build-step types, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38306
307```shell
308$ set NINJA_SUMMARIZE_BUILD=1
309$ autoninja -C out\Default base
310 Longest build steps:
311...
312 1.2 weighted s to build base.dll, base.dll.lib, base.dll.pdb (1.2 s CPU time)
313 8.5 weighted s to build obj/base/base/base_jumbo_38.obj (30.1 s CPU time)
314 Time by build-step type:
315...
316 1.2 s weighted time to generate 1 PEFile (linking) files (1.2 s CPU time)
317 30.3 s weighted time to generate 45 .obj files (688.8 s CPU time)
318 31.8 s weighted time (693.8 s CPU time, 21.8x parallelism)
319 86 build steps completed, average of 2.71/s
320```
321
Bruce Dawson0bbe2d42018-03-06 19:45:55322You can also generate these reports by manually running the script after a build:
323
324```shell
325$ python depot_tools\post_build_ninja_summary.py -C out\Default
326```
327
Bruce Dawsone9f20fff2018-03-03 01:58:38328You can also get a visual report of the build performance with
329[ninjatracing](https://github.com/nico/ninjatracing). This converts the
330.ninja_log file into a .json file which can be loaded into chrome://tracing:
331
332```shell
333$ python ninjatracing out\Default\.ninja_log >build.json
334```
335
336Finally, Ninja can report on its own overhead which can be helpful if, for
Bruce Dawson0bbe2d42018-03-06 19:45:55337instance, process creation is making builds slow, perhaps due to antivirus
Bruce Dawsone9f20fff2018-03-03 01:58:38338interference due to clang-cl not being in an excluded directory:
339
340```shell
341$ autoninja -d stats -C out\Default base
342metric count avg (us) total (ms)
343.ninja parse 3555 1539.4 5472.6
344canonicalize str 1383032 0.0 12.7
345canonicalize path 1402349 0.0 11.2
346lookup node 1398245 0.0 8.1
347.ninja_log load 2 118.0 0.2
348.ninja_deps load 2 67.5 0.1
349node stat 2516 29.6 74.4
350depfile load 2 1132.0 2.3
351StartEdge 88 3508.1 308.7
352FinishCommand 87 1670.9 145.4
353CLParser::Parse 45 1889.1 85.0
354```
355
dpranke0ae7cad2016-11-30 07:47:58356## Build Chromium
357
Max Morozf5b31fcd2018-08-10 21:55:48358Build Chromium (the "chrome" target) with Ninja using the command:
dpranke0ae7cad2016-11-30 07:47:58359
dpranke1a70d0c2016-12-01 02:42:29360```shell
Max Morozf5b31fcd2018-08-10 21:55:48361$ autoninja -C out\Default chrome
dpranke1a70d0c2016-12-01 02:42:29362```
dpranke0ae7cad2016-11-30 07:47:58363
Max Morozf5b31fcd2018-08-10 21:55:48364`autoninja` is a wrapper that automatically provides optimal values for the
365arguments passed to `ninja`.
366
dpranke0ae7cad2016-11-30 07:47:58367You can get a list of all of the other build targets from GN by running
368`gn ls out/Default` from the command line. To compile one, pass to Ninja
369the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
370use ninja -C out/Default chrome/test:unit_tests`).
371
372## Run Chromium
373
374Once it is built, you can simply run the browser:
375
dpranke1a70d0c2016-12-01 02:42:29376```shell
377$ out\Default\chrome.exe
378```
379
380(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58381
382## Running test targets
383
384You can run the tests in the same way. You can also limit which tests are
385run using the `--gtest_filter` arg, e.g.:
386
dpranke1a70d0c2016-12-01 02:42:29387```shell
388$ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*"
389```
dpranke0ae7cad2016-11-30 07:47:58390
391You can find out more about GoogleTest at its
392[GitHub page](https://github.com/google/googletest).
393
394## Update your checkout
395
396To update an existing checkout, you can run
397
dpranke1a70d0c2016-12-01 02:42:29398```shell
399$ git rebase-update
400$ gclient sync
401```
dpranke0ae7cad2016-11-30 07:47:58402
403The first command updates the primary Chromium source repository and rebases
404any of your local branches on top of tip-of-tree (aka the Git branch `origin/master`).
Bruce Dawson4d1de592017-09-08 00:24:00405If you don't want to use this script, you can also just use `git pull` or
dpranke0ae7cad2016-11-30 07:47:58406other common Git commands to update the repo.
407
408The second command syncs the subrepositories to the appropriate versions and
409re-runs the hooks as needed.