blob: dbbaa7f0f21e9bc9293e2d1080c254f69bf03bc3 [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 Drissmand1137732020-02-18 21:26:2315* A 64-bit Mac running 10.14+.
James Howarda07e1492020-06-26 15:34:0816* [Xcode](https://developer.apple.com/xcode) 11.2+
17* The OS X 10.15.1 SDK. Run
sdy93387fa2016-12-01 01:03:4418
erikchen7d7509a2017-10-02 23:40:3619 ```shell
sdy93387fa2016-12-01 01:03:4420 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0321 ```
erikchen7d7509a2017-10-02 23:40:3622
sdy93387fa2016-12-01 01:03:4423 to check whether you have it. Building with a newer SDK works too, but
James Howarda07e1492020-06-26 15:34:0824 the releases [currently use Xcode 11.2.1](https://source.chromium.org/search?q=MAC_BINARIES_LABEL&ss=chromium).
andybons3322f762015-08-24 21:37:0925
dpranke0ae7cad2016-11-30 07:47:5826## Install `depot_tools`
andybons3322f762015-08-24 21:37:0927
sdy93387fa2016-12-01 01:03:4428Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0929
sdy93387fa2016-12-01 01:03:4430```shell
31$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
32```
andybons3322f762015-08-24 21:37:0933
Gabriel Charetteb6780c12019-04-24 16:23:5234Add `depot_tools` to the end of your PATH (you will probably want to put this in
35your `~/.bash_profile` or `~/.zshrc`). Assuming you cloned `depot_tools` to
36`/path/to/depot_tools` (note: you **must** use the absolute path or Python will
37not be able to find infra tools):
dpranke0ae7cad2016-11-30 07:47:5838
sdy93387fa2016-12-01 01:03:4439```shell
40$ export PATH="$PATH:/path/to/depot_tools"
41```
dpranke0ae7cad2016-11-30 07:47:5842
43## Get the code
44
Aaron Gable94b7e2a32018-01-03 19:14:4145Ensure that unicode filenames aren't mangled by HFS:
46
47```shell
48$ git config --global core.precomposeUnicode true
49```
50
sdy93387fa2016-12-01 01:03:4451Create a `chromium` directory for the checkout and change to it (you can call
52this whatever you like and put it wherever you like, as long as the full path
53has no spaces):
dpranke0ae7cad2016-11-30 07:47:5854
sdy93387fa2016-12-01 01:03:4455```shell
56$ mkdir chromium && cd chromium
57```
58
59Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5860dependencies.
61
sdy93387fa2016-12-01 01:03:4462```shell
63$ fetch chromium
64```
dpranke0ae7cad2016-11-30 07:47:5865
[email protected]1436b952018-10-26 16:35:1366If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1967`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
68the full history later.
dpranke0ae7cad2016-11-30 07:47:5869
sdy93387fa2016-12-01 01:03:4470Expect the command to take 30 minutes on even a fast connection, and many
71hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5872
sdy93387fa2016-12-01 01:03:4473When `fetch` completes, it will have created a hidden `.gclient` file and a
74directory called `src` in the working directory. The remaining instructions
75assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5876
sdy93387fa2016-12-01 01:03:4477```shell
78$ cd src
79```
80
81*Optional*: You can also [install API
82keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
83build to talk to some Google services, but this is not necessary for most
84development and testing purposes.
andybons3322f762015-08-24 21:37:0985
dpranke1a70d0c2016-12-01 02:42:2986## Setting up the build
andybons3322f762015-08-24 21:37:0987
Tom Bridgwatereef401542018-08-17 00:54:4388Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
89a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
90to generate `.ninja` files. You can create any number of *build directories*
91with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:4492
sdy93387fa2016-12-01 01:03:4493```shell
94$ gn gen out/Default
95```
thakisf28551b2016-08-09 14:42:5596
sdy93387fa2016-12-01 01:03:4497* You only have to run this once for each new build directory, Ninja will
98 update the build files as needed.
99* You can replace `Default` with another name, but
100 it should be a subdirectory of `out`.
101* For other build arguments, including release settings, see [GN build
102 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58103 The default will be a debug component build matching the current host
104 operating system and CPU.
105* For more info on GN, run `gn help` on the command line or read the
Eric Roman01446752019-09-03 23:45:08106 [quick start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md).
thakisf28551b2016-08-09 14:42:55107
thakisf28551b2016-08-09 14:42:55108
dpranke0ae7cad2016-11-30 07:47:58109### Faster builds
andybons3322f762015-08-24 21:37:09110
andybonsad92aa32015-08-31 02:27:44111Full rebuilds are about the same speed in Debug and Release, but linking is a
112lot faster in Release builds.
andybons3322f762015-08-24 21:37:09113
thakisf28551b2016-08-09 14:42:55114Put
andybons3322f762015-08-24 21:37:09115
sdy93387fa2016-12-01 01:03:44116```
117is_debug = false
118```
andybons3322f762015-08-24 21:37:09119
sdy93387fa2016-12-01 01:03:44120in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55121
122Put
123
sdy93387fa2016-12-01 01:03:44124```
125is_component_build = true
126```
thakisf28551b2016-08-09 14:42:55127
sdy93387fa2016-12-01 01:03:44128in your `args.gn` to build many small dylibs instead of a single large
129executable. This makes incremental builds much faster, at the cost of producing
130a binary that opens less quickly. Component builds work in both debug and
131release.
thakisf28551b2016-08-09 14:42:55132
133Put
134
sdy93387fa2016-12-01 01:03:44135```
136symbol_level = 0
137```
thakisf28551b2016-08-09 14:42:55138
139in your args.gn to disable debug symbols altogether. This makes both full
140rebuilds and linking faster (at the cost of not getting symbolized backtraces
141in gdb).
andybons3322f762015-08-24 21:37:09142
Philip Rogerseb841682017-10-09 16:08:50143#### CCache
144
philipj5a0fcb92016-01-23 23:23:40145You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09146
dpranke1a70d0c2016-12-01 02:42:29147## Build Chromium
148
149Build Chromium (the "chrome" target) with Ninja using the command:
150
151```shell
Max Morozf5b31fcd2018-08-10 21:55:48152$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29153```
154
Dirk Pranke8bd55f22018-10-24 21:22:10155(`autoninja` is a wrapper that automatically provides optimal values for the
156arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48157
dpranke1a70d0c2016-12-01 02:42:29158You can get a list of all of the other build targets from GN by running `gn ls
159out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48160with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29161out/Default chrome/test:unit_tests`).
162
dpranke0ae7cad2016-11-30 07:47:58163## Run Chromium
andybons3322f762015-08-24 21:37:09164
dpranke0ae7cad2016-11-30 07:47:58165Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09166
sdy93387fa2016-12-01 01:03:44167```shell
Owen Min83eda1102017-06-28 18:47:21168$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44169```
andybons3322f762015-08-24 21:37:09170
dpranke0ae7cad2016-11-30 07:47:58171## Running test targets
andybons3322f762015-08-24 21:37:09172
dpranke0ae7cad2016-11-30 07:47:58173You can run the tests in the same way. You can also limit which tests are
174run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09175
sdy93387fa2016-12-01 01:03:44176```
dpranke1a70d0c2016-12-01 02:42:29177$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44178```
andybons3322f762015-08-24 21:37:09179
dpranke0ae7cad2016-11-30 07:47:58180You can find out more about GoogleTest at its
181[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09182
andybonsad92aa32015-08-31 02:27:44183## Debugging
andybons3322f762015-08-24 21:37:09184
andybonsad92aa32015-08-31 02:27:44185Good debugging tips can be found
xiaoyin.l1003c0b2016-12-06 02:51:17186[here](https://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you
andybonsad92aa32015-08-31 02:27:44187would like to debug in a graphical environment, rather than using `lldb` at the
sdy93387fa2016-12-01 01:03:44188command line, that is possible without building in Xcode (see
xiaoyin.l1003c0b2016-12-06 02:51:17189[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:09190
Vaclav Brozek539499e2018-07-18 11:19:51191Tips for printing variables from `lldb` prompt (both in Xcode or in terminal):
192* If `uptr` is a `std::unique_ptr`, the address it wraps is accessible as
193 `uptr.__ptr_.__value_`.
194* To pretty-print `base::string16`, ensure you have a `~/.lldbinit` file and
195 add the following line into it (substitute {SRC} for your actual path to the
196 root of Chromium's sources):
197```
198command script import {SRC}/tools/lldb/lldb_chrome.py
199```
200
dpranke0ae7cad2016-11-30 07:47:58201## Update your checkout
andybonsad92aa32015-08-31 02:27:44202
dpranke0ae7cad2016-11-30 07:47:58203To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44204
sdy93387fa2016-12-01 01:03:44205```shell
206$ git rebase-update
207$ gclient sync
208```
dpranke0ae7cad2016-11-30 07:47:58209
210The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44211any of your local branches on top of tip-of-tree (aka the Git branch
212`origin/master`). If you don't want to use this script, you can also just use
213`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58214
sdy93387fa2016-12-01 01:03:44215The second command syncs dependencies to the appropriate versions and re-runs
216hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58217
218## Tips, tricks, and troubleshooting
219
220### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44221
sdy93387fa2016-12-01 01:03:44222While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55223for building, but Xcode for editing and driving compilation. Xcode is still
224slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44225build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44226
sdy93387fa2016-12-01 01:03:44227With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10228the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00229target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09230
sdy93387fa2016-12-01 01:03:44231To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24232
233```shell
sdy93387fa2016-12-01 01:03:44234$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24235```
andybons3322f762015-08-24 21:37:09236
thakisf28551b2016-08-09 14:42:55237Open it:
tfarina59fb57ac2016-03-02 18:17:24238
239```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00240$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24241```
andybons3322f762015-08-24 21:37:09242
andybonsad92aa32015-08-31 02:27:44243You may run into a problem where http://YES is opened as a new tab every time
244you launch Chrome. To fix this, open the scheme editor for the Run scheme,
245choose the Options tab, and uncheck "Allow debugging when using document
246Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44247`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
248gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09249
andybonsad92aa32015-08-31 02:27:44250If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44251ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17252[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44253tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09254
dpranke0ae7cad2016-11-30 07:47:58255### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37256
ishermance1d9d82017-05-12 23:10:04257#### Increase the vnode cache size
258
shess1f4c3d92015-11-05 18:15:37259`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44260to the large number of files in Chromium's checkout, `git status` performance
261can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37262default, this command:
263
sdy93387fa2016-12-01 01:03:44264```shell
265$ sysctl -a | egrep kern\..*vnodes
266```
shess1f4c3d92015-11-05 18:15:37267
268Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
269setting:
270
sdy93387fa2016-12-01 01:03:44271```shell
272$ sudo sysctl kern.maxvnodes=$((512*1024))
273```
shess1f4c3d92015-11-05 18:15:37274
275Higher values may be appropriate if you routinely move between different
276Chromium checkouts. This setting will reset on reboot, the startup setting can
277be set in `/etc/sysctl.conf`:
278
sdy93387fa2016-12-01 01:03:44279```shell
280$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
281```
shess1f4c3d92015-11-05 18:15:37282
283Or edit the file directly.
284
ishermance1d9d82017-05-12 23:10:04285#### Configure git to use an untracked cache
286
287If `git --version` reports 2.8 or higher, try running
288
289```shell
290$ git update-index --test-untracked-cache
291```
292
293If the output ends with `OK`, then the following may also improve performance of
294`git status`:
295
296```shell
297$ git config core.untrackedCache true
298```
299
300If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
shess1f4c3d92015-11-05 18:15:37301
sdy93387fa2016-12-01 01:03:44302```shell
303$ git update-index --untracked-cache
304```
tnagelcad631692016-04-15 11:02:36305
dpranke0ae7cad2016-11-30 07:47:58306### Xcode license agreement
tnagelcad631692016-04-15 11:02:36307
308If you're getting the error
309
sdy93387fa2016-12-01 01:03:44310> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
311> root via sudo.
tnagelcad631692016-04-15 11:02:36312
313the Xcode license hasn't been accepted yet which (contrary to the message) any
314user can do by running:
315
sdy93387fa2016-12-01 01:03:44316```shell
317$ xcodebuild -license
318```
tnagelcad631692016-04-15 11:02:36319
320Only accepting for all users of the machine requires root:
321
sdy93387fa2016-12-01 01:03:44322```shell
323$ sudo xcodebuild -license
324```