blob: a360e8e61d555617bd81a79140c1fa484d3ef225 [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
Bruce Dawsonc2661722024-06-12 19:44:2915* An x86-64 machine with at least 8GB of RAM. More than 16GB is highly
dpranke0ae7cad2016-11-30 07:47:5816 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
Devon Loehrc0acd932024-10-21 18:15:2026Chromium requires [Visual Studio 2022](https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes)
27(>=17.0.0) to 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/)
Devon Loehrfca8e872025-03-20 16:54:0155version 10.0.26100.3323. This can be installed separately or by checking the
Solomon Kinard45427072023-06-22 18:21:0156appropriate box in the Visual Studio Installer.
Devon Loehrfca8e872025-03-20 16:54:0157* (Windows 11) SDK Debugging Tools 10.0.26100.3323 or higher. This version of the
Devon Loehrea1232d2024-10-31 17:01:3758Debugging tools is needed in order to support reading the large-page PDBs that
Devon Loehrfca8e872025-03-20 16:54:0159Chrome uses to allow greater-than 4 GiB PDBs. If the current SDK installation
60does not include debugging tools, they can be installed at:
61Control Panel -> Programs and Features -> Windows Software Development Kit [version]
62-> Change -> Debugging Tools for Windows. If building on ARM64 Windows then you
63will need to manually copy the Debuggers\x64 directory from another machine because
64it does not get installed on ARM64 and is needed, whether you are building Chromium
65for x64 or ARM64 on ARM64.
Devon Loehr0f6eaa52024-10-16 16:22:0166
Devon Loehrae8ba63e2025-04-04 16:59:4467WARNING: On sufficiently old versions of Windows (1909 or earlier), dawn or
68related components may fail with a D3d-related error when using the 26100 SDK.
69This is because the d3dcompiler_47.dll file in the new SDK attempts to
70dynamically link versions of the Universal C Runtime which are not present by
71default on older systems. If you experience these errors, you can either update
72the UCRT on your system, or install the 22621 SDK and use the d3dcompiler_47.dll
73file included there, which statically links the UCRT.
74
75This problem may also manifest as a DLL failure to load `__CxxFrameHandler4`.
76
Anne Redulla7b370052024-09-09 00:39:3577## git installation
78
79### Install git
80
81If you haven't installed `git` directly before, you can download a standalone
82installer for the latest version of Git For Windows from the Git website at
83https://git-scm.com/download/win.
84
85For more information on Git for Windows (which is a separate project from Git),
86see https://gitforwindows.org.
87
Kalvin Lee8d8ead12025-01-20 04:28:3388Note: if you are a Google employee, see git installation instructions at
89[go/building-chrome-win](https://goto.google.com/building-chrome-win#install-updates-and-required-software).
Anne Redulla7b370052024-09-09 00:39:3590
91### Update git
92
93Note: this section is about updating a direct installation of `git` because
94`depot_tools` will soon stop bundling `git`.
95
Anne Redulla7b370052024-09-09 00:39:3596Updating to the latest version of `git` will depend on which version you
97currently have installed. First, check your `git` version. From a cmd.exe shell,
98run:
99```shell
100$ git version
101```
102
103| Current version | How to update to latest |
104| --- | --- |
105| `2.14.1` or earlier | You will need to manually uninstall Git, then follow the instructions above to [install git](#install-git) |
106| `2.14.2` to `2.16.1` | In a cmd.exe shell, run: `git update` |
107| `2.16.1(2)` and later | In a cmd.exe shell, run: `git update-git-for-windows` |
108
dpranke0ae7cad2016-11-30 07:47:58109## Install `depot_tools`
tfarina502f3882016-03-23 12:48:10110
Anne Redulla4444f882025-02-20 23:30:00111From a command shell, navigate to the directory where you want to put
112`depot_tools` and clone the `depot_tools` repository. For example, if you
113want it to be cloned to `C:\src\depot_tools`:
Anne Redulla7b370052024-09-09 00:39:35114
Anne Redulla4444f882025-02-20 23:30:00115```shell
116$ cd C:\src
117$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
118```
tfarina502f3882016-03-23 12:48:10119
Bruce Dawson4d1de592017-09-08 00:24:00120Add depot_tools to the start of your PATH (must be ahead of any installs of
Eric Waldmanc469ba7b2022-03-02 20:33:00121Python. Note that environment variable names are case insensitive).
Anne Redulla4444f882025-02-20 23:30:00122* Assuming you cloned the repo to `C:\src\depot_tools`, open:
Anne Redulla7b370052024-09-09 00:39:35123 Control Panel → System and Security → System
124* Select which PATH variable to edit.
125 * If you have Administrator access, you can edit the **system** PATH. Click
126 Advanced system settings → Environment Variables. Under "System variables",
127 select the Path variable for editing.
128 * If you don't have Administrator access, you can edit your **user-level**
129 PATH. Search for "Edit environment variables for your account". Under "User
130 variables for %USER%", select the Path variable for editing.
131* Modify the Path variable by adding `C:\src\depot_tools` at the front (or at
132 least in front of any directory that might already have a copy of Python).
133 Note: If you can only modify your user-level PATH and the system PATH has a
134 Python in it, you will be out of luck.
135
Devon Loehrc0acd932024-10-21 18:15:20136Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN environment variable in the same way, and
137set it to 0. This tells depot_tools to use your locally installed version of
138Visual Studio (by default, depot_tools will try to use a google-internal
139version).
dpranke0ae7cad2016-11-30 07:47:58140
Bruce Dawsond95ceb62023-02-17 01:39:30141You may also have to set variable `vs2022_install` to your installation path of
142Visual Studio 2022, like
143`set vs2022_install=C:\Program Files\Microsoft Visual Studio\2022\Professional`.
Andreas Papacharalampous1d22c9612020-06-13 23:11:17144
Reilly Grant07ff22e2021-10-19 19:21:20145From a cmd.exe shell, run:
Reilly Grant07ff22e2021-10-19 19:21:20146```shell
147$ gclient
148```
149
150On first run, gclient will install all the Windows-specific bits needed to work
151with the code, including msysgit and python.
dpranke0ae7cad2016-11-30 07:47:58152
153* If you run gclient from a non-cmd shell (e.g., cygwin, PowerShell),
154 it may appear to run properly, but msysgit, python, and other tools
155 may not get installed correctly.
156* If you see strange errors with the file system on the first run of gclient,
Yuma Takaid4809d552022-02-15 03:48:19157 you may want to [disable Windows Indexing](https://tortoisesvn.net/faq.html#cantmove2).
dpranke0ae7cad2016-11-30 07:47:58158
Will Harris1c8f89c2021-03-08 22:53:43159## Check python install
160
henrikab232d892024-04-05 14:53:31161After running gclient open a command prompt and type `where python3` and
162confirm that the depot_tools `python3.bat` comes ahead of any copies of
163python3.exe. Failing to ensure this can lead to overbuilding when
dpranke0ae7cad2016-11-30 07:47:58164using gn - see [crbug.com/611087](https://crbug.com/611087).
165
Will Harris1c8f89c2021-03-08 22:53:43166[App Execution Aliases](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#alias)
167can conflict with other installations of python on the system so disable
168these for 'python.exe' and 'python3.exe' by opening 'App execution aliases'
169section of Control Panel and unticking the boxes next to both of these
170that point to 'App Installer'.
171
dpranke0ae7cad2016-11-30 07:47:58172## Get the code
173
Leonard Mosescu718c9ac2017-06-20 18:06:32174First, configure Git:
175
176```shell
177$ git config --global user.name "My Name"
178$ git config --global user.email "[email protected]"
179$ git config --global core.autocrlf false
180$ git config --global core.filemode false
Anne Redulla6a104522024-12-11 22:23:25181$ git config --global core.preloadindex true
182$ git config --global core.fscache true
Leonard Mosescu718c9ac2017-06-20 18:06:32183$ git config --global branch.autosetuprebase always
184```
185
Bruce Dawsonc2c02e52023-11-22 04:43:15186While not necessarily required it can be helpful to configure git to allow long
187path support (beyond the Windows MAX_PATH limit):
188
189```shell
190git config --global core.longpaths true
191```
192
Sonja Laurilac8949372023-06-27 10:09:23193Create a `chromium` directory for the checkout and change to it. You can call
194this whatever you like and put it wherever you like, as long as the full path
195has no spaces. However there are some performance benefits for Googlers in
196placing the directory under `C:\src\`
197(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:58198
sdy93387fa2016-12-01 01:03:44199```shell
200$ mkdir chromium && cd chromium
201```
202
203Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:58204dependencies.
205
sdy93387fa2016-12-01 01:03:44206```shell
xiaoyin.l802e4b3e2016-12-04 22:17:30207$ fetch chromium
sdy93387fa2016-12-01 01:03:44208```
dpranke0ae7cad2016-11-30 07:47:58209
210If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:44211adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:58212
Bruce Dawson2c83223e2022-10-25 21:08:22213Expect the command to take over an hour on even a fast connection, and many
214hours on slower ones. You should configure your PC so that it doesn't sleep
215or hibernate during the fetch or else errors may occur. If errors occur while
216fetching sub-repos then you can start over, or you may be able to correct them
217by going to the chromium/src directory and running this command:
218
219```shell
220$ gclient sync
221```
dpranke0ae7cad2016-11-30 07:47:58222
sdy93387fa2016-12-01 01:03:44223When `fetch` completes, it will have created a hidden `.gclient` file and a
224directory called `src` in the working directory. The remaining instructions
225assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:58226
sdy93387fa2016-12-01 01:03:44227```shell
228$ cd src
229```
dpranke0ae7cad2016-11-30 07:47:58230
sdy93387fa2016-12-01 01:03:44231*Optional*: You can also [install API
232keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
233build to talk to some Google services, but this is not necessary for most
234development and testing purposes.
dpranke0ae7cad2016-11-30 07:47:58235
dpranke1a70d0c2016-12-01 02:42:29236## Setting up the build
dpranke0ae7cad2016-11-30 07:47:58237
Junji Watanabe3ca79c72025-07-09 02:51:36238Chromium uses [Siso](https://pkg.go.dev/go.chromium.org/infra/build/siso#section-readme)
239 as its main build tool along with a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md)
Tom Bridgwatereef401542018-08-17 00:54:43240to generate `.ninja` files. You can create any number of *build directories*
241with different configurations. To create a build directory:
dpranke0ae7cad2016-11-30 07:47:58242
sdy93387fa2016-12-01 01:03:44243```shell
Andrew Williamsfa9b7d62023-03-20 15:48:28244$ gn gen out\Default
sdy93387fa2016-12-01 01:03:44245```
dpranke0ae7cad2016-11-30 07:47:58246
Junji Watanabe3ca79c72025-07-09 02:51:36247* You only have to run this once for each new build directory, Siso will
sdy93387fa2016-12-01 01:03:44248 update the build files as needed.
249* You can replace `Default` with another name, but
250 it should be a subdirectory of `out`.
Aaron Gabledad9e0f2020-01-09 19:38:52251* For other build arguments, including release settings or using an alternate
252 version of Visual Studio, see [GN build
sdy93387fa2016-12-01 01:03:44253 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58254 The default will be a debug component build matching the current host
255 operating system and CPU.
Tom Bridgwatereef401542018-08-17 00:54:43256* For more info on GN, run `gn help` on the command line or read the [quick
Andrew Williamsbbc1a1e2021-07-21 01:51:22257 start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
Juan Cruz Viotti9c7622d2021-06-30 00:27:23258
dpranke0ae7cad2016-11-30 07:47:58259### Faster builds
tfarina502f3882016-03-23 12:48:10260
dpranke0ae7cad2016-11-30 07:47:58261* Reduce file system overhead by excluding build directories from
262 antivirus and indexing software.
263* Store the build tree on a fast disk (preferably SSD).
brucedawsoncfc7fd52017-07-06 18:41:01264* The more cores the better (20+ is not excessive) and lots of RAM is needed
265(64 GB is not excessive).
tfarina502f3882016-03-23 12:48:10266
brucedawsoncfc7fd52017-07-06 18:41:01267There are some gn flags that can improve build speeds. You can specify these
268in the editor that appears when you create your output directory
Andrew Williamsfa9b7d62023-03-20 15:48:28269(`gn args out\Default`) or on the gn gen command line
270(`gn gen out\Default --args="is_component_build = true is_debug = true"`).
brucedawsoncfc7fd52017-07-06 18:41:01271Some helpful settings to consider using include:
Bruce Dawson2c83223e2022-10-25 21:08:22272* `is_component_build = true` - this uses more, smaller DLLs, and may avoid
273having to relink chrome.dll after every change.
Bruce Dawsonfcd3deb12017-07-28 17:12:20274* `enable_nacl = false` - this disables Native Client which is usually not
275needed for local builds.
Bruce Dawson2c83223e2022-10-25 21:08:22276* `target_cpu = "x86"` - x86 builds may be slightly faster than x64 builds. Note
277that if you set this but don't set `enable_nacl = false` then build times may
278get worse.
James Cook26699a92019-03-12 22:23:10279* `blink_symbol_level = 0` - turn off source-level debugging for
brucedawsoncfc7fd52017-07-06 18:41:01280blink to reduce build times, appropriate if you don't plan to debug blink.
Bruce Dawson63e0be72021-11-29 20:34:41281* `v8_symbol_level = 0` - turn off source-level debugging for v8 to reduce
282build times, appropriate if you don't plan to debug v8.
brucedawsoncfc7fd52017-07-06 18:41:01283
Bruce Dawson817f47fb2020-05-01 22:29:08284In order to speed up linking you can set `symbol_level = 1` or
285`symbol_level = 0` - these options reduce the work the compiler and linker have
286to do. With `symbol_level = 1` the compiler emits file name and line number
287information so you can still do source-level debugging but there will be no
288local variable or type information. With `symbol_level = 0` there is no
289source-level debugging but call stacks still have function names. Changing
290`symbol_level` requires recompiling everything.
brucedawsoncfc7fd52017-07-06 18:41:01291
Junji Watanabe3ca79c72025-07-09 02:51:36292When you build, specify `chrome` as the target to avoid building all test
Andrew Williams54da9cc2024-01-09 17:32:23293binaries as well.
294
Junji Watanabe3ca79c72025-07-09 02:51:36295#### Use Remote Execution
Ben Segall4a89ec52023-09-26 15:02:56296
Junji Watanabe3ca79c72025-07-09 02:51:36297In addition, Google employees should use RBE, a remote execution system. Detailed information is available internally but the relevant gn arg is:
Ben Segall4a89ec52023-09-26 15:02:56298* `use_remoteexec = true`
299
Solomon Kinard5cd00762023-11-04 00:47:19300Google employees can visit
Andrew Williams54da9cc2024-01-09 17:32:23301[go/building-chrome-win#setup-remote-execution](https://goto.google.com/building-chrome-win#setup-remote-execution)
Junji Watanabe3ca79c72025-07-09 02:51:36302for more information. For external contributors, remote execution for Windows builds is not supported.
Ben Segall4a89ec52023-09-26 15:02:56303
Juan Cruz Viotti9c7622d2021-06-30 00:27:23304#### Use SCCACHE
305
306You might be able to use [sccache](https://github.com/mozilla/sccache) for the
307build process by enabling the following arguments:
308
309* `cc_wrapper = "sccache"` - assuming the `sccache` binary is in your `%PATH%`
Juan Cruz Viotti9c7622d2021-06-30 00:27:23310
Bruce Dawsone9f20fff2018-03-03 01:58:38311### Why is my build slow?
312
313Many things can make builds slow, with Windows Defender slowing process startups
314being a frequent culprit. Have you ensured that the entire Chromium src
Bruce Dawson0bbe2d42018-03-06 19:45:55315directory is excluded from antivirus scanning (on Google machines this means
Bruce Dawsone9f20fff2018-03-03 01:58:38316putting it in a ``src`` directory in the root of a drive)? Have you tried the
317different settings listed above, including different link settings and -j
318values? Have you asked on the chromium-dev mailing list to see if your build is
319slower than expected for your machine's specifications?
320
Bruce Dawson15104782023-10-19 20:06:23321If you suspect that Defender is slowing your build then you can try Microsoft's
322[Performance analyzer for Microsoft Defender Antivirus](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/tune-performance-defender-antivirus?view=o365-worldwide)
323to investigate in detail.
324
Junji Watanabe3ca79c72025-07-09 02:51:36325Siso prints progress while building Chrome. It shows how many build processes
326are running at any given time, how many build steps have completed, how many
327 build steps have completed per second, and how long the entire build and
328 the longest build step has been running, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38329
330```shell
Bruce Dawsone9f20fff2018-03-03 01:58:38331$ autoninja -C out\Default base
332ninja: Entering directory `out\Default'
Junji Watanabe3ca79c72025-07-09 02:51:36333...
334pre:0 local:0 remote:6461 15.6/s cache: 0.00% fallback:0
335[3829/64499] 4m47.48s 4m00.35s[remote]: LINK(DLL) base.dll base.dll.lib base.dll.pdb
Bruce Dawsone9f20fff2018-03-03 01:58:38336```
337
Bruce Dawson89390172019-05-08 09:51:18338This makes slow process creation immediately obvious and lets you tell quickly
339if a build is running more slowly than normal.
340
341In addition, setting ``NINJA_SUMMARIZE_BUILD=1`` tells ``autoninja`` to print a
342build performance summary when the build completes, showing the slowest build
343steps and slowest build-step types, as shown here:
Bruce Dawsone9f20fff2018-03-03 01:58:38344
345```shell
346$ set NINJA_SUMMARIZE_BUILD=1
347$ autoninja -C out\Default base
Bruce Dawson2721f0b2019-11-08 18:41:27348Longest build steps:
349 0.1 weighted s to build obj/base/base/trace_log.obj (6.7 s elapsed time)
350 0.2 weighted s to build nasm.exe, nasm.exe.pdb (0.2 s elapsed time)
351 0.3 weighted s to build obj/base/base/win_util.obj (12.4 s elapsed time)
352 1.2 weighted s to build base.dll, base.dll.lib (1.2 s elapsed time)
353Time by build-step type:
354 0.0 s weighted time to generate 6 .lib files (0.3 s elapsed time sum)
355 0.1 s weighted time to generate 25 .stamp files (1.2 s elapsed time sum)
356 0.2 s weighted time to generate 20 .o files (2.8 s elapsed time sum)
357 1.7 s weighted time to generate 4 PEFile (linking) files (2.0 s elapsed
358time sum)
359 23.9 s weighted time to generate 770 .obj files (974.8 s elapsed time sum)
36026.1 s weighted time (982.9 s elapsed time sum, 37.7x parallelism)
361839 build steps completed, average of 32.17/s
Bruce Dawsone9f20fff2018-03-03 01:58:38362```
363
Bruce Dawson2721f0b2019-11-08 18:41:27364The "weighted" time is the elapsed time of each build step divided by the number
365of tasks that were running in parallel. This makes it an excellent approximation
366of how "important" a slow step was. A link that is entirely or mostly serialized
367will have a weighted time that is the same or similar to its elapsed time. A
368compile that runs in parallel with 999 other compiles will have a weighted time
369that is tiny.
370
Devon Loehrc0acd932024-10-21 18:15:20371You can also generate these reports by manually running the script after a
372build:
Bruce Dawson0bbe2d42018-03-06 19:45:55373
374```shell
375$ python depot_tools\post_build_ninja_summary.py -C out\Default
376```
377
Bruce Dawsonb9988e92019-09-16 17:01:10378You can also get a visual report of the build performance with
Junji Watanabe3ca79c72025-07-09 02:51:36379[perfetto](https://ui.perfetto.dev/) by uploading `.ninja_log` or
380 `siso_trace.json`.
Bruce Dawsonb9988e92019-09-16 17:01:10381
dpranke0ae7cad2016-11-30 07:47:58382## Build Chromium
383
Max Morozf5b31fcd2018-08-10 21:55:48384Build Chromium (the "chrome" target) with Ninja using the command:
dpranke0ae7cad2016-11-30 07:47:58385
dpranke1a70d0c2016-12-01 02:42:29386```shell
Max Morozf5b31fcd2018-08-10 21:55:48387$ autoninja -C out\Default chrome
dpranke1a70d0c2016-12-01 02:42:29388```
dpranke0ae7cad2016-11-30 07:47:58389
Max Morozf5b31fcd2018-08-10 21:55:48390`autoninja` is a wrapper that automatically provides optimal values for the
391arguments passed to `ninja`.
392
dpranke0ae7cad2016-11-30 07:47:58393You can get a list of all of the other build targets from GN by running
Andrew Williamsfa9b7d62023-03-20 15:48:28394`gn ls out\Default` from the command line. To compile one, pass to Ninja
dpranke0ae7cad2016-11-30 07:47:58395the GN label with no preceding "//" (so for `//chrome/test:unit_tests`
Andrew Williamsfa9b7d62023-03-20 15:48:28396use `autoninja -C out\Default chrome/test:unit_tests`).
dpranke0ae7cad2016-11-30 07:47:58397
Junji Watanabedb7caa62024-04-22 08:15:34398## Compile a single file
399
Lalit Rana8bd378e2024-08-19 19:34:37400Ninja supports a special [syntax `^`][ninja hat syntax] to compile a single
401object file specifying the source file. For example, `ninja -C
402out/Default ../../base/logging.cc^` compiles `obj/base/base/logging.o`.
Junji Watanabedb7caa62024-04-22 08:15:34403
404[ninja hat syntax]: https://ninja-build.org/manual.html#:~:text=There%20is%20also%20a%20special%20syntax%20target%5E%20for%20specifying%20a%20target%20as%20the%20first%20output%20of%20some%20rule%20containing%20the%20source%20you%20put%20in%20the%20command%20line%2C%20if%20one%20exists.%20For%20example%2C%20if%20you%20specify%20target%20as%20foo.c%5E%20then%20foo.o%20will%20get%20built%20(assuming%20you%20have%20those%20targets%20in%20your%20build%20files)
405
406With autoninja, you need to add `^^` to preserve the trailing `^`.
407
408```shell
409$ autoninja -C out\Default ..\..\base\logging.cc^^
410```
411
412In addition to `foo.cc^^`, Siso also supports `foo.h^^` syntax to compile
413the corresponding `foo.o` if it exists.
414
Peter Kastinga8ddeee2024-08-09 08:42:33415If you run a `bash` shell, you can use the following script to ease invocation:
416
417```shell
418#!/bin/sh
419files=("${@/#/..\/..\/}")
420autoninja -C out/Default ${files[@]/%/^^}
421```
422
423This script assumes it is run from `src` and your output dir is `out/Default`;
424it invokes `autoninja` to compile all given files. If you place it in your
425`$PATH` and name it e.g. `compile`, you can invoke like this:
426
427```shell
428$ pwd # Just to illustrate where this is run from
429/c/src
430$ compile base/time/time.cc base/time/time_unittest.cc
431...
432[0/47] 5.56s S CXX obj/base/base/time.obj
433...
434[2/3] 9.27s S CXX obj/base/base_unittests/time_unittest.obj
435...
436```
437
dpranke0ae7cad2016-11-30 07:47:58438## Run Chromium
439
440Once it is built, you can simply run the browser:
441
dpranke1a70d0c2016-12-01 02:42:29442```shell
443$ out\Default\chrome.exe
444```
445
446(The ".exe" suffix in the command is actually optional).
dpranke0ae7cad2016-11-30 07:47:58447
448## Running test targets
449
Andrew Williamsfa9b7d62023-03-20 15:48:28450Tests are split into multiple test targets based on their type and where they
451exist in the directory structure. To see what target a given unit test or
452browser test file corresponds to, the following command can be used:
dpranke0ae7cad2016-11-30 07:47:58453
dpranke1a70d0c2016-12-01 02:42:29454```shell
Andrew Williamsfa9b7d62023-03-20 15:48:28455$ gn refs out\Default --testonly=true --type=executable --all chrome\browser\ui\browser_list_unittest.cc
456//chrome/test:unit_tests
457```
458
459In the example above, the target is unit_tests. The unit_tests binary can be
460built by running the following command:
461
462```shell
463$ autoninja -C out\Default unit_tests
464```
465
466You can run the tests by running the unit_tests binary. You can also limit which
467tests are run using the `--gtest_filter` arg, e.g.:
468
469```shell
470$ out\Default\unit_tests.exe --gtest_filter="BrowserListUnitTest.*"
dpranke1a70d0c2016-12-01 02:42:29471```
dpranke0ae7cad2016-11-30 07:47:58472
473You can find out more about GoogleTest at its
474[GitHub page](https://github.com/google/googletest).
475
Greg Thompson530c2a92024-07-16 14:03:33476## Build an Installer
477
478Build the `mini_installer` target to create a self-contained installer. This
479has everything needed to install your browser on a machine.
480
481```shell
482$ autoninja -C out\Default mini_installer
483```
484
485See [//chrome/installer/setup/README.md](../chrome/installer/setup/README.md)
486and [//chrome/installer/mini_installer/README.md](../chrome/installer/mini_installer/README.md)
487for more information.
488
dpranke0ae7cad2016-11-30 07:47:58489## Update your checkout
490
491To update an existing checkout, you can run
492
dpranke1a70d0c2016-12-01 02:42:29493```shell
494$ git rebase-update
Bruce Dawsonef0b5452020-10-03 00:13:09495$ gclient sync -D
dpranke1a70d0c2016-12-01 02:42:29496```
dpranke0ae7cad2016-11-30 07:47:58497
498The first command updates the primary Chromium source repository and rebases
Andrew Williamsbbc1a1e2021-07-21 01:51:22499any of your local branches on top of tip-of-tree (aka the Git branch
500`origin/main`). If you don't want to use this script, you can also just use
501`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58502
Bruce Dawsonef0b5452020-10-03 00:13:09503The second command syncs the subrepositories to the appropriate versions,
504deleting those that are no longer needed, and re-runs the hooks as needed.
505
506### Editing and Debugging With the Visual Studio IDE
507
508You can use the Visual Studio IDE to edit and debug Chrome, with or without
509Intellisense support.
510
511#### Using Visual Studio Intellisense
512
513If you want to use Visual Studio Intellisense when developing Chromium, use the
514`--ide` command line argument to `gn gen` when you generate your output
515directory (as described on the [get the code](https://dev.chromium.org/developers/how-tos/get-the-code)
Junji Watanabe0f6489c72023-02-01 04:02:11516page). This is an example when your checkout is `C:\src\chromium` and your
517output directory is `out\Default`:
Bruce Dawsonef0b5452020-10-03 00:13:09518
519```shell
Junji Watanabe3ca79c72025-07-09 02:51:36520$ gn gen --ide=vs --ninja-executable=autoninja out\Default
Bruce Dawsonef0b5452020-10-03 00:13:09521$ devenv out\Default\all.sln
522```
523
524GN will produce a file `all.sln` in your build directory. It will internally
525use Ninja to compile while still allowing most IDE functions to work (there is
526no native Visual Studio compilation mode). If you manually run "gen" again you
527will need to resupply this argument, but normally GN will keep the build and
528IDE files up to date automatically when you build.
529
530The generated solution will contain several thousand projects and will be very
531slow to load. Use the `--filters` argument to restrict generating project files
532for only the code you're interested in. Although this will also limit what
533files appear in the project explorer, debugging will still work and you can
534set breakpoints in files that you open manually. A minimal solution that will
535let you compile and run Chrome in the IDE but will not show any source files
536is:
537
538```
Junji Watanabe3ca79c72025-07-09 02:51:36539$ gn gen --ide=vs --ninja-executable=autoninja --filters=//chrome --no-deps out\Default
Bruce Dawsonef0b5452020-10-03 00:13:09540```
541
542You can selectively add other directories you care about to the filter like so:
543`--filters=//chrome;//third_party/WebKit/*;//gpu/*`.
544
545There are other options for controlling how the solution is generated, run `gn
546help gen` for the current documentation.
547
548#### Using Visual Studio without Intellisense
549
550It is also possible to debug and develop Chrome in Visual Studio without the
551overhead of a multi-project solution file. Simply "open" your chrome.exe binary
552with `File->Open->Project/Solution`, or from a Visual Studio command prompt like
553so: `devenv /debugexe out\Debug\chrome.exe <your arguments>`. Many of Visual
554Studio's code exploration features will not work in this configuration, but by
555installing the [VsChromium Visual Studio Extension](https://chromium.github.io/vs-chromium/)
556you can get the source code to appear in the solution explorer window along
557with other useful features such as code search. You can add multiple executables
558of interest (base_unittests.exe, browser_tests.exe) to your solution with
559`File->Add->Existing Project...` and change which one will be debugged by
560right-clicking on them in `Solution Explorer` and selecting `Set as Startup
561Project`. You can also change their properties, including command line
562arguments, by right-clicking on them in `Solution Explorer` and selecting
563`Properties`.
564
565By default when you start debugging in Visual Studio the debugger will only
566attach to the main browser process. To debug all of Chrome, install
567[Microsoft's Child Process Debugging Power Tool](https://blogs.msdn.microsoft.com/devops/2014/11/24/introducing-the-child-process-debugging-power-tool/).
568You will also need to run Visual Studio as administrator, or it will silently
569fail to attach to some of Chrome's child processes.
570
Bruce Dawson425d4ab2023-06-25 01:36:15571### Improving performance of git commands
Avi Drissmanc0f6793ac2023-05-26 19:22:44572
573#### Configure git to use an untracked cache
574
Bruce Dawson2154274a2023-06-17 22:24:29575Try running
Avi Drissmanc0f6793ac2023-05-26 19:22:44576
577```shell
578$ git update-index --test-untracked-cache
579```
580
581If the output ends with `OK`, then the following may also improve performance of
582`git status`:
583
584```shell
585$ git config core.untrackedCache true
586```
587
Avi Drissmanc0f6793ac2023-05-26 19:22:44588#### Configure git to use fsmonitor
589
Bruce Dawson2154274a2023-06-17 22:24:29590You can significantly speed up git by using [fsmonitor.](https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/)
591You should enable fsmonitor in large repos, such as Chromium and v8. Enabling
592it globally will launch many processes and consume excess commit/memory and
593probably isn't worthwhile. The command to enable fsmonitor in the current repo
594is:
Avi Drissmanc0f6793ac2023-05-26 19:22:44595
596```shell
597$ git config core.fsmonitor true
598```