blob: 33f78ca0d61d0a821f866662af7d4572a08ca84d [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
Avi Drissman1a520bf2020-12-08 19:00:4715* A 64-bit Intel Mac running 10.15.4+. (Building on Arm Macs is
16 [not yet supported](https://chromium.googlesource.com/chromium/src.git/+/master/docs/mac_arm64.md).)
17* [Xcode](https://developer.apple.com/xcode/) 12.2+. This version of Xcode
18 comes with ...
19* The macOS 11.0 SDK. Run
sdy93387fa2016-12-01 01:03:4420
erikchen7d7509a2017-10-02 23:40:3621 ```shell
sdy93387fa2016-12-01 01:03:4422 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0323 ```
erikchen7d7509a2017-10-02 23:40:3624
Avi Drissman1a520bf2020-12-08 19:00:4725 to check whether you have it. Building with a newer SDK usually works too
26 (please fix it if it doesn't), but the releases
27 [currently use Xcode 12.2](https://source.chromium.org/search?q=MAC_BINARIES_LABEL&ss=chromium)
28 and the macOS 11.0 SDK.
andybons3322f762015-08-24 21:37:0929
dpranke0ae7cad2016-11-30 07:47:5830## Install `depot_tools`
andybons3322f762015-08-24 21:37:0931
sdy93387fa2016-12-01 01:03:4432Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0933
sdy93387fa2016-12-01 01:03:4434```shell
35$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
36```
andybons3322f762015-08-24 21:37:0937
Gabriel Charetteb6780c12019-04-24 16:23:5238Add `depot_tools` to the end of your PATH (you will probably want to put this in
39your `~/.bash_profile` or `~/.zshrc`). Assuming you cloned `depot_tools` to
40`/path/to/depot_tools` (note: you **must** use the absolute path or Python will
41not be able to find infra tools):
dpranke0ae7cad2016-11-30 07:47:5842
sdy93387fa2016-12-01 01:03:4443```shell
44$ export PATH="$PATH:/path/to/depot_tools"
45```
dpranke0ae7cad2016-11-30 07:47:5846
47## Get the code
48
Aaron Gable94b7e2a32018-01-03 19:14:4149Ensure that unicode filenames aren't mangled by HFS:
50
51```shell
52$ git config --global core.precomposeUnicode true
53```
54
L. David Baron8d606c542021-03-05 19:56:0755In System Preferences, check that "Energy Saver" -> "Power Adapter" ->
56"Prevent computer from sleeping automatically when the display is off" is
57checked so that your laptop doesn't go to sleep and interrupt the long network
58connection needed here.
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
72$ fetch chromium
73```
dpranke0ae7cad2016-11-30 07:47:5874
[email protected]1436b952018-10-26 16:35:1375If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1976`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
77the full history later.
dpranke0ae7cad2016-11-30 07:47:5878
sdy93387fa2016-12-01 01:03:4479Expect the command to take 30 minutes on even a fast connection, and many
80hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5881
sdy93387fa2016-12-01 01:03:4482When `fetch` completes, it will have created a hidden `.gclient` file and a
83directory called `src` in the working directory. The remaining instructions
84assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5885
sdy93387fa2016-12-01 01:03:4486```shell
87$ cd src
88```
89
90*Optional*: You can also [install API
91keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
92build to talk to some Google services, but this is not necessary for most
93development and testing purposes.
andybons3322f762015-08-24 21:37:0994
dpranke1a70d0c2016-12-01 02:42:2995## Setting up the build
andybons3322f762015-08-24 21:37:0996
Tom Bridgwatereef401542018-08-17 00:54:4397Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
98a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
99to generate `.ninja` files. You can create any number of *build directories*
100with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:44101
sdy93387fa2016-12-01 01:03:44102```shell
103$ gn gen out/Default
104```
thakisf28551b2016-08-09 14:42:55105
sdy93387fa2016-12-01 01:03:44106* You only have to run this once for each new build directory, Ninja will
107 update the build files as needed.
108* You can replace `Default` with another name, but
109 it should be a subdirectory of `out`.
110* For other build arguments, including release settings, see [GN build
111 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58112 The default will be a debug component build matching the current host
113 operating system and CPU.
114* For more info on GN, run `gn help` on the command line or read the
Eric Roman01446752019-09-03 23:45:08115 [quick start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md).
Reilly Grantf057adf2020-11-03 17:42:37116* Building Chromium for arm Macs requires [additional setup](mac_arm64.md).
thakisf28551b2016-08-09 14:42:55117
thakisf28551b2016-08-09 14:42:55118
dpranke0ae7cad2016-11-30 07:47:58119### Faster builds
andybons3322f762015-08-24 21:37:09120
andybonsad92aa32015-08-31 02:27:44121Full rebuilds are about the same speed in Debug and Release, but linking is a
122lot faster in Release builds.
andybons3322f762015-08-24 21:37:09123
thakisf28551b2016-08-09 14:42:55124Put
andybons3322f762015-08-24 21:37:09125
sdy93387fa2016-12-01 01:03:44126```
127is_debug = false
128```
andybons3322f762015-08-24 21:37:09129
sdy93387fa2016-12-01 01:03:44130in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55131
132Put
133
sdy93387fa2016-12-01 01:03:44134```
135is_component_build = true
136```
thakisf28551b2016-08-09 14:42:55137
sdy93387fa2016-12-01 01:03:44138in your `args.gn` to build many small dylibs instead of a single large
139executable. This makes incremental builds much faster, at the cost of producing
140a binary that opens less quickly. Component builds work in both debug and
141release.
thakisf28551b2016-08-09 14:42:55142
143Put
144
sdy93387fa2016-12-01 01:03:44145```
146symbol_level = 0
147```
thakisf28551b2016-08-09 14:42:55148
149in your args.gn to disable debug symbols altogether. This makes both full
150rebuilds and linking faster (at the cost of not getting symbolized backtraces
151in gdb).
andybons3322f762015-08-24 21:37:09152
Philip Rogerseb841682017-10-09 16:08:50153#### CCache
154
philipj5a0fcb92016-01-23 23:23:40155You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09156
dpranke1a70d0c2016-12-01 02:42:29157## Build Chromium
158
159Build Chromium (the "chrome" target) with Ninja using the command:
160
161```shell
Max Morozf5b31fcd2018-08-10 21:55:48162$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29163```
164
Dirk Pranke8bd55f22018-10-24 21:22:10165(`autoninja` is a wrapper that automatically provides optimal values for the
166arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48167
dpranke1a70d0c2016-12-01 02:42:29168You can get a list of all of the other build targets from GN by running `gn ls
169out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48170with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29171out/Default chrome/test:unit_tests`).
172
dpranke0ae7cad2016-11-30 07:47:58173## Run Chromium
andybons3322f762015-08-24 21:37:09174
dpranke0ae7cad2016-11-30 07:47:58175Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09176
sdy93387fa2016-12-01 01:03:44177```shell
Owen Min83eda1102017-06-28 18:47:21178$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44179```
andybons3322f762015-08-24 21:37:09180
Dominic Mazzonia7494a52020-08-06 19:19:11181## Avoiding the "incoming network connections" dialog
182
183Every time you start a new developer build of Chrome you get a system dialog
184asking "Do you want the application Chromium.app to accept incoming
185network connections?" - to avoid this, run with this command-line flag:
186
187--disable-features="MediaRouter"
188
dpranke0ae7cad2016-11-30 07:47:58189## Running test targets
andybons3322f762015-08-24 21:37:09190
dpranke0ae7cad2016-11-30 07:47:58191You can run the tests in the same way. You can also limit which tests are
192run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09193
sdy93387fa2016-12-01 01:03:44194```
dpranke1a70d0c2016-12-01 02:42:29195$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44196```
andybons3322f762015-08-24 21:37:09197
dpranke0ae7cad2016-11-30 07:47:58198You can find out more about GoogleTest at its
199[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09200
andybonsad92aa32015-08-31 02:27:44201## Debugging
andybons3322f762015-08-24 21:37:09202
Robert Sesek3b731b12021-04-14 21:54:03203Good debugging tips can be found [here](mac/debugging.md).
Vaclav Brozek539499e2018-07-18 11:19:51204
dpranke0ae7cad2016-11-30 07:47:58205## Update your checkout
andybonsad92aa32015-08-31 02:27:44206
dpranke0ae7cad2016-11-30 07:47:58207To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44208
sdy93387fa2016-12-01 01:03:44209```shell
210$ git rebase-update
211$ gclient sync
212```
dpranke0ae7cad2016-11-30 07:47:58213
214The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44215any of your local branches on top of tip-of-tree (aka the Git branch
216`origin/master`). If you don't want to use this script, you can also just use
217`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58218
sdy93387fa2016-12-01 01:03:44219The second command syncs dependencies to the appropriate versions and re-runs
220hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58221
222## Tips, tricks, and troubleshooting
223
224### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44225
sdy93387fa2016-12-01 01:03:44226While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55227for building, but Xcode for editing and driving compilation. Xcode is still
228slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44229build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44230
sdy93387fa2016-12-01 01:03:44231With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10232the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00233target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09234
sdy93387fa2016-12-01 01:03:44235To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24236
237```shell
sdy93387fa2016-12-01 01:03:44238$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24239```
andybons3322f762015-08-24 21:37:09240
thakisf28551b2016-08-09 14:42:55241Open it:
tfarina59fb57ac2016-03-02 18:17:24242
243```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00244$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24245```
andybons3322f762015-08-24 21:37:09246
andybonsad92aa32015-08-31 02:27:44247You may run into a problem where http://YES is opened as a new tab every time
248you launch Chrome. To fix this, open the scheme editor for the Run scheme,
249choose the Options tab, and uncheck "Allow debugging when using document
250Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44251`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
252gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09253
andybonsad92aa32015-08-31 02:27:44254If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44255ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17256[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44257tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09258
dpranke0ae7cad2016-11-30 07:47:58259### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37260
ishermance1d9d82017-05-12 23:10:04261#### Increase the vnode cache size
262
shess1f4c3d92015-11-05 18:15:37263`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44264to the large number of files in Chromium's checkout, `git status` performance
265can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37266default, this command:
267
sdy93387fa2016-12-01 01:03:44268```shell
269$ sysctl -a | egrep kern\..*vnodes
270```
shess1f4c3d92015-11-05 18:15:37271
272Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
273setting:
274
sdy93387fa2016-12-01 01:03:44275```shell
276$ sudo sysctl kern.maxvnodes=$((512*1024))
277```
shess1f4c3d92015-11-05 18:15:37278
279Higher values may be appropriate if you routinely move between different
280Chromium checkouts. This setting will reset on reboot, the startup setting can
281be set in `/etc/sysctl.conf`:
282
sdy93387fa2016-12-01 01:03:44283```shell
284$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
285```
shess1f4c3d92015-11-05 18:15:37286
287Or edit the file directly.
288
ishermance1d9d82017-05-12 23:10:04289#### Configure git to use an untracked cache
290
291If `git --version` reports 2.8 or higher, try running
292
293```shell
294$ git update-index --test-untracked-cache
295```
296
297If the output ends with `OK`, then the following may also improve performance of
298`git status`:
299
300```shell
301$ git config core.untrackedCache true
302```
303
304If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
shess1f4c3d92015-11-05 18:15:37305
sdy93387fa2016-12-01 01:03:44306```shell
307$ git update-index --untracked-cache
308```
tnagelcad631692016-04-15 11:02:36309
dpranke0ae7cad2016-11-30 07:47:58310### Xcode license agreement
tnagelcad631692016-04-15 11:02:36311
312If you're getting the error
313
sdy93387fa2016-12-01 01:03:44314> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
315> root via sudo.
tnagelcad631692016-04-15 11:02:36316
317the Xcode license hasn't been accepted yet which (contrary to the message) any
318user can do by running:
319
sdy93387fa2016-12-01 01:03:44320```shell
321$ xcodebuild -license
322```
tnagelcad631692016-04-15 11:02:36323
324Only accepting for all users of the machine requires root:
325
sdy93387fa2016-12-01 01:03:44326```shell
327$ sudo xcodebuild -license
328```