blob: 773241e8b2952915d8752ca172690935bf14b288 [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.
Bruce Dawson52c749c2020-12-03 16:44:2620* Windows 10 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 Dawsond95ceb62023-02-17 01:39:3026Chromium requires [Visual Studio 2022](https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes) (>=17.0.0)
27to build. Visual Studio can also be used to debug Chromium.
Raul Tambre1bb5c1a2018-12-29 00:57:1228The clang-cl compiler is used but Visual Studio's header files, libraries, and
29some tools are required. Visual Studio Community Edition should work if its
30license is appropriate for you. You must install the "Desktop development with
31C++" component and the "MFC/ATL support" sub-components. This can be done from
32the command line by passing these arguments to the Visual Studio installer (see
33below for ARM64 instructions):
Bruce Dawson1c0979a62017-09-13 17:47:2134```shell
Bruce Dawsone42d7642018-12-10 23:50:0035$ PATH_TO_INSTALLER.EXE ^
36--add Microsoft.VisualStudio.Workload.NativeDesktop ^
37--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
38--includeRecommended
Bruce Dawson1c0979a62017-09-13 17:47:2139```
pwnall43b43ba2016-08-22 19:29:2940
Bruce Dawsone42d7642018-12-10 23:50:0041If you want to build for ARM64 Win32 then some extra arguments are needed. The
42full set for that case is:
43```shell
44$ PATH_TO_INSTALLER.EXE ^
45--add Microsoft.VisualStudio.Workload.NativeDesktop ^
46--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
47--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^
48--add Microsoft.VisualStudio.Component.VC.MFC.ARM64 ^
49--includeRecommended
50```
51
Solomon Kinard45427072023-06-22 18:21:0152Required
Bruce Dawsone9f20fff2018-03-03 01:58:3853
Solomon Kinard45427072023-06-22 18:21:0154* [Windows 11 SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/)
55version 10.0.22621.0. This can be installed separately or by checking the
56appropriate box in the Visual Studio Installer.
57* (Windows 11) SDK Debugging Tools 10.0.22621.755. This version of the Debugging
58tools is needed in order to support reading the large-page PDBs that Chrome uses
59to allow greater-than 4 GiB PDBs. This can be installed after the matching
60Windows SDK version is installed, from: Control Panel -> Programs and Features
61-> Windows Software Development Kit [version] -> Change -> Debugging Tools for
Bruce Dawson9588daa2023-10-18 22:07:2562Windows. If building on ARM64 Windows then you will need to manually copy the
63Debuggers\x64 directory from another machine because it does not get installed
64on ARM64 and is needed, whether you are building Chromium for x64 or ARM64 on
65ARM64.
Robert Sesekc8ffa1b2017-08-04 19:55:2266
dpranke0ae7cad2016-11-30 07:47:5867## Install `depot_tools`
tfarina502f3882016-03-23 12:48:1068
Solomon Kinard45427072023-06-22 18:21:0169Download the
70[depot_tools bundle](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
Eric Waldmanc469ba7b2022-03-02 20:33:0071and extract it somewhere (eg: C:\src\depot_tools).
tfarina502f3882016-03-23 12:48:1072
Solomon Kinard45427072023-06-22 18:21:0173***
dpranke0ae7cad2016-11-30 07:47:5874**Warning:** **DO NOT** use drag-n-drop or copy-n-paste extract from Explorer,
75this will not extract the hidden “.git” folder which is necessary for
Bruce Dawson4d1de592017-09-08 00:24:0076depot_tools to autoupdate itself. You can use “Extract all…” from the
dpranke0ae7cad2016-11-30 07:47:5877context menu though.
78***
tfarina502f3882016-03-23 12:48:1079
Bruce Dawson4d1de592017-09-08 00:24:0080Add depot_tools to the start of your PATH (must be ahead of any installs of
Eric Waldmanc469ba7b2022-03-02 20:33:0081Python. Note that environment variable names are case insensitive).
Solomon Kinard45427072023-06-22 18:21:0182* Assuming you unzipped the bundle to C:\src\depot_tools, open: Control Panel → System and Security → System → Advanced system settings
83* If you have Administrator access, Modify the PATH system variable and put
84`C:\src\depot_tools` at the front (or at least in front of any directory that
85might already have a copy of Python or Git).
86* If you don't have Administrator access, you can add a user-level PATH
87environment variable by opening: Control Panel → System and Security → System →
88Search for "Edit environment variables for your account"
89* Add `C:\src\depot_tools` at the front. Note: If your system PATH has a Python
90in it, you will be out of luck.
dpranke0ae7cad2016-11-30 07:47:5891
Wan-Teh Chang03912872022-03-14 23:07:3492Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN environment variable in the same way, and set
dpranke0ae7cad2016-11-30 07:47:5893it to 0. This tells depot_tools to use your locally installed version of Visual
Aaron Gabledad9e0f2020-01-09 19:38:5294Studio (by default, depot_tools will try to use a google-internal version).
dpranke0ae7cad2016-11-30 07:47:5895
Bruce Dawsond95ceb62023-02-17 01:39:3096You may also have to set variable `vs2022_install` to your installation path of
97Visual Studio 2022, like
98`set vs2022_install=C:\Program Files\Microsoft Visual Studio\2022\Professional`.
Andreas Papacharalampous1d22c9612020-06-13 23:11:1799
Reilly Grant07ff22e2021-10-19 19:21:20100From a cmd.exe shell, run:
Reilly Grant07ff22e2021-10-19 19:21:20101```shell
102$ gclient
103```
104
105On first run, gclient will install all the Windows-specific bits needed to work
106with the code, including msysgit and python.
dpranke0ae7cad2016-11-30 07:47:58107
108* If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell),
109 it may appear to run properly, but msysgit, python, and other tools
110 may not get installed correctly.
111* If you see strange errors with the file system on the first run of gclient,
Yuma Takaid4809d552022-02-15 03:48:19112 you may want to [disable Windows Indexing](https://tortoisesvn.net/faq.html#cantmove2).
dpranke0ae7cad2016-11-30 07:47:58113
Will Harris1c8f89c2021-03-08 22:53:43114## Check python install
115
Bruce Dawson4d1de592017-09-08 00:24:00116After running gclient open a command prompt and type `where python` and
117confirm that the depot_tools `python.bat` comes ahead of any copies of
118python.exe. Failing to ensure this can lead to overbuilding when
dpranke0ae7cad2016-11-30 07:47:58119using gn - see [crbug.com/611087](https://crbug.com/611087).
120
Will Harris1c8f89c2021-03-08 22:53:43121[App Execution Aliases](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#alias)
122can conflict with other installations of python on the system so disable
123these for 'python.exe' and 'python3.exe' by opening 'App execution aliases'
124section of Control Panel and unticking the boxes next to both of these
125that point to 'App Installer'.
126
dpranke0ae7cad2016-11-30 07:47:58127## Get the code
128
Leonard Mosescu718c9ac2017-06-20 18:06:32129First, configure Git:
130
131```shell
132$ git config --global user.name "My Name"
133$ git config --global user.email "[email protected]"
134$ git config --global core.autocrlf false
135$ git config --global core.filemode false
136$ git config --global branch.autosetuprebase always
137```
138
Bruce Dawsonc2c02e52023-11-22 04:43:15139While not necessarily required it can be helpful to configure git to allow long
140path support (beyond the Windows MAX_PATH limit):
141
142```shell
143git config --global core.longpaths true
144```
145
Sonja Laurilac8949372023-06-27 10:09:23146Create a `chromium` directory for the checkout and change to it. You can call
147this whatever you like and put it wherever you like, as long as the full path
148has no spaces. However there are some performance benefits for Googlers in
149placing the directory under `C:\src\`
150(See [Why is my build slow?](https://chromium.googlesource.com/chromium/src/+/main/docs/windows_build_instructions.md#why-is-my-build-slow)).
dpranke0ae7cad2016-11-30 07:47:58151
sdy93387fa2016-12-01 01:03:44152```shell
153$ mkdir chromium && cd chromium
154```
155
156Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:58157dependencies.
158
sdy93387fa2016-12-01 01:03:44159```shell
xiaoyin.l802e4b3e2016-12-04 22:17:30160$ fetch chromium
sdy93387fa2016-12-01 01:03:44161```
dpranke0ae7cad2016-11-30 07:47:58162
163If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:44164adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:58165
Bruce Dawson2c83223e2022-10-25 21:08:22166Expect the command to take over an hour on even a fast connection, and many
167hours on slower ones. You should configure your PC so that it doesn't sleep
168or hibernate during the fetch or else errors may occur. If errors occur while
169fetching sub-repos then you can start over, or you may be able to correct them
170by going to the chromium/src directory and running this command:
171
172```shell
173$ gclient sync
174```
dpranke0ae7cad2016-11-30 07:47:58175
sdy93387fa2016-12-01 01:03:44176When `fetch` completes, it will have created a hidden `.gclient` file and a
177directory called `src` in the working directory. The remaining instructions
178assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:58179
sdy93387fa2016-12-01 01:03:44180```shell
181$ cd src
182```
dpranke0ae7cad2016-11-30 07:47:58183
sdy93387fa2016-12-01 01:03:44184*Optional*: You can also [install API
185keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
186build to talk to some Google services, but this is not necessary for most
187development and testing purposes.
dpranke0ae7cad2016-11-30 07:47:58188
dpranke1a70d0c2016-12-01 02:42:29189## Setting up the build
dpranke0ae7cad2016-11-30 07:47:58190
Tom Bridgwatereef401542018-08-17 00:54:43191Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
Andrew Williamsbbc1a1e2021-07-21 01:51:22192a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md)
Tom Bridgwatereef401542018-08-17 00:54:43193to generate `.ninja` files. You can create any number of *build directories*
194with different configurations. To create a build directory:
dpranke0ae7cad2016-11-30 07:47:58195
sdy93387fa2016-12-01 01:03:44196```shell
Andrew Williamsfa9b7d62023-03-20 15:48:28197$ gn gen out\Default
sdy93387fa2016-12-01 01:03:44198```
dpranke0ae7cad2016-11-30 07:47:58199
sdy93387fa2016-12-01 01:03:44200* You only have to run this once for each new build directory, Ninja will
201 update the build files as needed.
202* You can replace `Default` with another name, but
203 it should be a subdirectory of `out`.
Aaron Gabledad9e0f2020-01-09 19:38:52204* For other build arguments, including release settings or using an alternate
205 version of Visual Studio, see [GN build
sdy93387fa2016-12-01 01:03:44206 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58207 The default will be a debug component build matching the current host
208 operating system and CPU.
Tom Bridgwatereef401542018-08-17 00:54:43209* For more info on GN, run `gn help` on the command line or read the [quick
Andrew Williamsbbc1a1e2021-07-21 01:51:22210 start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
Juan Cruz Viotti9c7622d2021-06-30 00:27:23211
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
Andrew Williamsfa9b7d62023-03-20 15:48:28222(`gn args out\Default`) or on the gn gen command line
223(`gn gen out\Default --args="is_component_build = true is_debug = true"`).
brucedawsoncfc7fd52017-07-06 18:41:01224Some helpful settings to consider using include:
Bruce Dawson2c83223e2022-10-25 21:08:22225* `is_component_build = true` - this uses more, smaller DLLs, and may avoid
226having to relink chrome.dll after every change.
Bruce Dawsonfcd3deb12017-07-28 17:12:20227* `enable_nacl = false` - this disables Native Client which is usually not
228needed for local builds.
Bruce Dawson2c83223e2022-10-25 21:08:22229* `target_cpu = "x86"` - x86 builds may be slightly faster than x64 builds. Note
230that if you set this but don't set `enable_nacl = false` then build times may
231get worse.
James Cook26699a92019-03-12 22:23:10232* `blink_symbol_level = 0` - turn off source-level debugging for
brucedawsoncfc7fd52017-07-06 18:41:01233blink to reduce build times, appropriate if you don't plan to debug blink.
Bruce Dawson63e0be72021-11-29 20:34:41234* `v8_symbol_level = 0` - turn off source-level debugging for v8 to reduce
235build times, appropriate if you don't plan to debug v8.
brucedawsoncfc7fd52017-07-06 18:41:01236
Bruce Dawson817f47fb2020-05-01 22:29:08237In order to speed up linking you can set `symbol_level = 1` or
238`symbol_level = 0` - these options reduce the work the compiler and linker have
239to do. With `symbol_level = 1` the compiler emits file name and line number
240information so you can still do source-level debugging but there will be no
241local variable or type information. With `symbol_level = 0` there is no
242source-level debugging but call stacks still have function names. Changing
243`symbol_level` requires recompiling everything.
brucedawsoncfc7fd52017-07-06 18:41:01244
Ben Segall4a89ec52023-09-26 15:02:56245#### Use Reclient
246
247In addition, Google employees should use reclient, a distributed compilation system.
248Detailed information is available internally but the relevant gn arg is:
249* `use_remoteexec = true`
250
Solomon Kinard5cd00762023-11-04 00:47:19251Google employees can visit
252[go/building-chrome-win#setup-remote-execution](http://go/building-chrome-win#setup-remote-execution)
253for more information.
Ben Segall4a89ec52023-09-26 15:02:56254
255When invoking ninja, specify 'chrome' as the target to avoid building all test
256binaries as well.
257
258Still, builds will take many hours on many machines.
259
260#### Use Goma (deprecated)
261
Bruce Dawsone9f20fff2018-03-03 01:58:38262In addition, Google employees should use goma, a distributed compilation system.
263Detailed information is available internally but the relevant gn arg is:
264* `use_goma = true`
brucedawsoncfc7fd52017-07-06 18:41:01265
266To get any benefit from goma it is important to pass a large -j value to ninja.
Bruce Dawsone9f20fff2018-03-03 01:58:38267A good default is 10\*numCores to 20\*numCores. If you run autoninja then it
268will automatically pass an appropriate -j value to ninja for goma or not.
269
270```shell
271$ autoninja -C out\Default chrome
272```
brucedawsoncfc7fd52017-07-06 18:41:01273
Ben Segall4a89ec52023-09-26 15:02:56274When invoking ninja, specify 'chrome' as the target to avoid building all test
brucedawsoncfc7fd52017-07-06 18:41:01275binaries as well.
276
277Still, builds will take many hours on many machines.
dpranke0ae7cad2016-11-30 07:47:58278
Juan Cruz Viotti9c7622d2021-06-30 00:27:23279#### Use SCCACHE
280
281You might be able to use [sccache](https://github.com/mozilla/sccache) for the
282build process by enabling the following arguments:
283
284* `cc_wrapper = "sccache"` - assuming the `sccache` binary is in your `%PATH%`
285* `chrome_pgo_phase = 0`
286
Bruce Dawsone9f20fff2018-03-03 01:58:38287### Why is my build slow?
288
289Many things can make builds slow, with Windows Defender slowing process startups
290being a frequent culprit. Have you ensured that the entire Chromium src
Bruce Dawson0bbe2d42018-03-06 19:45:55291directory is excluded from antivirus scanning (on Google machines this means
Bruce Dawsone9f20fff2018-03-03 01:58:38292putting it in a ``src`` directory in the root of a drive)? Have you tried the
293different settings listed above, including different link settings and -j
294values? Have you asked on the chromium-dev mailing list to see if your build is
295slower than expected for your machine's specifications?
296
Bruce Dawson15104782023-10-19 20:06:23297If you suspect that Defender is slowing your build then you can try Microsoft's
298[Performance analyzer for Microsoft Defender Antivirus](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/tune-performance-defender-antivirus?view=o365-worldwide)
299to investigate in detail.
300
Bruce Dawson89390172019-05-08 09:51:18301The next step is to gather some data. If you set the ``NINJA_SUMMARIZE_BUILD``
Bruce Dawsonb9988e92019-09-16 17:01:10302environment variable to 1 then ``autoninja`` will do three things. First, it
303will set the [NINJA_STATUS](https://ninja-build.org/manual.html#_environment_variables)
Bruce Dawson89390172019-05-08 09:51:18304environment variable so that ninja will print additional information while
305building Chrome. It will show how many build processes are running at any given
306time, how many build steps have completed, how many build steps have completed
307per second, and how long the build has been running, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38308
309```shell
Bruce Dawson89390172019-05-08 09:51:18310$ set NINJA_SUMMARIZE_BUILD=1
Bruce Dawsone9f20fff2018-03-03 01:58:38311$ autoninja -C out\Default base
312ninja: Entering directory `out\Default'
313[1 processes, 86/86 @ 2.7/s : 31.785s ] LINK(DLL) base.dll base.dll.lib base.dll.pdb
314```
315
Bruce Dawson89390172019-05-08 09:51:18316This makes slow process creation immediately obvious and lets you tell quickly
317if a build is running more slowly than normal.
318
319In addition, setting ``NINJA_SUMMARIZE_BUILD=1`` tells ``autoninja`` to print a
320build performance summary when the build completes, showing the slowest build
321steps and slowest build-step types, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38322
323```shell
324$ set NINJA_SUMMARIZE_BUILD=1
325$ autoninja -C out\Default base
Bruce Dawson2721f0b2019-11-08 18:41:27326Longest build steps:
327 0.1 weighted s to build obj/base/base/trace_log.obj (6.7 s elapsed time)
328 0.2 weighted s to build nasm.exe, nasm.exe.pdb (0.2 s elapsed time)
329 0.3 weighted s to build obj/base/base/win_util.obj (12.4 s elapsed time)
330 1.2 weighted s to build base.dll, base.dll.lib (1.2 s elapsed time)
331Time by build-step type:
332 0.0 s weighted time to generate 6 .lib files (0.3 s elapsed time sum)
333 0.1 s weighted time to generate 25 .stamp files (1.2 s elapsed time sum)
334 0.2 s weighted time to generate 20 .o files (2.8 s elapsed time sum)
335 1.7 s weighted time to generate 4 PEFile (linking) files (2.0 s elapsed
336time sum)
337 23.9 s weighted time to generate 770 .obj files (974.8 s elapsed time sum)
33826.1 s weighted time (982.9 s elapsed time sum, 37.7x parallelism)
339839 build steps completed, average of 32.17/s
Bruce Dawsone9f20fff2018-03-03 01:58:38340```
341
Bruce Dawson2721f0b2019-11-08 18:41:27342The "weighted" time is the elapsed time of each build step divided by the number
343of tasks that were running in parallel. This makes it an excellent approximation
344of how "important" a slow step was. A link that is entirely or mostly serialized
345will have a weighted time that is the same or similar to its elapsed time. A
346compile that runs in parallel with 999 other compiles will have a weighted time
347that is tiny.
348
Bruce Dawson0bbe2d42018-03-06 19:45:55349You can also generate these reports by manually running the script after a build:
350
351```shell
352$ python depot_tools\post_build_ninja_summary.py -C out\Default
353```
354
Bruce Dawsonb9988e92019-09-16 17:01:10355Finally, setting ``NINJA_SUMMARIZE_BUILD=1`` tells autoninja to tell Ninja to
356report on its own overhead by passing "-d stats". This can be helpful if, for
357instance, process creation (which shows up in the StartEdge metric) is making
358builds slow, perhaps due to antivirus interference due to clang-cl not being in
359an excluded directory:
Bruce Dawsone9f20fff2018-03-03 01:58:38360
361```shell
Bruce Dawsonb9988e92019-09-16 17:01:10362$ set NINJA_SUMMARIZE_BUILD=1
363$ autoninja -C out\Default base
Bruce Dawsone9f20fff2018-03-03 01:58:38364metric count avg (us) total (ms)
365.ninja parse 3555 1539.4 5472.6
366canonicalize str 1383032 0.0 12.7
367canonicalize path 1402349 0.0 11.2
368lookup node 1398245 0.0 8.1
369.ninja_log load 2 118.0 0.2
370.ninja_deps load 2 67.5 0.1
371node stat 2516 29.6 74.4
372depfile load 2 1132.0 2.3
373StartEdge 88 3508.1 308.7
374FinishCommand 87 1670.9 145.4
375CLParser::Parse 45 1889.1 85.0
376```
377
Bruce Dawsonb9988e92019-09-16 17:01:10378You can also get a visual report of the build performance with
379[ninjatracing](https://github.com/nico/ninjatracing). This converts the
Chunbo Huaea6a9cf2022-07-20 03:01:10380.ninja_log file into a .json file which can be loaded into [chrome://tracing](chrome://tracing):
Bruce Dawsonb9988e92019-09-16 17:01:10381
382```shell
383$ python ninjatracing out\Default\.ninja_log >build.json
384```
385
dpranke0ae7cad2016-11-30 07:47:58386## Build Chromium
387
Max Morozf5b31fcd2018-08-10 21:55:48388Build Chromium (the "chrome" target) with Ninja using the command:
dpranke0ae7cad2016-11-30 07:47:58389
dpranke1a70d0c2016-12-01 02:42:29390```shell
Max Morozf5b31fcd2018-08-10 21:55:48391$ autoninja -C out\Default chrome
dpranke1a70d0c2016-12-01 02:42:29392```
dpranke0ae7cad2016-11-30 07:47:58393
Max Morozf5b31fcd2018-08-10 21:55:48394`autoninja` is a wrapper that automatically provides optimal values for the
395arguments passed to `ninja`.
396
dpranke0ae7cad2016-11-30 07:47:58397You can get a list of all of the other build targets from GN by running
Andrew Williamsfa9b7d62023-03-20 15:48:28398`gn ls out\Default` from the command line. To compile one, pass to Ninja
dpranke0ae7cad2016-11-30 07:47:58399the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
Andrew Williamsfa9b7d62023-03-20 15:48:28400use `autoninja -C out\Default chrome/test:unit_tests`).
dpranke0ae7cad2016-11-30 07:47:58401
402## Run Chromium
403
404Once it is built, you can simply run the browser:
405
dpranke1a70d0c2016-12-01 02:42:29406```shell
407$ out\Default\chrome.exe
408```
409
410(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58411
412## Running test targets
413
Andrew Williamsfa9b7d62023-03-20 15:48:28414Tests are split into multiple test targets based on their type and where they
415exist in the directory structure. To see what target a given unit test or
416browser test file corresponds to, the following command can be used:
dpranke0ae7cad2016-11-30 07:47:58417
dpranke1a70d0c2016-12-01 02:42:29418```shell
Andrew Williamsfa9b7d62023-03-20 15:48:28419$ gn refs out\Default --testonly=true --type=executable --all chrome\browser\ui\browser_list_unittest.cc
420//chrome/test:unit_tests
421```
422
423In the example above, the target is unit_tests. The unit_tests binary can be
424built by running the following command:
425
426```shell
427$ autoninja -C out\Default unit_tests
428```
429
430You can run the tests by running the unit_tests binary. You can also limit which
431tests are run using the `--gtest_filter` arg, e.g.:
432
433```shell
434$ out\Default\unit_tests.exe --gtest_filter="BrowserListUnitTest.*"
dpranke1a70d0c2016-12-01 02:42:29435```
dpranke0ae7cad2016-11-30 07:47:58436
437You can find out more about GoogleTest at its
438[GitHub page](https://github.com/google/googletest).
439
440## Update your checkout
441
442To update an existing checkout, you can run
443
dpranke1a70d0c2016-12-01 02:42:29444```shell
445$ git rebase-update
Bruce Dawsonef0b5452020-10-03 00:13:09446$ gclient sync -D
dpranke1a70d0c2016-12-01 02:42:29447```
dpranke0ae7cad2016-11-30 07:47:58448
449The first command updates the primary Chromium source repository and rebases
Andrew Williamsbbc1a1e2021-07-21 01:51:22450any of your local branches on top of tip-of-tree (aka the Git branch
451`origin/main`). If you don't want to use this script, you can also just use
452`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58453
Bruce Dawsonef0b5452020-10-03 00:13:09454The second command syncs the subrepositories to the appropriate versions,
455deleting those that are no longer needed, and re-runs the hooks as needed.
456
457### Editing and Debugging With the Visual Studio IDE
458
459You can use the Visual Studio IDE to edit and debug Chrome, with or without
460Intellisense support.
461
462#### Using Visual Studio Intellisense
463
464If you want to use Visual Studio Intellisense when developing Chromium, use the
465`--ide` command line argument to `gn gen` when you generate your output
466directory (as described on the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code)
Junji Watanabe0f6489c72023-02-01 04:02:11467page). This is an example when your checkout is `C:\src\chromium` and your
468output directory is `out\Default`:
Bruce Dawsonef0b5452020-10-03 00:13:09469
470```shell
Junji Watanabe0f6489c72023-02-01 04:02:11471$ gn gen --ide=vs --ninja-executable=C:\src\chromium\src\third_party\ninja\ninja.exe out\Default
Bruce Dawsonef0b5452020-10-03 00:13:09472$ devenv out\Default\all.sln
473```
474
475GN will produce a file `all.sln` in your build directory. It will internally
476use Ninja to compile while still allowing most IDE functions to work (there is
477no native Visual Studio compilation mode). If you manually run "gen" again you
478will need to resupply this argument, but normally GN will keep the build and
479IDE files up to date automatically when you build.
480
481The generated solution will contain several thousand projects and will be very
482slow to load. Use the `--filters` argument to restrict generating project files
483for only the code you're interested in. Although this will also limit what
484files appear in the project explorer, debugging will still work and you can
485set breakpoints in files that you open manually. A minimal solution that will
486let you compile and run Chrome in the IDE but will not show any source files
487is:
488
489```
Junji Watanabe0f6489c72023-02-01 04:02:11490$ gn gen --ide=vs --ninja-executable=C:\src\chromium\src\third_party\ninja\ninja.exe --filters=//chrome --no-deps out\Default
Bruce Dawsonef0b5452020-10-03 00:13:09491```
492
493You can selectively add other directories you care about to the filter like so:
494`--filters=//chrome;//third_party/WebKit/*;//gpu/*`.
495
496There are other options for controlling how the solution is generated, run `gn
497help gen` for the current documentation.
498
499#### Using Visual Studio without Intellisense
500
501It is also possible to debug and develop Chrome in Visual Studio without the
502overhead of a multi-project solution file. Simply "open" your chrome.exe binary
503with `File->Open->Project/Solution`, or from a Visual Studio command prompt like
504so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual
505Studio's code exploration features will not work in this configuration, but by
506installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/)
507you can get the source code to appear in the solution explorer window along
508with other useful features such as code search. You can add multiple executables
509of interest (base_unittests.exe, browser_tests.exe) to your solution with
510`File->Add->Existing Project...` and change which one will be debugged by
511right-clicking on them in `Solution Explorer` and selecting `Set as Startup
512Project`. You can also change their properties, including command line
513arguments, by right-clicking on them in `Solution Explorer` and selecting
514`Properties`.
515
516By default when you start debugging in Visual Studio the debugger will only
517attach to the main browser process. To debug all of Chrome, install
518[Microsoft's Child Process Debugging Power Tool](https://blogs.msdn.microsoft.com/devops/2014/11/24/introducing-the-child-process-debugging-power-tool/).
519You will also need to run Visual Studio as administrator, or it will silently
520fail to attach to some of Chrome's child processes.
521
Bruce Dawson425d4ab2023-06-25 01:36:15522### Improving performance of git commands
Avi Drissmanc0f6793ac2023-05-26 19:22:44523
524#### Configure git to use an untracked cache
525
Bruce Dawson2154274a2023-06-17 22:24:29526Try running
Avi Drissmanc0f6793ac2023-05-26 19:22:44527
528```shell
529$ git update-index --test-untracked-cache
530```
531
532If the output ends with `OK`, then the following may also improve performance of
533`git status`:
534
535```shell
536$ git config core.untrackedCache true
537```
538
Avi Drissmanc0f6793ac2023-05-26 19:22:44539#### Configure git to use fsmonitor
540
Bruce Dawson2154274a2023-06-17 22:24:29541You can significantly speed up git by using [fsmonitor.](https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/)
542You should enable fsmonitor in large repos, such as Chromium and v8. Enabling
543it globally will launch many processes and consume excess commit/memory and
544probably isn't worthwhile. The command to enable fsmonitor in the current repo
545is:
Avi Drissmanc0f6793ac2023-05-26 19:22:44546
547```shell
548$ git config core.fsmonitor true
549```