blob: af4f4699f099746c100ed6f1021e385d045a9051 [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 Dawsone9f20fff2018-03-03 01:58:3826As of September, 2017 (R503915) Chromium requires Visual Studio 2017 update 3.x
27to build. The clang-cl compiler is used but Visual Studio's header files,
28libraries, and some tools are required. Visual Studio Community Edition should
29work if its license is appropriate for you. You must install the "Desktop
30development 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
32Studio installer that you download:
Bruce Dawson1c0979a62017-09-13 17:47:2133```shell
Bruce Dawson97367b72017-10-18 00:47:4934--add Microsoft.VisualStudio.Workload.NativeDesktop
Bruce Dawson1c0979a62017-09-13 17:47:2135 --add Microsoft.VisualStudio.Component.VC.ATLMFC --includeRecommended
36```
pwnall43b43ba2016-08-22 19:29:2937
Bruce Dawsone9f20fff2018-03-03 01:58:3838You must have the version 10.0.15063 Windows 10 SDK installed. This can be
39installed separately or by checking the appropriate box in the Visual Studio
40Installer.
41
42The SDK Debugging Tools must also be installed. If the Windows 10 SDK was
43installed via the Visual Studio installer, then they can be installed by going
44to: Control Panel → Programs → Programs and Features → Select the "Windows
45Software Development Kit" → Change → Change → Check "Debugging Tools For
46Windows" → Change. Or, you can download the standalone SDK installer and use it
47to install the Debugging Tools.
Robert Sesekc8ffa1b2017-08-04 19:55:2248
dpranke0ae7cad2016-11-30 07:47:5849## Install `depot_tools`
tfarina502f3882016-03-23 12:48:1050
dpranke1a70d0c2016-12-01 02:42:2951Download the [depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
dpranke0ae7cad2016-11-30 07:47:5852and extract it somewhere.
tfarina502f3882016-03-23 12:48:1053
dpranke0ae7cad2016-11-30 07:47:5854*** note
55**Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer,
56this will not extract the hidden “.git” folder which is necessary for
Bruce Dawson4d1de592017-09-08 00:24:0057depot_tools to autoupdate itself. You can use “Extract all…” from the
dpranke0ae7cad2016-11-30 07:47:5858context menu though.
59***
tfarina502f3882016-03-23 12:48:1060
Bruce Dawson4d1de592017-09-08 00:24:0061Add depot_tools to the start of your PATH (must be ahead of any installs of
dpranke4b470c5b2017-01-19 17:38:0462Python). Assuming you unzipped the bundle to C:\src\depot_tools, open:
tfarina502f3882016-03-23 12:48:1063
dpranke0ae7cad2016-11-30 07:47:5864Control Panel → System and Security → System → Advanced system settings
tfarina502f3882016-03-23 12:48:1065
dpranke4b470c5b2017-01-19 17:38:0466If you have Administrator access, Modify the PATH system variable and
67put `C:\src\depot_tools` at the front (or at least in front of any directory
68that might already have a copy of Python or Git).
tfarina502f3882016-03-23 12:48:1069
dpranke4b470c5b2017-01-19 17:38:0470If you don't have Administrator access, you can add a user-level PATH
71environment variable and put `C:\src\depot_tools` at the front, but
72if your system PATH has a Python in it, you will be out of luck.
dpranke0ae7cad2016-11-30 07:47:5873
74Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN system variable in the same way, and set
75it to 0. This tells depot_tools to use your locally installed version of Visual
76Studio (by default, depot_tools will try to use a google-internal version).
77
78From a cmd.exe shell, run the command gclient (without arguments). On first
79run, gclient will install all the Windows-specific bits needed to work with
80the code, including msysgit and python.
81
82* If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell),
83 it may appear to run properly, but msysgit, python, and other tools
84 may not get installed correctly.
85* If you see strange errors with the file system on the first run of gclient,
86 you may want to [disable Windows Indexing](http://tortoisesvn.tigris.org/faq.html#cantmove2).
87
Bruce Dawson4d1de592017-09-08 00:24:0088After running gclient open a command prompt and type `where python` and
89confirm that the depot_tools `python.bat` comes ahead of any copies of
90python.exe. Failing to ensure this can lead to overbuilding when
dpranke0ae7cad2016-11-30 07:47:5891using gn - see [crbug.com/611087](https://crbug.com/611087).
92
93## Get the code
94
Leonard Mosescu718c9ac2017-06-20 18:06:3295First, configure Git:
96
97```shell
98$ git config --global user.name "My Name"
99$ git config --global user.email "[email protected]"
100$ git config --global core.autocrlf false
101$ git config --global core.filemode false
102$ git config --global branch.autosetuprebase always
103```
104
sdy93387fa2016-12-01 01:03:44105Create a `chromium` directory for the checkout and change to it (you can call
dpranke0ae7cad2016-11-30 07:47:58106this whatever you like and put it wherever you like, as
107long as the full path has no spaces):
dpranke0ae7cad2016-11-30 07:47:58108
sdy93387fa2016-12-01 01:03:44109```shell
110$ mkdir chromium && cd chromium
111```
112
113Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:58114dependencies.
115
sdy93387fa2016-12-01 01:03:44116```shell
xiaoyin.l802e4b3e2016-12-04 22:17:30117$ fetch chromium
sdy93387fa2016-12-01 01:03:44118```
dpranke0ae7cad2016-11-30 07:47:58119
120If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:44121adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:58122
sdy93387fa2016-12-01 01:03:44123Expect the command to take 30 minutes on even a fast connection, and many
124hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:58125
sdy93387fa2016-12-01 01:03:44126When `fetch` completes, it will have created a hidden `.gclient` file and a
127directory called `src` in the working directory. The remaining instructions
128assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:58129
sdy93387fa2016-12-01 01:03:44130```shell
131$ cd src
132```
dpranke0ae7cad2016-11-30 07:47:58133
sdy93387fa2016-12-01 01:03:44134*Optional*: You can also [install API
135keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
136build to talk to some Google services, but this is not necessary for most
137development and testing purposes.
dpranke0ae7cad2016-11-30 07:47:58138
dpranke1a70d0c2016-12-01 02:42:29139## Setting up the build
dpranke0ae7cad2016-11-30 07:47:58140
sdy93387fa2016-12-01 01:03:44141Chromium uses [Ninja](https://ninja-build.org) as its main build tool along
142with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja`
143files. You can create any number of *build directories* with different
144configurations. To create a build directory:
dpranke0ae7cad2016-11-30 07:47:58145
sdy93387fa2016-12-01 01:03:44146```shell
147$ gn gen out/Default
148```
dpranke0ae7cad2016-11-30 07:47:58149
sdy93387fa2016-12-01 01:03:44150* You only have to run this once for each new build directory, Ninja will
151 update the build files as needed.
152* You can replace `Default` with another name, but
153 it should be a subdirectory of `out`.
154* For other build arguments, including release settings, see [GN build
155 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58156 The default will be a debug component build matching the current host
157 operating system and CPU.
158* For more info on GN, run `gn help` on the command line or read the
159 [quick start guide](../tools/gn/docs/quick_start.md).
160
161### Using the Visual Studio IDE
tfarina502f3882016-03-23 12:48:10162
brettwc25693b32016-05-26 01:11:52163If you want to use the Visual Studio IDE, use the `--ide` command line
164argument to `gn gen` when you generate your output directory (as described on
xiaoyin.l1003c0b2016-12-06 02:51:17165the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code)
brettwc25693b32016-05-26 01:11:52166page):
tfarina502f3882016-03-23 12:48:10167
dpranke1a70d0c2016-12-01 02:42:29168```shell
169$ gn gen --ide=vs out\Default
170$ devenv out\Default\all.sln
tfarina502f3882016-03-23 12:48:10171```
172
brettwc25693b32016-05-26 01:11:52173GN will produce a file `all.sln` in your build directory. It will internally
174use Ninja to compile while still allowing most IDE functions to work (there is
175no native Visual Studio compilation mode). If you manually run "gen" again you
176will need to resupply this argument, but normally GN will keep the build and
thakis3e861de2016-06-14 14:24:01177IDE files up to date automatically when you build.
tfarina502f3882016-03-23 12:48:10178
brettwc25693b32016-05-26 01:11:52179The generated solution will contain several thousand projects and will be very
180slow to load. Use the `--filters` argument to restrict generating project files
181for only the code you're interested in, although this will also limit what
182files appear in the project explorer. A minimal solution that will let you
183compile and run Chrome in the IDE but will not show any source files is:
184
dpranke1a70d0c2016-12-01 02:42:29185```
186$ gn gen --ide=vs --filters=//chrome out\Default
187```
brettwc25693b32016-05-26 01:11:52188
189There are other options for controlling how the solution is generated, run `gn
190help gen` for the current documentation.
191
dpranke0ae7cad2016-11-30 07:47:58192### Faster builds
tfarina502f3882016-03-23 12:48:10193
dpranke0ae7cad2016-11-30 07:47:58194* Reduce file system overhead by excluding build directories from
195 antivirus and indexing software.
196* Store the build tree on a fast disk (preferably SSD).
brucedawsoncfc7fd52017-07-06 18:41:01197* The more cores the better (20+ is not excessive) and lots of RAM is needed
198(64 GB is not excessive).
tfarina502f3882016-03-23 12:48:10199
brucedawsoncfc7fd52017-07-06 18:41:01200There are some gn flags that can improve build speeds. You can specify these
201in the editor that appears when you create your output directory
202(`gn args out/Default`) or on the gn gen command line
203(`gn gen out/Default --args="is_component_build = true is_debug = true"`).
204Some helpful settings to consider using include:
Bruce Dawsone9f20fff2018-03-03 01:58:38205* `use_jumbo_build = true` - *experimental* [Jumbo/unity](jumbo.md) builds.
brucedawsoncfc7fd52017-07-06 18:41:01206* `is_component_build = true` - this uses more, smaller DLLs, and incremental
207linking.
Bruce Dawsonfcd3deb12017-07-28 17:12:20208* `enable_nacl = false` - this disables Native Client which is usually not
209needed for local builds.
brucedawsoncfc7fd52017-07-06 18:41:01210* `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and
211support incremental linking for more targets. Note that if you set this but
Bruce Dawsonfcd3deb12017-07-28 17:12:20212don't' set enable_nacl = false then build times may get worse.
brucedawsoncfc7fd52017-07-06 18:41:01213* `remove_webcore_debug_symbols = true` - turn off source-level debugging for
214blink to reduce build times, appropriate if you don't plan to debug blink.
brucedawsoncfc7fd52017-07-06 18:41:01215
Bruce Dawsone9f20fff2018-03-03 01:58:38216In order to ensure that linking is fast enough we recommend that you use one of
217these settings - they all have tradeoffs:
218* `use_lld = true` - this linker is very fast on full links but does not support
219incremental linking.
220* `is_win_fastlink = true` - this option makes the Visual Studio linker run much
221faster, and incremental linking is supported, but it can lead to debugger
222slowdowns or out-of-memory crashes.
223* `symbol_level = 1` - this option reduces the work the linker has to do but
224when this option is set you cannot do source-level debugging.
brucedawsoncfc7fd52017-07-06 18:41:01225
Bruce Dawsone9f20fff2018-03-03 01:58:38226In addition, Google employees should use goma, a distributed compilation system.
227Detailed information is available internally but the relevant gn arg is:
228* `use_goma = true`
brucedawsoncfc7fd52017-07-06 18:41:01229
230To get any benefit from goma it is important to pass a large -j value to ninja.
Bruce Dawsone9f20fff2018-03-03 01:58:38231A good default is 10\*numCores to 20\*numCores. If you run autoninja then it
232will automatically pass an appropriate -j value to ninja for goma or not.
233
234```shell
235$ autoninja -C out\Default chrome
236```
brucedawsoncfc7fd52017-07-06 18:41:01237
238When invoking ninja specify 'chrome' as the target to avoid building all test
239binaries as well.
240
241Still, builds will take many hours on many machines.
dpranke0ae7cad2016-11-30 07:47:58242
Bruce Dawsone9f20fff2018-03-03 01:58:38243### Why is my build slow?
244
245Many things can make builds slow, with Windows Defender slowing process startups
246being a frequent culprit. Have you ensured that the entire Chromium src
247directory is excluded from anti-virus scanning (on Google machines this means
248putting it in a ``src`` directory in the root of a drive)? Have you tried the
249different settings listed above, including different link settings and -j
250values? Have you asked on the chromium-dev mailing list to see if your build is
251slower than expected for your machine's specifications?
252
253The next step is to gather some data. There are several options. Setting
254[NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables) lets
255you configure Ninja's output so that, for instance, you can see how many
256processes are running at any given time, how long the build has been running,
257etc., as shown here:
258
259```shell
260$ set NINJA_STATUS=[%r processes, %f/%t @ %o/s : %es ]
261$ autoninja -C out\Default base
262ninja: Entering directory `out\Default'
263[1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb
264```
265
266In addition, if you set the ``NINJA_SUMMARIZE_BUILD`` environment variable to 1 then
267autoninja will print a build performance summary when the build completes,
268showing the slowest build steps and build-step types, as shown here:
269
270```shell
271$ set NINJA_SUMMARIZE_BUILD=1
272$ autoninja -C out\Default base
273 Longest build steps:
274...
275 1.2 weighted s to build base.dll, base.dll.lib, base.dll.pdb (1.2 s CPU time)
276 8.5 weighted s to build obj/base/base/base_jumbo_38.obj (30.1 s CPU time)
277 Time by build-step type:
278...
279 1.2 s weighted time to generate 1 PEFile (linking) files (1.2 s CPU time)
280 30.3 s weighted time to generate 45 .obj files (688.8 s CPU time)
281 31.8 s weighted time (693.8 s CPU time, 21.8x parallelism)
282 86 build steps completed, average of 2.71/s
283```
284
285You can also get a visual report of the build performance with
286[ninjatracing](https://github.com/nico/ninjatracing). This converts the
287.ninja_log file into a .json file which can be loaded into chrome://tracing:
288
289```shell
290$ python ninjatracing out\Default\.ninja_log >build.json
291```
292
293Finally, Ninja can report on its own overhead which can be helpful if, for
294instance, process creation is making builds slow, perhaps due to anti-virus
295interference due to clang-cl not being in an excluded directory:
296
297```shell
298$ autoninja -d stats -C out\Default base
299metric count avg (us) total (ms)
300.ninja parse 3555 1539.4 5472.6
301canonicalize str 1383032 0.0 12.7
302canonicalize path 1402349 0.0 11.2
303lookup node 1398245 0.0 8.1
304.ninja_log load 2 118.0 0.2
305.ninja_deps load 2 67.5 0.1
306node stat 2516 29.6 74.4
307depfile load 2 1132.0 2.3
308StartEdge 88 3508.1 308.7
309FinishCommand 87 1670.9 145.4
310CLParser::Parse 45 1889.1 85.0
311```
312
dpranke0ae7cad2016-11-30 07:47:58313## Build Chromium
314
Bruce Dawsone9f20fff2018-03-03 01:58:38315Build Chromium (the "chrome" target) with Ninja (or autoninja) using the
316command:
dpranke0ae7cad2016-11-30 07:47:58317
dpranke1a70d0c2016-12-01 02:42:29318```shell
319$ ninja -C out\Default chrome
320```
dpranke0ae7cad2016-11-30 07:47:58321
322You can get a list of all of the other build targets from GN by running
323`gn ls out/Default` from the command line. To compile one, pass to Ninja
324the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
325use ninja -C out/Default chrome/test:unit_tests`).
326
327## Run Chromium
328
329Once it is built, you can simply run the browser:
330
dpranke1a70d0c2016-12-01 02:42:29331```shell
332$ out\Default\chrome.exe
333```
334
335(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58336
337## Running test targets
338
339You can run the tests in the same way. You can also limit which tests are
340run using the `--gtest_filter` arg, e.g.:
341
dpranke1a70d0c2016-12-01 02:42:29342```shell
343$ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*"
344```
dpranke0ae7cad2016-11-30 07:47:58345
346You can find out more about GoogleTest at its
347[GitHub page](https://github.com/google/googletest).
348
349## Update your checkout
350
351To update an existing checkout, you can run
352
dpranke1a70d0c2016-12-01 02:42:29353```shell
354$ git rebase-update
355$ gclient sync
356```
dpranke0ae7cad2016-11-30 07:47:58357
358The first command updates the primary Chromium source repository and rebases
359any of your local branches on top of tip-of-tree (aka the Git branch `origin/master`).
Bruce Dawson4d1de592017-09-08 00:24:00360If you don't want to use this script, you can also just use `git pull` or
dpranke0ae7cad2016-11-30 07:47:58361other common Git commands to update the repo.
362
363The second command syncs the subrepositories to the appropriate versions and
364re-runs the hooks as needed.