blob: 5350c0edb8fb590416610c81c326d543914cb974 [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
Bruce Dawsone42d7642018-12-10 23:50:0026As of September, 2017 (R503915) Chromium requires Visual Studio 2017 (15.7.2 or
27higher) to build. The clang-cl compiler is used but Visual Studio's header
28files, libraries, and some tools are required. Visual Studio Community Edition
29should work if its license is appropriate for you. You must install the "Desktop
Bruce Dawsone9f20fff2018-03-03 01:58:3830development with C++" component and the "MFC and ATL support" sub-component.
31This can be done from the command line by passing these arguments to the Visual
Bruce Dawsone42d7642018-12-10 23:50:0032Studio installer that you download (see below for ARM64 instructions):
Bruce Dawson1c0979a62017-09-13 17:47:2133```shell
Bruce Dawsone42d7642018-12-10 23:50:0034$ PATH_TO_INSTALLER.EXE ^
35--add Microsoft.VisualStudio.Workload.NativeDesktop ^
36--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
37--includeRecommended
Bruce Dawson1c0979a62017-09-13 17:47:2138```
pwnall43b43ba2016-08-22 19:29:2939
Bruce Dawsone42d7642018-12-10 23:50:0040If you want to build for ARM64 Win32 then some extra arguments are needed. The
41full set for that case is:
42```shell
43$ PATH_TO_INSTALLER.EXE ^
44--add Microsoft.VisualStudio.Workload.NativeDesktop ^
45--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
46--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^
47--add Microsoft.VisualStudio.Component.VC.MFC.ARM64 ^
48--includeRecommended
49```
50
51You must have the version 10.0.17134 or higher Windows 10 SDK installed. This
52can be installed separately or by checking the appropriate box in the Visual
53Studio Installer.
Bruce Dawsone9f20fff2018-03-03 01:58:3854
55The SDK Debugging Tools must also be installed. If the Windows 10 SDK was
56installed via the Visual Studio installer, then they can be installed by going
57to: Control Panel → Programs → Programs and Features → Select the "Windows
58Software Development Kit" → Change → Change → Check "Debugging Tools For
59Windows" → Change. Or, you can download the standalone SDK installer and use it
60to install the Debugging Tools.
Robert Sesekc8ffa1b2017-08-04 19:55:2261
dpranke0ae7cad2016-11-30 07:47:5862## Install `depot_tools`
tfarina502f3882016-03-23 12:48:1063
dpranke1a70d0c2016-12-01 02:42:2964Download the [depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
dpranke0ae7cad2016-11-30 07:47:5865and extract it somewhere.
tfarina502f3882016-03-23 12:48:1066
dpranke0ae7cad2016-11-30 07:47:5867*** note
68**Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer,
69this will not extract the hidden “.git” folder which is necessary for
Bruce Dawson4d1de592017-09-08 00:24:0070depot_tools to autoupdate itself. You can use “Extract all…” from the
dpranke0ae7cad2016-11-30 07:47:5871context menu though.
72***
tfarina502f3882016-03-23 12:48:1073
Bruce Dawson4d1de592017-09-08 00:24:0074Add depot_tools to the start of your PATH (must be ahead of any installs of
dpranke4b470c5b2017-01-19 17:38:0475Python). Assuming you unzipped the bundle to C:\src\depot_tools, open:
tfarina502f3882016-03-23 12:48:1076
dpranke0ae7cad2016-11-30 07:47:5877Control Panel → System and Security → System → Advanced system settings
tfarina502f3882016-03-23 12:48:1078
dpranke4b470c5b2017-01-19 17:38:0479If you have Administrator access, Modify the PATH system variable and
80put `C:\src\depot_tools` at the front (or at least in front of any directory
81that might already have a copy of Python or Git).
tfarina502f3882016-03-23 12:48:1082
dpranke4b470c5b2017-01-19 17:38:0483If you don't have Administrator access, you can add a user-level PATH
84environment variable and put `C:\src\depot_tools` at the front, but
85if your system PATH has a Python in it, you will be out of luck.
dpranke0ae7cad2016-11-30 07:47:5886
87Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set
88it to 0. This tells depot_tools to use your locally installed version of Visual
89Studio (by default, depot_tools will try to use a google-internal version).
90
91From a cmd.exe shell, run the command gclient (without arguments). On first
92run, gclient will install all the Windows-specific bits needed to work with
93the code, including msysgit and python.
94
95* If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell),
96 it may appear to run properly, but msysgit, python, and other tools
97 may not get installed correctly.
98* If you see strange errors with the file system on the first run of gclient,
99 you may want to [disable Windows Indexing](http://tortoisesvn.tigris.org/faq.html#cantmove2).
100
Bruce Dawson4d1de592017-09-08 00:24:00101After running gclient open a command prompt and type `where python` and
102confirm that the depot_tools `python.bat` comes ahead of any copies of
103python.exe. Failing to ensure this can lead to overbuilding when
dpranke0ae7cad2016-11-30 07:47:58104using gn - see [crbug.com/611087](https://crbug.com/611087).
105
106## Get the code
107
Leonard Mosescu718c9ac2017-06-20 18:06:32108First, configure Git:
109
110```shell
111$ git config --global user.name "My Name"
112$ git config --global user.email "[email protected]"
113$ git config --global core.autocrlf false
114$ git config --global core.filemode false
115$ git config --global branch.autosetuprebase always
116```
117
sdy93387fa2016-12-01 01:03:44118Create a `chromium` directory for the checkout and change to it (you can call
dpranke0ae7cad2016-11-30 07:47:58119this whatever you like and put it wherever you like, as
120long as the full path has no spaces):
dpranke0ae7cad2016-11-30 07:47:58121
sdy93387fa2016-12-01 01:03:44122```shell
123$ mkdir chromium && cd chromium
124```
125
126Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:58127dependencies.
128
sdy93387fa2016-12-01 01:03:44129```shell
xiaoyin.l802e4b3e2016-12-04 22:17:30130$ fetch chromium
sdy93387fa2016-12-01 01:03:44131```
dpranke0ae7cad2016-11-30 07:47:58132
133If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:44134adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:58135
sdy93387fa2016-12-01 01:03:44136Expect the command to take 30 minutes on even a fast connection, and many
137hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:58138
sdy93387fa2016-12-01 01:03:44139When `fetch` completes, it will have created a hidden `.gclient` file and a
140directory called `src` in the working directory. The remaining instructions
141assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:58142
sdy93387fa2016-12-01 01:03:44143```shell
144$ cd src
145```
dpranke0ae7cad2016-11-30 07:47:58146
sdy93387fa2016-12-01 01:03:44147*Optional*: You can also [install API
148keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
149build to talk to some Google services, but this is not necessary for most
150development and testing purposes.
dpranke0ae7cad2016-11-30 07:47:58151
dpranke1a70d0c2016-12-01 02:42:29152## Setting up the build
dpranke0ae7cad2016-11-30 07:47:58153
Tom Bridgwatereef401542018-08-17 00:54:43154Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
155a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
156to generate `.ninja` files. You can create any number of *build directories*
157with different configurations. To create a build directory:
dpranke0ae7cad2016-11-30 07:47:58158
sdy93387fa2016-12-01 01:03:44159```shell
160$ gn gen out/Default
161```
dpranke0ae7cad2016-11-30 07:47:58162
sdy93387fa2016-12-01 01:03:44163* You only have to run this once for each new build directory, Ninja will
164 update the build files as needed.
165* You can replace `Default` with another name, but
166 it should be a subdirectory of `out`.
167* For other build arguments, including release settings, see [GN build
168 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58169 The default will be a debug component build matching the current host
170 operating system and CPU.
Tom Bridgwatereef401542018-08-17 00:54:43171* For more info on GN, run `gn help` on the command line or read the [quick
172 start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md).
dpranke0ae7cad2016-11-30 07:47:58173
174### Using the Visual Studio IDE
tfarina502f3882016-03-23 12:48:10175
brettwc25693b32016-05-26 01:11:52176If you want to use the Visual Studio IDE, use the `--ide` command line
177argument to `gn gen` when you generate your output directory (as described on
xiaoyin.l1003c0b2016-12-06 02:51:17178the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code)
brettwc25693b32016-05-26 01:11:52179page):
tfarina502f3882016-03-23 12:48:10180
dpranke1a70d0c2016-12-01 02:42:29181```shell
182$ gn gen --ide=vs out\Default
183$ devenv out\Default\all.sln
tfarina502f3882016-03-23 12:48:10184```
185
brettwc25693b32016-05-26 01:11:52186GN will produce a file `all.sln` in your build directory. It will internally
187use Ninja to compile while still allowing most IDE functions to work (there is
188no native Visual Studio compilation mode). If you manually run "gen" again you
189will need to resupply this argument, but normally GN will keep the build and
thakis3e861de2016-06-14 14:24:01190IDE files up to date automatically when you build.
tfarina502f3882016-03-23 12:48:10191
brettwc25693b32016-05-26 01:11:52192The generated solution will contain several thousand projects and will be very
193slow to load. Use the `--filters` argument to restrict generating project files
James Darpiniandde42b52018-04-05 23:06:56194for only the code you're interested in. Although this will also limit what
195files appear in the project explorer, debugging will still work and you can
196set breakpoints in files that you open manually. A minimal solution that will
197let you compile and run Chrome in the IDE but will not show any source files
198is:
brettwc25693b32016-05-26 01:11:52199
dpranke1a70d0c2016-12-01 02:42:29200```
James Darpiniandde42b52018-04-05 23:06:56201$ gn gen --ide=vs --filters=//chrome --no-deps out\Default
dpranke1a70d0c2016-12-01 02:42:29202```
brettwc25693b32016-05-26 01:11:52203
James Darpiniandde42b52018-04-05 23:06:56204You can selectively add other directories you care about to the filter like so:
205`--filters=//chrome;//third_party/WebKit/*;//gpu/*`.
206
brettwc25693b32016-05-26 01:11:52207There are other options for controlling how the solution is generated, run `gn
208help gen` for the current documentation.
209
James Darpiniandde42b52018-04-05 23:06:56210By default when you start debugging in Visual Studio the debugger will only
211attach to the main browser process. To debug all of Chrome, install
212[Microsoft's Child Process Debugging Power Tool](https://blogs.msdn.microsoft.com/devops/2014/11/24/introducing-the-child-process-debugging-power-tool/).
213You will also need to run Visual Studio as administrator, or it will silently
214fail to attach to some of Chrome's child processes.
215
216It is also possible to debug and develop Chrome in Visual Studio without a
217solution file. Simply "open" your chrome.exe binary with
218`File->Open->Project/Solution`, or from a Visual Studio command prompt like
219so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual
220Studio's code editing features will not work in this configuration, but by
221installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/)
222you can get the source code to appear in the solution explorer window along
223with other useful features such as code search.
224
dpranke0ae7cad2016-11-30 07:47:58225### Faster builds
tfarina502f3882016-03-23 12:48:10226
dpranke0ae7cad2016-11-30 07:47:58227* Reduce file system overhead by excluding build directories from
228 antivirus and indexing software.
229* Store the build tree on a fast disk (preferably SSD).
brucedawsoncfc7fd52017-07-06 18:41:01230* The more cores the better (20+ is not excessive) and lots of RAM is needed
231(64 GB is not excessive).
tfarina502f3882016-03-23 12:48:10232
brucedawsoncfc7fd52017-07-06 18:41:01233There are some gn flags that can improve build speeds. You can specify these
234in the editor that appears when you create your output directory
235(`gn args out/Default`) or on the gn gen command line
236(`gn gen out/Default --args="is_component_build = true is_debug = true"`).
237Some helpful settings to consider using include:
Daniel Bratell5a5292e2018-11-19 09:58:32238* `use_jumbo_build = true` - [Jumbo/unity](jumbo.md) builds.
brucedawsoncfc7fd52017-07-06 18:41:01239* `is_component_build = true` - this uses more, smaller DLLs, and incremental
240linking.
Bruce Dawsonfcd3deb12017-07-28 17:12:20241* `enable_nacl = false` - this disables Native Client which is usually not
242needed for local builds.
brucedawsoncfc7fd52017-07-06 18:41:01243* `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and
244support incremental linking for more targets. Note that if you set this but
Bruce Dawsonfcd3deb12017-07-28 17:12:20245don't' set enable_nacl = false then build times may get worse.
brucedawsoncfc7fd52017-07-06 18:41:01246* `remove_webcore_debug_symbols = true` - turn off source-level debugging for
247blink to reduce build times, appropriate if you don't plan to debug blink.
brucedawsoncfc7fd52017-07-06 18:41:01248
Bruce Dawson7ff1fe932018-06-14 19:57:12249In order to speed up linking you can set `symbol_level = 1` - this option
250reduces the work the linker has to do but when this option is set you cannot do
251source-level debugging. Switching from `symbol_level = 2` (the default) to
252`symbol_level = 1` requires recompiling everything.
brucedawsoncfc7fd52017-07-06 18:41:01253
Bruce Dawsone9f20fff2018-03-03 01:58:38254In addition, Google employees should use goma, a distributed compilation system.
255Detailed information is available internally but the relevant gn arg is:
256* `use_goma = true`
brucedawsoncfc7fd52017-07-06 18:41:01257
258To get any benefit from goma it is important to pass a large -j value to ninja.
Bruce Dawsone9f20fff2018-03-03 01:58:38259A good default is 10\*numCores to 20\*numCores. If you run autoninja then it
260will automatically pass an appropriate -j value to ninja for goma or not.
261
262```shell
263$ autoninja -C out\Default chrome
264```
brucedawsoncfc7fd52017-07-06 18:41:01265
266When invoking ninja specify 'chrome' as the target to avoid building all test
267binaries as well.
268
269Still, builds will take many hours on many machines.
dpranke0ae7cad2016-11-30 07:47:58270
Bruce Dawsone9f20fff2018-03-03 01:58:38271### Why is my build slow?
272
273Many things can make builds slow, with Windows Defender slowing process startups
274being a frequent culprit. Have you ensured that the entire Chromium src
Bruce Dawson0bbe2d42018-03-06 19:45:55275directory is excluded from antivirus scanning (on Google machines this means
Bruce Dawsone9f20fff2018-03-03 01:58:38276putting it in a ``src`` directory in the root of a drive)? Have you tried the
277different settings listed above, including different link settings and -j
278values? Have you asked on the chromium-dev mailing list to see if your build is
279slower than expected for your machine's specifications?
280
281The next step is to gather some data. There are several options. Setting
282[NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables) lets
283you configure Ninja's output so that, for instance, you can see how many
284processes are running at any given time, how long the build has been running,
285etc., as shown here:
286
287```shell
288$ set NINJA_STATUS=[%r processes, %f/%t @ %o/s : %es ]
289$ autoninja -C out\Default base
290ninja: Entering directory `out\Default'
291[1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb
292```
293
294In addition, if you set the ``NINJA_SUMMARIZE_BUILD`` environment variable to 1 then
295autoninja will print a build performance summary when the build completes,
296showing the slowest build steps and build-step types, as shown here:
297
298```shell
299$ set NINJA_SUMMARIZE_BUILD=1
300$ autoninja -C out\Default base
301 Longest build steps:
302...
303 1.2 weighted s to build base.dll, base.dll.lib, base.dll.pdb (1.2 s CPU time)
304 8.5 weighted s to build obj/base/base/base_jumbo_38.obj (30.1 s CPU time)
305 Time by build-step type:
306...
307 1.2 s weighted time to generate 1 PEFile (linking) files (1.2 s CPU time)
308 30.3 s weighted time to generate 45 .obj files (688.8 s CPU time)
309 31.8 s weighted time (693.8 s CPU time, 21.8x parallelism)
310 86 build steps completed, average of 2.71/s
311```
312
Bruce Dawson0bbe2d42018-03-06 19:45:55313You can also generate these reports by manually running the script after a build:
314
315```shell
316$ python depot_tools\post_build_ninja_summary.py -C out\Default
317```
318
Bruce Dawsone9f20fff2018-03-03 01:58:38319You can also get a visual report of the build performance with
320[ninjatracing](https://github.com/nico/ninjatracing). This converts the
321.ninja_log file into a .json file which can be loaded into chrome://tracing:
322
323```shell
324$ python ninjatracing out\Default\.ninja_log >build.json
325```
326
327Finally, Ninja can report on its own overhead which can be helpful if, for
Bruce Dawson0bbe2d42018-03-06 19:45:55328instance, process creation is making builds slow, perhaps due to antivirus
Bruce Dawsone9f20fff2018-03-03 01:58:38329interference due to clang-cl not being in an excluded directory:
330
331```shell
332$ autoninja -d stats -C out\Default base
333metric count avg (us) total (ms)
334.ninja parse 3555 1539.4 5472.6
335canonicalize str 1383032 0.0 12.7
336canonicalize path 1402349 0.0 11.2
337lookup node 1398245 0.0 8.1
338.ninja_log load 2 118.0 0.2
339.ninja_deps load 2 67.5 0.1
340node stat 2516 29.6 74.4
341depfile load 2 1132.0 2.3
342StartEdge 88 3508.1 308.7
343FinishCommand 87 1670.9 145.4
344CLParser::Parse 45 1889.1 85.0
345```
346
dpranke0ae7cad2016-11-30 07:47:58347## Build Chromium
348
Max Morozf5b31fcd2018-08-10 21:55:48349Build Chromium (the "chrome" target) with Ninja using the command:
dpranke0ae7cad2016-11-30 07:47:58350
dpranke1a70d0c2016-12-01 02:42:29351```shell
Max Morozf5b31fcd2018-08-10 21:55:48352$ autoninja -C out\Default chrome
dpranke1a70d0c2016-12-01 02:42:29353```
dpranke0ae7cad2016-11-30 07:47:58354
Max Morozf5b31fcd2018-08-10 21:55:48355`autoninja` is a wrapper that automatically provides optimal values for the
356arguments passed to `ninja`.
357
dpranke0ae7cad2016-11-30 07:47:58358You can get a list of all of the other build targets from GN by running
359`gn ls out/Default` from the command line. To compile one, pass to Ninja
360the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
361use ninja -C out/Default chrome/test:unit_tests`).
362
363## Run Chromium
364
365Once it is built, you can simply run the browser:
366
dpranke1a70d0c2016-12-01 02:42:29367```shell
368$ out\Default\chrome.exe
369```
370
371(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58372
373## Running test targets
374
375You can run the tests in the same way. You can also limit which tests are
376run using the `--gtest_filter` arg, e.g.:
377
dpranke1a70d0c2016-12-01 02:42:29378```shell
379$ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*"
380```
dpranke0ae7cad2016-11-30 07:47:58381
382You can find out more about GoogleTest at its
383[GitHub page](https://github.com/google/googletest).
384
385## Update your checkout
386
387To update an existing checkout, you can run
388
dpranke1a70d0c2016-12-01 02:42:29389```shell
390$ git rebase-update
391$ gclient sync
392```
dpranke0ae7cad2016-11-30 07:47:58393
394The first command updates the primary Chromium source repository and rebases
395any of your local branches on top of tip-of-tree (aka the Git branch `origin/master`).
Bruce Dawson4d1de592017-09-08 00:24:00396If you don't want to use this script, you can also just use `git pull` or
dpranke0ae7cad2016-11-30 07:47:58397other common Git commands to update the repo.
398
399The second command syncs the subrepositories to the appropriate versions and
400re-runs the hooks as needed.