blob: ea1c26022533bea70a9ac3e9ee7a6f34dc4f9d4c [file] [log] [blame] [view]
dpranke1a70d0c2016-12-01 02:42:291# Checking out and building Chromium for Mac
andybons3322f762015-08-24 21:37:092
dpranke1a70d0c2016-12-01 02:42:293There are instructions for other platforms linked from the
4[get the code](get_the_code.md) page.
5
6**See also [the old version of this page](old_mac_build_instructions.md).**
7
8## Instructions for Google Employees
9
10Are you a Google employee? See
11[go/building-chrome](https://goto.google.com/building-chrome) instead.
dpranke0ae7cad2016-11-30 07:47:5812
andybonsad92aa32015-08-31 02:27:4413[TOC]
andybons3322f762015-08-24 21:37:0914
dpranke0ae7cad2016-11-30 07:47:5815## System requirements
sdya8197bd22016-09-14 19:06:4216
dpranke0ae7cad2016-11-30 07:47:5817* A 64-bit Mac running 10.9+.
thakisf28551b2016-08-09 14:42:5518* [Xcode](https://developer.apple.com/xcode) 7.3+.
sdy93387fa2016-12-01 01:03:4419* The OS X 10.10 SDK. Run
20
21 ```shell
22 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0323 ```
sdy93387fa2016-12-01 01:03:4424
25 to check whether you have it. Building with a newer SDK works too, but
thakisf28551b2016-08-09 14:42:5526 the releases currently use the 10.10 SDK.
andybons3322f762015-08-24 21:37:0927
dpranke0ae7cad2016-11-30 07:47:5828## Install `depot_tools`
andybons3322f762015-08-24 21:37:0929
sdy93387fa2016-12-01 01:03:4430Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0931
sdy93387fa2016-12-01 01:03:4432```shell
33$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
34```
andybons3322f762015-08-24 21:37:0935
sdy93387fa2016-12-01 01:03:4436Add `depot_tools` to the end of your PATH (you will probably want to put this
37in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
38`/path/to/depot_tools`:
dpranke0ae7cad2016-11-30 07:47:5839
sdy93387fa2016-12-01 01:03:4440```shell
41$ export PATH="$PATH:/path/to/depot_tools"
42```
dpranke0ae7cad2016-11-30 07:47:5843
44## Get the code
45
sdy93387fa2016-12-01 01:03:4446Create a `chromium` directory for the checkout and change to it (you can call
47this whatever you like and put it wherever you like, as long as the full path
48has no spaces):
dpranke0ae7cad2016-11-30 07:47:5849
sdy93387fa2016-12-01 01:03:4450```shell
51$ mkdir chromium && cd chromium
52```
53
54Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5855dependencies.
56
sdy93387fa2016-12-01 01:03:4457```shell
58$ fetch chromium
59```
dpranke0ae7cad2016-11-30 07:47:5860
61If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:4462adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:5863
sdy93387fa2016-12-01 01:03:4464Expect the command to take 30 minutes on even a fast connection, and many
65hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5866
sdy93387fa2016-12-01 01:03:4467When `fetch` completes, it will have created a hidden `.gclient` file and a
68directory called `src` in the working directory. The remaining instructions
69assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5870
sdy93387fa2016-12-01 01:03:4471```shell
72$ cd src
73```
74
75*Optional*: You can also [install API
76keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
77build to talk to some Google services, but this is not necessary for most
78development and testing purposes.
andybons3322f762015-08-24 21:37:0979
dpranke1a70d0c2016-12-01 02:42:2980## Setting up the build
andybons3322f762015-08-24 21:37:0981
sdy93387fa2016-12-01 01:03:4482Chromium uses [Ninja](https://ninja-build.org) as its main build tool along
83with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja`
84files. You can create any number of *build directories* with different
85configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:4486
sdy93387fa2016-12-01 01:03:4487```shell
88$ gn gen out/Default
89```
thakisf28551b2016-08-09 14:42:5590
sdy93387fa2016-12-01 01:03:4491* You only have to run this once for each new build directory, Ninja will
92 update the build files as needed.
93* You can replace `Default` with another name, but
94 it should be a subdirectory of `out`.
95* For other build arguments, including release settings, see [GN build
96 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:5897 The default will be a debug component build matching the current host
98 operating system and CPU.
99* For more info on GN, run `gn help` on the command line or read the
100 [quick start guide](../tools/gn/docs/quick_start.md).
thakisf28551b2016-08-09 14:42:55101
thakisf28551b2016-08-09 14:42:55102
dpranke0ae7cad2016-11-30 07:47:58103### Faster builds
andybons3322f762015-08-24 21:37:09104
andybonsad92aa32015-08-31 02:27:44105Full rebuilds are about the same speed in Debug and Release, but linking is a
106lot faster in Release builds.
andybons3322f762015-08-24 21:37:09107
thakisf28551b2016-08-09 14:42:55108Put
andybons3322f762015-08-24 21:37:09109
sdy93387fa2016-12-01 01:03:44110```
111is_debug = false
112```
andybons3322f762015-08-24 21:37:09113
sdy93387fa2016-12-01 01:03:44114in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55115
116Put
117
sdy93387fa2016-12-01 01:03:44118```
119is_component_build = true
120```
thakisf28551b2016-08-09 14:42:55121
sdy93387fa2016-12-01 01:03:44122in your `args.gn` to build many small dylibs instead of a single large
123executable. This makes incremental builds much faster, at the cost of producing
124a binary that opens less quickly. Component builds work in both debug and
125release.
thakisf28551b2016-08-09 14:42:55126
127Put
128
sdy93387fa2016-12-01 01:03:44129```
130symbol_level = 0
131```
thakisf28551b2016-08-09 14:42:55132
133in your args.gn to disable debug symbols altogether. This makes both full
134rebuilds and linking faster (at the cost of not getting symbolized backtraces
135in gdb).
andybons3322f762015-08-24 21:37:09136
philipj5a0fcb92016-01-23 23:23:40137You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09138
dpranke1a70d0c2016-12-01 02:42:29139## Build Chromium
140
141Build Chromium (the "chrome" target) with Ninja using the command:
142
143```shell
144$ ninja -C out/Default chrome
145```
146
147You can get a list of all of the other build targets from GN by running `gn ls
148out/Default` from the command line. To compile one, pass the GN label to Ninja
149with no preceding "//" (so, for `//chrome/test:unit_tests` use `ninja -C
150out/Default chrome/test:unit_tests`).
151
dpranke0ae7cad2016-11-30 07:47:58152## Run Chromium
andybons3322f762015-08-24 21:37:09153
dpranke0ae7cad2016-11-30 07:47:58154Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09155
sdy93387fa2016-12-01 01:03:44156```shell
157$ out/Default/chrome
158```
andybons3322f762015-08-24 21:37:09159
dpranke0ae7cad2016-11-30 07:47:58160## Running test targets
andybons3322f762015-08-24 21:37:09161
dpranke0ae7cad2016-11-30 07:47:58162You can run the tests in the same way. You can also limit which tests are
163run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09164
sdy93387fa2016-12-01 01:03:44165```
dpranke1a70d0c2016-12-01 02:42:29166$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44167```
andybons3322f762015-08-24 21:37:09168
dpranke0ae7cad2016-11-30 07:47:58169You can find out more about GoogleTest at its
170[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09171
andybonsad92aa32015-08-31 02:27:44172## Debugging
andybons3322f762015-08-24 21:37:09173
andybonsad92aa32015-08-31 02:27:44174Good debugging tips can be found
175[here](http://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you
176would like to debug in a graphical environment, rather than using `lldb` at the
sdy93387fa2016-12-01 01:03:44177command line, that is possible without building in Xcode (see
178[Debugging in Xcode](http://www.chromium.org/developers/how-tos/debugging-on-os-x/building-with-ninja-debugging-with-xcode)).
andybons3322f762015-08-24 21:37:09179
dpranke0ae7cad2016-11-30 07:47:58180## Update your checkout
andybonsad92aa32015-08-31 02:27:44181
dpranke0ae7cad2016-11-30 07:47:58182To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44183
sdy93387fa2016-12-01 01:03:44184```shell
185$ git rebase-update
186$ gclient sync
187```
dpranke0ae7cad2016-11-30 07:47:58188
189The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44190any of your local branches on top of tip-of-tree (aka the Git branch
191`origin/master`). If you don't want to use this script, you can also just use
192`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58193
sdy93387fa2016-12-01 01:03:44194The second command syncs dependencies to the appropriate versions and re-runs
195hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58196
197## Tips, tricks, and troubleshooting
198
199### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44200
sdy93387fa2016-12-01 01:03:44201While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55202for building, but Xcode for editing and driving compilation. Xcode is still
203slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44204build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44205
sdy93387fa2016-12-01 01:03:44206With hybrid builds, compilation is still handled by Ninja, and can be run from
207the command line (e.g. `ninja -C out/gn chrome`) or by choosing the `chrome`
208target in the hybrid workspace and choosing Build.
andybons3322f762015-08-24 21:37:09209
sdy93387fa2016-12-01 01:03:44210To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24211
212```shell
sdy93387fa2016-12-01 01:03:44213$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24214```
andybons3322f762015-08-24 21:37:09215
thakisf28551b2016-08-09 14:42:55216Open it:
tfarina59fb57ac2016-03-02 18:17:24217
218```shell
sdy93387fa2016-12-01 01:03:44219$ open out/gn/ninja/all.xcworkspace
tfarina59fb57ac2016-03-02 18:17:24220```
andybons3322f762015-08-24 21:37:09221
andybonsad92aa32015-08-31 02:27:44222You may run into a problem where http://YES is opened as a new tab every time
223you launch Chrome. To fix this, open the scheme editor for the Run scheme,
224choose the Options tab, and uncheck "Allow debugging when using document
225Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44226`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
227gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09228
andybonsad92aa32015-08-31 02:27:44229If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44230ask there. Be sure that the
231[waterfall](http://build.chromium.org/buildbot/waterfall/) is green and the
232tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09233
dpranke0ae7cad2016-11-30 07:47:58234### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37235
236`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44237to the large number of files in Chromium's checkout, `git status` performance
238can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37239default, this command:
240
sdy93387fa2016-12-01 01:03:44241```shell
242$ sysctl -a | egrep kern\..*vnodes
243```
shess1f4c3d92015-11-05 18:15:37244
245Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
246setting:
247
sdy93387fa2016-12-01 01:03:44248```shell
249$ sudo sysctl kern.maxvnodes=$((512*1024))
250```
shess1f4c3d92015-11-05 18:15:37251
252Higher values may be appropriate if you routinely move between different
253Chromium checkouts. This setting will reset on reboot, the startup setting can
254be set in `/etc/sysctl.conf`:
255
sdy93387fa2016-12-01 01:03:44256```shell
257$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
258```
shess1f4c3d92015-11-05 18:15:37259
260Or edit the file directly.
261
sdy93387fa2016-12-01 01:03:44262If `git --version` reports 2.6 or higher, the following may also improve
shess1f4c3d92015-11-05 18:15:37263performance of `git status`:
264
sdy93387fa2016-12-01 01:03:44265```shell
266$ git update-index --untracked-cache
267```
tnagelcad631692016-04-15 11:02:36268
dpranke0ae7cad2016-11-30 07:47:58269### Xcode license agreement
tnagelcad631692016-04-15 11:02:36270
271If you're getting the error
272
sdy93387fa2016-12-01 01:03:44273> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
274> root via sudo.
tnagelcad631692016-04-15 11:02:36275
276the Xcode license hasn't been accepted yet which (contrary to the message) any
277user can do by running:
278
sdy93387fa2016-12-01 01:03:44279```shell
280$ xcodebuild -license
281```
tnagelcad631692016-04-15 11:02:36282
283Only accepting for all users of the machine requires root:
284
sdy93387fa2016-12-01 01:03:44285```shell
286$ sudo xcodebuild -license
287```