blob: b6cf3103389cab9e3cbf6d948c1cba96e230a2fc [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
chaopeng708466c2018-05-24 14:29:0226As of September, 2017 (R503915) Chromium requires Visual Studio 2017 (15.7.2)
Bruce Dawsone9f20fff2018-03-03 01:58:3827to 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 Dawson82a5f0042018-05-18 20:05:4938You must have the version 10.0.17134 Windows 10 SDK installed. This can be
Bruce Dawsone9f20fff2018-03-03 01:58:3839installed 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
James Darpiniandde42b52018-04-05 23:06:56181for only the code you're interested in. Although this will also limit what
182files appear in the project explorer, debugging will still work and you can
183set breakpoints in files that you open manually. A minimal solution that will
184let you compile and run Chrome in the IDE but will not show any source files
185is:
brettwc25693b32016-05-26 01:11:52186
dpranke1a70d0c2016-12-01 02:42:29187```
James Darpiniandde42b52018-04-05 23:06:56188$ gn gen --ide=vs --filters=//chrome --no-deps out\Default
dpranke1a70d0c2016-12-01 02:42:29189```
brettwc25693b32016-05-26 01:11:52190
James Darpiniandde42b52018-04-05 23:06:56191You can selectively add other directories you care about to the filter like so:
192`--filters=//chrome;//third_party/WebKit/*;//gpu/*`.
193
brettwc25693b32016-05-26 01:11:52194There are other options for controlling how the solution is generated, run `gn
195help gen` for the current documentation.
196
James Darpiniandde42b52018-04-05 23:06:56197By default when you start debugging in Visual Studio the debugger will only
198attach to the main browser process. To debug all of Chrome, install
199[Microsoft's Child Process Debugging Power Tool](https://blogs.msdn.microsoft.com/devops/2014/11/24/introducing-the-child-process-debugging-power-tool/).
200You will also need to run Visual Studio as administrator, or it will silently
201fail to attach to some of Chrome's child processes.
202
203It is also possible to debug and develop Chrome in Visual Studio without a
204solution file. Simply "open" your chrome.exe binary with
205`File->Open->Project/Solution`, or from a Visual Studio command prompt like
206so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual
207Studio's code editing features will not work in this configuration, but by
208installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/)
209you can get the source code to appear in the solution explorer window along
210with other useful features such as code search.
211
dpranke0ae7cad2016-11-30 07:47:58212### Faster builds
tfarina502f3882016-03-23 12:48:10213
dpranke0ae7cad2016-11-30 07:47:58214* Reduce file system overhead by excluding build directories from
215 antivirus and indexing software.
216* Store the build tree on a fast disk (preferably SSD).
brucedawsoncfc7fd52017-07-06 18:41:01217* The more cores the better (20+ is not excessive) and lots of RAM is needed
218(64 GB is not excessive).
tfarina502f3882016-03-23 12:48:10219
brucedawsoncfc7fd52017-07-06 18:41:01220There are some gn flags that can improve build speeds. You can specify these
221in the editor that appears when you create your output directory
222(`gn args out/Default`) or on the gn gen command line
223(`gn gen out/Default --args="is_component_build = true is_debug = true"`).
224Some helpful settings to consider using include:
Bruce Dawsone9f20fff2018-03-03 01:58:38225* `use_jumbo_build = true` - *experimental* [Jumbo/unity](jumbo.md) builds.
brucedawsoncfc7fd52017-07-06 18:41:01226* `is_component_build = true` - this uses more, smaller DLLs, and incremental
227linking.
Bruce Dawsonfcd3deb12017-07-28 17:12:20228* `enable_nacl = false` - this disables Native Client which is usually not
229needed for local builds.
brucedawsoncfc7fd52017-07-06 18:41:01230* `target_cpu = "x86"` - x86 builds are slightly faster than x64 builds and
231support incremental linking for more targets. Note that if you set this but
Bruce Dawsonfcd3deb12017-07-28 17:12:20232don't' set enable_nacl = false then build times may get worse.
brucedawsoncfc7fd52017-07-06 18:41:01233* `remove_webcore_debug_symbols = true` - turn off source-level debugging for
234blink to reduce build times, appropriate if you don't plan to debug blink.
brucedawsoncfc7fd52017-07-06 18:41:01235
Bruce Dawson7ff1fe932018-06-14 19:57:12236In order to speed up linking you can set `symbol_level = 1` - this option
237reduces the work the linker has to do but when this option is set you cannot do
238source-level debugging. Switching from `symbol_level = 2` (the default) to
239`symbol_level = 1` requires recompiling everything.
brucedawsoncfc7fd52017-07-06 18:41:01240
Bruce Dawsone9f20fff2018-03-03 01:58:38241In addition, Google employees should use goma, a distributed compilation system.
242Detailed information is available internally but the relevant gn arg is:
243* `use_goma = true`
brucedawsoncfc7fd52017-07-06 18:41:01244
245To get any benefit from goma it is important to pass a large -j value to ninja.
Bruce Dawsone9f20fff2018-03-03 01:58:38246A good default is 10\*numCores to 20\*numCores. If you run autoninja then it
247will automatically pass an appropriate -j value to ninja for goma or not.
248
249```shell
250$ autoninja -C out\Default chrome
251```
brucedawsoncfc7fd52017-07-06 18:41:01252
253When invoking ninja specify 'chrome' as the target to avoid building all test
254binaries as well.
255
256Still, builds will take many hours on many machines.
dpranke0ae7cad2016-11-30 07:47:58257
Bruce Dawsone9f20fff2018-03-03 01:58:38258### Why is my build slow?
259
260Many things can make builds slow, with Windows Defender slowing process startups
261being a frequent culprit. Have you ensured that the entire Chromium src
Bruce Dawson0bbe2d42018-03-06 19:45:55262directory is excluded from antivirus scanning (on Google machines this means
Bruce Dawsone9f20fff2018-03-03 01:58:38263putting it in a ``src`` directory in the root of a drive)? Have you tried the
264different settings listed above, including different link settings and -j
265values? Have you asked on the chromium-dev mailing list to see if your build is
266slower than expected for your machine's specifications?
267
268The next step is to gather some data. There are several options. Setting
269[NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables) lets
270you configure Ninja's output so that, for instance, you can see how many
271processes are running at any given time, how long the build has been running,
272etc., as shown here:
273
274```shell
275$ set NINJA_STATUS=[%r processes, %f/%t @ %o/s : %es ]
276$ autoninja -C out\Default base
277ninja: Entering directory `out\Default'
278[1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb
279```
280
281In addition, if you set the ``NINJA_SUMMARIZE_BUILD`` environment variable to 1 then
282autoninja will print a build performance summary when the build completes,
283showing the slowest build steps and build-step types, as shown here:
284
285```shell
286$ set NINJA_SUMMARIZE_BUILD=1
287$ autoninja -C out\Default base
288 Longest build steps:
289...
290 1.2 weighted s to build base.dll, base.dll.lib, base.dll.pdb (1.2 s CPU time)
291 8.5 weighted s to build obj/base/base/base_jumbo_38.obj (30.1 s CPU time)
292 Time by build-step type:
293...
294 1.2 s weighted time to generate 1 PEFile (linking) files (1.2 s CPU time)
295 30.3 s weighted time to generate 45 .obj files (688.8 s CPU time)
296 31.8 s weighted time (693.8 s CPU time, 21.8x parallelism)
297 86 build steps completed, average of 2.71/s
298```
299
Bruce Dawson0bbe2d42018-03-06 19:45:55300You can also generate these reports by manually running the script after a build:
301
302```shell
303$ python depot_tools\post_build_ninja_summary.py -C out\Default
304```
305
Bruce Dawsone9f20fff2018-03-03 01:58:38306You can also get a visual report of the build performance with
307[ninjatracing](https://github.com/nico/ninjatracing). This converts the
308.ninja_log file into a .json file which can be loaded into chrome://tracing:
309
310```shell
311$ python ninjatracing out\Default\.ninja_log >build.json
312```
313
314Finally, Ninja can report on its own overhead which can be helpful if, for
Bruce Dawson0bbe2d42018-03-06 19:45:55315instance, process creation is making builds slow, perhaps due to antivirus
Bruce Dawsone9f20fff2018-03-03 01:58:38316interference due to clang-cl not being in an excluded directory:
317
318```shell
319$ autoninja -d stats -C out\Default base
320metric count avg (us) total (ms)
321.ninja parse 3555 1539.4 5472.6
322canonicalize str 1383032 0.0 12.7
323canonicalize path 1402349 0.0 11.2
324lookup node 1398245 0.0 8.1
325.ninja_log load 2 118.0 0.2
326.ninja_deps load 2 67.5 0.1
327node stat 2516 29.6 74.4
328depfile load 2 1132.0 2.3
329StartEdge 88 3508.1 308.7
330FinishCommand 87 1670.9 145.4
331CLParser::Parse 45 1889.1 85.0
332```
333
dpranke0ae7cad2016-11-30 07:47:58334## Build Chromium
335
Max Morozf5b31fcd2018-08-10 21:55:48336Build Chromium (the "chrome" target) with Ninja using the command:
dpranke0ae7cad2016-11-30 07:47:58337
dpranke1a70d0c2016-12-01 02:42:29338```shell
Max Morozf5b31fcd2018-08-10 21:55:48339$ autoninja -C out\Default chrome
dpranke1a70d0c2016-12-01 02:42:29340```
dpranke0ae7cad2016-11-30 07:47:58341
Max Morozf5b31fcd2018-08-10 21:55:48342`autoninja` is a wrapper that automatically provides optimal values for the
343arguments passed to `ninja`.
344
dpranke0ae7cad2016-11-30 07:47:58345You can get a list of all of the other build targets from GN by running
346`gn ls out/Default` from the command line. To compile one, pass to Ninja
347the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
348use ninja -C out/Default chrome/test:unit_tests`).
349
350## Run Chromium
351
352Once it is built, you can simply run the browser:
353
dpranke1a70d0c2016-12-01 02:42:29354```shell
355$ out\Default\chrome.exe
356```
357
358(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58359
360## Running test targets
361
362You can run the tests in the same way. You can also limit which tests are
363run using the `--gtest_filter` arg, e.g.:
364
dpranke1a70d0c2016-12-01 02:42:29365```shell
366$ out\Default\unit_tests.exe --gtest_filter="PushClientTest.*"
367```
dpranke0ae7cad2016-11-30 07:47:58368
369You can find out more about GoogleTest at its
370[GitHub page](https://github.com/google/googletest).
371
372## Update your checkout
373
374To update an existing checkout, you can run
375
dpranke1a70d0c2016-12-01 02:42:29376```shell
377$ git rebase-update
378$ gclient sync
379```
dpranke0ae7cad2016-11-30 07:47:58380
381The first command updates the primary Chromium source repository and rebases
382any of your local branches on top of tip-of-tree (aka the Git branch `origin/master`).
Bruce Dawson4d1de592017-09-08 00:24:00383If you don't want to use this script, you can also just use `git pull` or
dpranke0ae7cad2016-11-30 07:47:58384other common Git commands to update the repo.
385
386The second command syncs the subrepositories to the appropriate versions and
387re-runs the hooks as needed.