blob: 731b2dca1eae1257b75c58f4cc3f640111ba22e8 [file] [log] [blame] [view]
dpranke1a70d0c2016-12-01 02:42:291# Checking out and building Chromium for Mac
andybons3322f762015-08-24 21:37:092
erikchen7d7509a2017-10-02 23:40:363There are instructions for other platforms linked from the
dpranke1a70d0c2016-12-01 02:42:294[get the code](get_the_code.md) page.
5
dpranke1a70d0c2016-12-01 02:42:296## Instructions for Google Employees
7
8Are you a Google employee? See
9[go/building-chrome](https://goto.google.com/building-chrome) instead.
dpranke0ae7cad2016-11-30 07:47:5810
andybonsad92aa32015-08-31 02:27:4411[TOC]
andybons3322f762015-08-24 21:37:0912
dpranke0ae7cad2016-11-30 07:47:5813## System requirements
sdya8197bd22016-09-14 19:06:4214
Nico Weber3c9befa2021-11-03 17:07:1115* A Mac, Intel or Arm.
Avi Drissmanab7729b2021-06-10 19:17:1516 ([More details about Arm Macs](https://chromium.googlesource.com/chromium/src.git/+/main/docs/mac_arm64.md).)
Nico Weber3c9befa2021-11-03 17:07:1117* [Xcode](https://developer.apple.com/xcode/). Xcode comes with...
18* The macOS SDK. Run
sdy93387fa2016-12-01 01:03:4419
erikchen7d7509a2017-10-02 23:40:3620 ```shell
sdy93387fa2016-12-01 01:03:4421 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0322 ```
erikchen7d7509a2017-10-02 23:40:3623
Nico Weber3c9befa2021-11-03 17:07:1124 to check whether you have it, and what version you have.
25 `mac_sdk_official_version` in [mac_sdk.gni](../build/config/mac/mac_sdk.gni)
26 is the SDK version used on all the bots and for
27 [official builds](https://source.chromium.org/search?q=MAC_BINARIES_LABEL&ss=chromium),
28 so that version is guaranteed to work. Building with a newer SDK usually
29 works too (please fix or file a bug if it doesn't).
wafuwafu13b6854ba52021-12-24 06:02:4330
Nico Weber3c9befa2021-11-03 17:07:1131 Building with an older SDK might also work, but if it doesn't then we won't
32 accept changes for making it work.
wafuwafu13b6854ba52021-12-24 06:02:4333
Nico Weber3c9befa2021-11-03 17:07:1134 The easiest way to get the newest SDK is to use the newest version of Xcode,
35 which often requires using the newest version of macOS. We don't use Xcode
36 itself much, so if you're know what you're doing, you can likely get the
37 build working with an older version of macOS as long as you get a new
38 version of the macOS SDK on it.
Nico Weber36cd0a552022-01-18 16:31:4939* An APFS-formatted volume (this is the default format for macOS volumes).
andybons3322f762015-08-24 21:37:0940
dpranke0ae7cad2016-11-30 07:47:5841## Install `depot_tools`
andybons3322f762015-08-24 21:37:0942
sdy93387fa2016-12-01 01:03:4443Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0944
sdy93387fa2016-12-01 01:03:4445```shell
46$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
47```
andybons3322f762015-08-24 21:37:0948
Gabriel Charetteb6780c12019-04-24 16:23:5249Add `depot_tools` to the end of your PATH (you will probably want to put this in
50your `~/.bash_profile` or `~/.zshrc`). Assuming you cloned `depot_tools` to
51`/path/to/depot_tools` (note: you **must** use the absolute path or Python will
52not be able to find infra tools):
dpranke0ae7cad2016-11-30 07:47:5853
sdy93387fa2016-12-01 01:03:4454```shell
55$ export PATH="$PATH:/path/to/depot_tools"
56```
dpranke0ae7cad2016-11-30 07:47:5857
58## Get the code
59
sdy93387fa2016-12-01 01:03:4460Create a `chromium` directory for the checkout and change to it (you can call
61this whatever you like and put it wherever you like, as long as the full path
62has no spaces):
dpranke0ae7cad2016-11-30 07:47:5863
sdy93387fa2016-12-01 01:03:4464```shell
65$ mkdir chromium && cd chromium
66```
67
68Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5869dependencies.
70
sdy93387fa2016-12-01 01:03:4471```shell
David Sanderse3827172022-02-08 15:48:5672$ caffeinate fetch chromium
sdy93387fa2016-12-01 01:03:4473```
dpranke0ae7cad2016-11-30 07:47:5874
David Sanderse3827172022-02-08 15:48:5675Running the `fetch` with `caffeinate` is optional, but it will prevent the
76system from sleeping for the duration of the `fetch` command, which may run for
77a considerable amount of time.
78
[email protected]1436b952018-10-26 16:35:1379If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1980`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
81the full history later.
dpranke0ae7cad2016-11-30 07:47:5882
sdy93387fa2016-12-01 01:03:4483Expect the command to take 30 minutes on even a fast connection, and many
84hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5885
sdy93387fa2016-12-01 01:03:4486When `fetch` completes, it will have created a hidden `.gclient` file and a
87directory called `src` in the working directory. The remaining instructions
88assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5889
sdy93387fa2016-12-01 01:03:4490```shell
91$ cd src
92```
93
94*Optional*: You can also [install API
95keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
96build to talk to some Google services, but this is not necessary for most
97development and testing purposes.
andybons3322f762015-08-24 21:37:0998
dpranke1a70d0c2016-12-01 02:42:2999## Setting up the build
andybons3322f762015-08-24 21:37:09100
Tom Bridgwatereef401542018-08-17 00:54:43101Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
Andrew Williamsbbc1a1e2021-07-21 01:51:22102a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md)
Tom Bridgwatereef401542018-08-17 00:54:43103to generate `.ninja` files. You can create any number of *build directories*
104with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:44105
sdy93387fa2016-12-01 01:03:44106```shell
107$ gn gen out/Default
108```
thakisf28551b2016-08-09 14:42:55109
sdy93387fa2016-12-01 01:03:44110* You only have to run this once for each new build directory, Ninja will
111 update the build files as needed.
112* You can replace `Default` with another name, but
113 it should be a subdirectory of `out`.
114* For other build arguments, including release settings, see [GN build
115 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58116 The default will be a debug component build matching the current host
117 operating system and CPU.
118* For more info on GN, run `gn help` on the command line or read the
Andrew Williamsbbc1a1e2021-07-21 01:51:22119 [quick start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
Reilly Grantf057adf2020-11-03 17:42:37120* Building Chromium for arm Macs requires [additional setup](mac_arm64.md).
thakisf28551b2016-08-09 14:42:55121
thakisf28551b2016-08-09 14:42:55122
dpranke0ae7cad2016-11-30 07:47:58123### Faster builds
andybons3322f762015-08-24 21:37:09124
andybonsad92aa32015-08-31 02:27:44125Full rebuilds are about the same speed in Debug and Release, but linking is a
126lot faster in Release builds.
andybons3322f762015-08-24 21:37:09127
thakisf28551b2016-08-09 14:42:55128Put
andybons3322f762015-08-24 21:37:09129
sdy93387fa2016-12-01 01:03:44130```
131is_debug = false
132```
andybons3322f762015-08-24 21:37:09133
sdy93387fa2016-12-01 01:03:44134in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55135
136Put
137
sdy93387fa2016-12-01 01:03:44138```
139is_component_build = true
140```
thakisf28551b2016-08-09 14:42:55141
sdy93387fa2016-12-01 01:03:44142in your `args.gn` to build many small dylibs instead of a single large
143executable. This makes incremental builds much faster, at the cost of producing
144a binary that opens less quickly. Component builds work in both debug and
145release.
thakisf28551b2016-08-09 14:42:55146
147Put
148
sdy93387fa2016-12-01 01:03:44149```
150symbol_level = 0
151```
thakisf28551b2016-08-09 14:42:55152
153in your args.gn to disable debug symbols altogether. This makes both full
154rebuilds and linking faster (at the cost of not getting symbolized backtraces
155in gdb).
andybons3322f762015-08-24 21:37:09156
Andrew Williams54da9cc2024-01-09 17:32:23157#### Use Reclient
158
159In addition, Google employees should use Reclient, a distributed compilation system.
160Detailed information is available internally but the relevant gn arg is:
161* `use_remoteexec = true`
162
163Google employees can visit
164[go/building-chrome-mac#using-remote-execution](https://goto.google.com/building-chrome-mac#using-remote-execution)
165for more information. For external contributors, Reclient does not support Mac
166builds.
167
Philip Rogerseb841682017-10-09 16:08:50168#### CCache
169
philipj5a0fcb92016-01-23 23:23:40170You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09171
dpranke1a70d0c2016-12-01 02:42:29172## Build Chromium
173
174Build Chromium (the "chrome" target) with Ninja using the command:
175
176```shell
Max Morozf5b31fcd2018-08-10 21:55:48177$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29178```
179
Dirk Pranke8bd55f22018-10-24 21:22:10180(`autoninja` is a wrapper that automatically provides optimal values for the
181arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48182
dpranke1a70d0c2016-12-01 02:42:29183You can get a list of all of the other build targets from GN by running `gn ls
184out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48185with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29186out/Default chrome/test:unit_tests`).
187
dpranke0ae7cad2016-11-30 07:47:58188## Run Chromium
andybons3322f762015-08-24 21:37:09189
dpranke0ae7cad2016-11-30 07:47:58190Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09191
sdy93387fa2016-12-01 01:03:44192```shell
Owen Min83eda1102017-06-28 18:47:21193$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44194```
andybons3322f762015-08-24 21:37:09195
Kai Ninomiyac52b6bc2022-05-10 23:27:43196## Avoiding system permissions dialogs after each build
Dominic Mazzonia7494a52020-08-06 19:19:11197
Kai Ninomiyac52b6bc2022-05-10 23:27:43198Every time you start a new developer build, you may get two system dialogs:
199`Chromium wants to use your confidential information stored in "Chromium Safe
200Storage" in your keychain.`, and `Do you want the application "Chromium.app" to
201accept incoming network connections?`.
Dominic Mazzonia7494a52020-08-06 19:19:11202
Kai Ninomiyac52b6bc2022-05-10 23:27:43203To avoid them, you can run Chromium with these command-line flags (but of
204course beware that they will change the behavior of certain subsystems):
205
206```shell
207--use-mock-keychain --disable-features=DialMediaRouteProvider
208```
Dominic Mazzonia7494a52020-08-06 19:19:11209
wafuwafu13b6854ba52021-12-24 06:02:43210## Build and run test targets
andybons3322f762015-08-24 21:37:09211
Andrew Williamsfa9b7d62023-03-20 15:48:28212Tests are split into multiple test targets based on their type and where they
213exist in the directory structure. To see what target a given unit test or
214browser test file corresponds to, the following command can be used:
215
216```shell
217$ gn refs out/Default --testonly=true --type=executable --all chrome/browser/ui/browser_list_unittest.cc
218//chrome/test:unit_tests
219```
220
221In the example above, the target is unit_tests. The unit_tests binary can be
222built by running the following command:
wafuwafu13b6854ba52021-12-24 06:02:43223
224```shell
225$ autoninja -C out/Default unit_tests
226```
227
Andrew Williamsfa9b7d62023-03-20 15:48:28228You can run the tests by running the unit_tests binary. You can also limit which
229tests are run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09230
Andrew Williamsfa9b7d62023-03-20 15:48:28231```shell
232$ out/Default/unit_tests --gtest_filter="BrowserListUnitTest.*"
sdy93387fa2016-12-01 01:03:44233```
andybons3322f762015-08-24 21:37:09234
dpranke0ae7cad2016-11-30 07:47:58235You can find out more about GoogleTest at its
236[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09237
andybonsad92aa32015-08-31 02:27:44238## Debugging
andybons3322f762015-08-24 21:37:09239
Robert Sesek3b731b12021-04-14 21:54:03240Good debugging tips can be found [here](mac/debugging.md).
Vaclav Brozek539499e2018-07-18 11:19:51241
dpranke0ae7cad2016-11-30 07:47:58242## Update your checkout
andybonsad92aa32015-08-31 02:27:44243
dpranke0ae7cad2016-11-30 07:47:58244To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44245
sdy93387fa2016-12-01 01:03:44246```shell
247$ git rebase-update
248$ gclient sync
249```
dpranke0ae7cad2016-11-30 07:47:58250
251The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44252any of your local branches on top of tip-of-tree (aka the Git branch
Andrew Williamsbbc1a1e2021-07-21 01:51:22253`origin/main`). If you don't want to use this script, you can also just use
sdy93387fa2016-12-01 01:03:44254`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58255
sdy93387fa2016-12-01 01:03:44256The second command syncs dependencies to the appropriate versions and re-runs
257hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58258
259## Tips, tricks, and troubleshooting
260
261### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44262
sdy93387fa2016-12-01 01:03:44263While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55264for building, but Xcode for editing and driving compilation. Xcode is still
265slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44266build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44267
sdy93387fa2016-12-01 01:03:44268With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10269the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00270target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09271
sdy93387fa2016-12-01 01:03:44272To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24273
274```shell
sdy93387fa2016-12-01 01:03:44275$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24276```
andybons3322f762015-08-24 21:37:09277
thakisf28551b2016-08-09 14:42:55278Open it:
tfarina59fb57ac2016-03-02 18:17:24279
280```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00281$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24282```
andybons3322f762015-08-24 21:37:09283
andybonsad92aa32015-08-31 02:27:44284You may run into a problem where http://YES is opened as a new tab every time
285you launch Chrome. To fix this, open the scheme editor for the Run scheme,
286choose the Options tab, and uncheck "Allow debugging when using document
287Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44288`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
289gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09290
andybonsad92aa32015-08-31 02:27:44291If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44292ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17293[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44294tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09295
Bruce Dawson425d4ab2023-06-25 01:36:15296### Improving performance of git commands
shess1f4c3d92015-11-05 18:15:37297
ishermance1d9d82017-05-12 23:10:04298#### Increase the vnode cache size
299
shess1f4c3d92015-11-05 18:15:37300`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44301to the large number of files in Chromium's checkout, `git status` performance
302can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37303default, this command:
304
sdy93387fa2016-12-01 01:03:44305```shell
Steve Kobes11a670a2022-03-25 21:49:09306$ sysctl -a | egrep 'kern\..*vnodes'
sdy93387fa2016-12-01 01:03:44307```
shess1f4c3d92015-11-05 18:15:37308
309Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
310setting:
311
sdy93387fa2016-12-01 01:03:44312```shell
313$ sudo sysctl kern.maxvnodes=$((512*1024))
314```
shess1f4c3d92015-11-05 18:15:37315
316Higher values may be appropriate if you routinely move between different
Steve Kobes11a670a2022-03-25 21:49:09317Chromium checkouts. This setting will reset on reboot. To apply it at startup:
shess1f4c3d92015-11-05 18:15:37318
sdy93387fa2016-12-01 01:03:44319```shell
Steve Kobes11a670a2022-03-25 21:49:09320$ sudo tee /Library/LaunchDaemons/kern.maxvnodes.plist > /dev/null <<EOF
321<?xml version="1.0" encoding="UTF-8"?>
322<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
323<plist version="1.0">
324 <dict>
325 <key>Label</key>
326 <string>kern.maxvnodes</string>
327 <key>ProgramArguments</key>
328 <array>
329 <string>sysctl</string>
330 <string>kern.maxvnodes=524288</string>
331 </array>
332 <key>RunAtLoad</key>
333 <true/>
334 </dict>
335</plist>
336EOF
sdy93387fa2016-12-01 01:03:44337```
shess1f4c3d92015-11-05 18:15:37338
339Or edit the file directly.
340
ishermance1d9d82017-05-12 23:10:04341#### Configure git to use an untracked cache
342
Bruce Dawson2154274a2023-06-17 22:24:29343Try running
ishermance1d9d82017-05-12 23:10:04344
345```shell
346$ git update-index --test-untracked-cache
347```
348
349If the output ends with `OK`, then the following may also improve performance of
350`git status`:
351
352```shell
353$ git config core.untrackedCache true
354```
355
Avi Drissmanc0f6793ac2023-05-26 19:22:44356#### Configure git to use fsmonitor
357
Bruce Dawson2154274a2023-06-17 22:24:29358You can significantly speed up git by using [fsmonitor.](https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/)
359You should enable fsmonitor in large repos, such as Chromium and v8. Enabling
Avi Drissman9908ae442023-09-29 16:31:11360it globally will launch many processes and probably isn't worthwhile. Be sure
361you have at least version 2.43 (fsmonitor on the Mac is broken before then). The
Bruce Dawson2154274a2023-06-17 22:24:29362command to enable fsmonitor in the current repo is:
Avi Drissmanc0f6793ac2023-05-26 19:22:44363
364```shell
365$ git config core.fsmonitor true
366```
367
dpranke0ae7cad2016-11-30 07:47:58368### Xcode license agreement
tnagelcad631692016-04-15 11:02:36369
370If you're getting the error
371
sdy93387fa2016-12-01 01:03:44372> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
373> root via sudo.
tnagelcad631692016-04-15 11:02:36374
375the Xcode license hasn't been accepted yet which (contrary to the message) any
376user can do by running:
377
sdy93387fa2016-12-01 01:03:44378```shell
379$ xcodebuild -license
380```
tnagelcad631692016-04-15 11:02:36381
382Only accepting for all users of the machine requires root:
383
sdy93387fa2016-12-01 01:03:44384```shell
385$ sudo xcodebuild -license
386```
David Sandersaa3fdeb702022-05-26 14:42:18387
388### Exclude checkout from Spotlight indexing
389
390Chromium's checkout contains a lot of files, and building generates many more.
391Spotlight will try to index all of those files, and uses a lot of CPU time
392doing so, especially during a build, which can slow things down.
393
394To prevent the Chromium checkout from being indexed by Spotlight, open System
395Preferences, go to "Spotlight" -> "Privacy" and add your Chromium checkout
396directory to the list of excluded locations.