blob: 0396294fa7e99d651ac8b455d34593533994ffa6 [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
sdy93387fa2016-12-01 01:03:4455Create a `chromium` directory for the checkout and change to it (you can call
56this whatever you like and put it wherever you like, as long as the full path
57has no spaces):
dpranke0ae7cad2016-11-30 07:47:5858
sdy93387fa2016-12-01 01:03:4459```shell
60$ mkdir chromium && cd chromium
61```
62
63Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5864dependencies.
65
sdy93387fa2016-12-01 01:03:4466```shell
67$ fetch chromium
68```
dpranke0ae7cad2016-11-30 07:47:5869
[email protected]1436b952018-10-26 16:35:1370If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1971`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
72the full history later.
dpranke0ae7cad2016-11-30 07:47:5873
sdy93387fa2016-12-01 01:03:4474Expect the command to take 30 minutes on even a fast connection, and many
75hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5876
sdy93387fa2016-12-01 01:03:4477When `fetch` completes, it will have created a hidden `.gclient` file and a
78directory called `src` in the working directory. The remaining instructions
79assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5880
sdy93387fa2016-12-01 01:03:4481```shell
82$ cd src
83```
84
85*Optional*: You can also [install API
86keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
87build to talk to some Google services, but this is not necessary for most
88development and testing purposes.
andybons3322f762015-08-24 21:37:0989
dpranke1a70d0c2016-12-01 02:42:2990## Setting up the build
andybons3322f762015-08-24 21:37:0991
Tom Bridgwatereef401542018-08-17 00:54:4392Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
93a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
94to generate `.ninja` files. You can create any number of *build directories*
95with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:4496
sdy93387fa2016-12-01 01:03:4497```shell
98$ gn gen out/Default
99```
thakisf28551b2016-08-09 14:42:55100
sdy93387fa2016-12-01 01:03:44101* You only have to run this once for each new build directory, Ninja will
102 update the build files as needed.
103* You can replace `Default` with another name, but
104 it should be a subdirectory of `out`.
105* For other build arguments, including release settings, see [GN build
106 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58107 The default will be a debug component build matching the current host
108 operating system and CPU.
109* For more info on GN, run `gn help` on the command line or read the
Eric Roman01446752019-09-03 23:45:08110 [quick start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md).
Reilly Grantf057adf2020-11-03 17:42:37111* Building Chromium for arm Macs requires [additional setup](mac_arm64.md).
thakisf28551b2016-08-09 14:42:55112
thakisf28551b2016-08-09 14:42:55113
dpranke0ae7cad2016-11-30 07:47:58114### Faster builds
andybons3322f762015-08-24 21:37:09115
andybonsad92aa32015-08-31 02:27:44116Full rebuilds are about the same speed in Debug and Release, but linking is a
117lot faster in Release builds.
andybons3322f762015-08-24 21:37:09118
thakisf28551b2016-08-09 14:42:55119Put
andybons3322f762015-08-24 21:37:09120
sdy93387fa2016-12-01 01:03:44121```
122is_debug = false
123```
andybons3322f762015-08-24 21:37:09124
sdy93387fa2016-12-01 01:03:44125in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55126
127Put
128
sdy93387fa2016-12-01 01:03:44129```
130is_component_build = true
131```
thakisf28551b2016-08-09 14:42:55132
sdy93387fa2016-12-01 01:03:44133in your `args.gn` to build many small dylibs instead of a single large
134executable. This makes incremental builds much faster, at the cost of producing
135a binary that opens less quickly. Component builds work in both debug and
136release.
thakisf28551b2016-08-09 14:42:55137
138Put
139
sdy93387fa2016-12-01 01:03:44140```
141symbol_level = 0
142```
thakisf28551b2016-08-09 14:42:55143
144in your args.gn to disable debug symbols altogether. This makes both full
145rebuilds and linking faster (at the cost of not getting symbolized backtraces
146in gdb).
andybons3322f762015-08-24 21:37:09147
Philip Rogerseb841682017-10-09 16:08:50148#### CCache
149
philipj5a0fcb92016-01-23 23:23:40150You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09151
dpranke1a70d0c2016-12-01 02:42:29152## Build Chromium
153
154Build Chromium (the "chrome" target) with Ninja using the command:
155
156```shell
Max Morozf5b31fcd2018-08-10 21:55:48157$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29158```
159
Dirk Pranke8bd55f22018-10-24 21:22:10160(`autoninja` is a wrapper that automatically provides optimal values for the
161arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48162
dpranke1a70d0c2016-12-01 02:42:29163You can get a list of all of the other build targets from GN by running `gn ls
164out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48165with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29166out/Default chrome/test:unit_tests`).
167
dpranke0ae7cad2016-11-30 07:47:58168## Run Chromium
andybons3322f762015-08-24 21:37:09169
dpranke0ae7cad2016-11-30 07:47:58170Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09171
sdy93387fa2016-12-01 01:03:44172```shell
Owen Min83eda1102017-06-28 18:47:21173$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44174```
andybons3322f762015-08-24 21:37:09175
Dominic Mazzonia7494a52020-08-06 19:19:11176## Avoiding the "incoming network connections" dialog
177
178Every time you start a new developer build of Chrome you get a system dialog
179asking "Do you want the application Chromium.app to accept incoming
180network connections?" - to avoid this, run with this command-line flag:
181
182--disable-features="MediaRouter"
183
dpranke0ae7cad2016-11-30 07:47:58184## Running test targets
andybons3322f762015-08-24 21:37:09185
dpranke0ae7cad2016-11-30 07:47:58186You can run the tests in the same way. You can also limit which tests are
187run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09188
sdy93387fa2016-12-01 01:03:44189```
dpranke1a70d0c2016-12-01 02:42:29190$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44191```
andybons3322f762015-08-24 21:37:09192
dpranke0ae7cad2016-11-30 07:47:58193You can find out more about GoogleTest at its
194[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09195
andybonsad92aa32015-08-31 02:27:44196## Debugging
andybons3322f762015-08-24 21:37:09197
andybonsad92aa32015-08-31 02:27:44198Good debugging tips can be found
xiaoyin.l1003c0b2016-12-06 02:51:17199[here](https://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you
andybonsad92aa32015-08-31 02:27:44200would like to debug in a graphical environment, rather than using `lldb` at the
sdy93387fa2016-12-01 01:03:44201command line, that is possible without building in Xcode (see
xiaoyin.l1003c0b2016-12-06 02:51:17202[Debugging in Xcode](https://www.chromium.org/developers/how-tos/debugging-on-os-x/building-with-ninja-debugging-with-xcode)).
andybons3322f762015-08-24 21:37:09203
Vaclav Brozek539499e2018-07-18 11:19:51204Tips for printing variables from `lldb` prompt (both in Xcode or in terminal):
205* If `uptr` is a `std::unique_ptr`, the address it wraps is accessible as
206 `uptr.__ptr_.__value_`.
207* To pretty-print `base::string16`, ensure you have a `~/.lldbinit` file and
208 add the following line into it (substitute {SRC} for your actual path to the
209 root of Chromium's sources):
210```
211command script import {SRC}/tools/lldb/lldb_chrome.py
212```
213
dpranke0ae7cad2016-11-30 07:47:58214## Update your checkout
andybonsad92aa32015-08-31 02:27:44215
dpranke0ae7cad2016-11-30 07:47:58216To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44217
sdy93387fa2016-12-01 01:03:44218```shell
219$ git rebase-update
220$ gclient sync
221```
dpranke0ae7cad2016-11-30 07:47:58222
223The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44224any of your local branches on top of tip-of-tree (aka the Git branch
225`origin/master`). If you don't want to use this script, you can also just use
226`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58227
sdy93387fa2016-12-01 01:03:44228The second command syncs dependencies to the appropriate versions and re-runs
229hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58230
231## Tips, tricks, and troubleshooting
232
233### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44234
sdy93387fa2016-12-01 01:03:44235While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55236for building, but Xcode for editing and driving compilation. Xcode is still
237slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44238build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44239
sdy93387fa2016-12-01 01:03:44240With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10241the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00242target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09243
sdy93387fa2016-12-01 01:03:44244To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24245
246```shell
sdy93387fa2016-12-01 01:03:44247$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24248```
andybons3322f762015-08-24 21:37:09249
thakisf28551b2016-08-09 14:42:55250Open it:
tfarina59fb57ac2016-03-02 18:17:24251
252```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00253$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24254```
andybons3322f762015-08-24 21:37:09255
andybonsad92aa32015-08-31 02:27:44256You may run into a problem where http://YES is opened as a new tab every time
257you launch Chrome. To fix this, open the scheme editor for the Run scheme,
258choose the Options tab, and uncheck "Allow debugging when using document
259Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44260`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
261gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09262
andybonsad92aa32015-08-31 02:27:44263If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44264ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17265[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44266tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09267
dpranke0ae7cad2016-11-30 07:47:58268### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37269
ishermance1d9d82017-05-12 23:10:04270#### Increase the vnode cache size
271
shess1f4c3d92015-11-05 18:15:37272`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44273to the large number of files in Chromium's checkout, `git status` performance
274can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37275default, this command:
276
sdy93387fa2016-12-01 01:03:44277```shell
278$ sysctl -a | egrep kern\..*vnodes
279```
shess1f4c3d92015-11-05 18:15:37280
281Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
282setting:
283
sdy93387fa2016-12-01 01:03:44284```shell
285$ sudo sysctl kern.maxvnodes=$((512*1024))
286```
shess1f4c3d92015-11-05 18:15:37287
288Higher values may be appropriate if you routinely move between different
289Chromium checkouts. This setting will reset on reboot, the startup setting can
290be set in `/etc/sysctl.conf`:
291
sdy93387fa2016-12-01 01:03:44292```shell
293$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
294```
shess1f4c3d92015-11-05 18:15:37295
296Or edit the file directly.
297
ishermance1d9d82017-05-12 23:10:04298#### Configure git to use an untracked cache
299
300If `git --version` reports 2.8 or higher, try running
301
302```shell
303$ git update-index --test-untracked-cache
304```
305
306If the output ends with `OK`, then the following may also improve performance of
307`git status`:
308
309```shell
310$ git config core.untrackedCache true
311```
312
313If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
shess1f4c3d92015-11-05 18:15:37314
sdy93387fa2016-12-01 01:03:44315```shell
316$ git update-index --untracked-cache
317```
tnagelcad631692016-04-15 11:02:36318
dpranke0ae7cad2016-11-30 07:47:58319### Xcode license agreement
tnagelcad631692016-04-15 11:02:36320
321If you're getting the error
322
sdy93387fa2016-12-01 01:03:44323> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
324> root via sudo.
tnagelcad631692016-04-15 11:02:36325
326the Xcode license hasn't been accepted yet which (contrary to the message) any
327user can do by running:
328
sdy93387fa2016-12-01 01:03:44329```shell
330$ xcodebuild -license
331```
tnagelcad631692016-04-15 11:02:36332
333Only accepting for all users of the machine requires root:
334
sdy93387fa2016-12-01 01:03:44335```shell
336$ sudo xcodebuild -license
337```