blob: a6521c9979ae9d4815bd5a78add85b3f0418cfa4 [file] [log] [blame] [view]
andybonsad92aa32015-08-31 02:27:441# Mac Build Instructions
andybons3322f762015-08-24 21:37:092
dpranke0ae7cad2016-11-30 07:47:583Google employee? See [go/building-chrome](https://goto.google.com/building-chrome) instead.
4
andybonsad92aa32015-08-31 02:27:445[TOC]
andybons3322f762015-08-24 21:37:096
dpranke0ae7cad2016-11-30 07:47:587## System requirements
sdya8197bd22016-09-14 19:06:428
dpranke0ae7cad2016-11-30 07:47:589* A 64-bit Mac running 10.9+.
thakisf28551b2016-08-09 14:42:5510* [Xcode](https://developer.apple.com/xcode) 7.3+.
sdy93387fa2016-12-01 01:03:4411* The OS X 10.10 SDK. Run
12
13 ```shell
14 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0315 ```
sdy93387fa2016-12-01 01:03:4416
17 to check whether you have it. Building with a newer SDK works too, but
thakisf28551b2016-08-09 14:42:5518 the releases currently use the 10.10 SDK.
andybons3322f762015-08-24 21:37:0919
dpranke0ae7cad2016-11-30 07:47:5820## Install `depot_tools`
andybons3322f762015-08-24 21:37:0921
sdy93387fa2016-12-01 01:03:4422Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0923
sdy93387fa2016-12-01 01:03:4424```shell
25$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
26```
andybons3322f762015-08-24 21:37:0927
sdy93387fa2016-12-01 01:03:4428Add `depot_tools` to the end of your PATH (you will probably want to put this
29in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
30`/path/to/depot_tools`:
dpranke0ae7cad2016-11-30 07:47:5831
sdy93387fa2016-12-01 01:03:4432```shell
33$ export PATH="$PATH:/path/to/depot_tools"
34```
dpranke0ae7cad2016-11-30 07:47:5835
36## Get the code
37
sdy93387fa2016-12-01 01:03:4438Create a `chromium` directory for the checkout and change to it (you can call
39this whatever you like and put it wherever you like, as long as the full path
40has no spaces):
dpranke0ae7cad2016-11-30 07:47:5841
sdy93387fa2016-12-01 01:03:4442```shell
43$ mkdir chromium && cd chromium
44```
45
46Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5847dependencies.
48
sdy93387fa2016-12-01 01:03:4449```shell
50$ fetch chromium
51```
dpranke0ae7cad2016-11-30 07:47:5852
53If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:4454adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:5855
sdy93387fa2016-12-01 01:03:4456Expect the command to take 30 minutes on even a fast connection, and many
57hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5858
sdy93387fa2016-12-01 01:03:4459When `fetch` completes, it will have created a hidden `.gclient` file and a
60directory called `src` in the working directory. The remaining instructions
61assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5862
sdy93387fa2016-12-01 01:03:4463```shell
64$ cd src
65```
66
67*Optional*: You can also [install API
68keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
69build to talk to some Google services, but this is not necessary for most
70development and testing purposes.
andybons3322f762015-08-24 21:37:0971
andybonsad92aa32015-08-31 02:27:4472## Building
andybons3322f762015-08-24 21:37:0973
sdy93387fa2016-12-01 01:03:4474Chromium uses [Ninja](https://ninja-build.org) as its main build tool along
75with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja`
76files. You can create any number of *build directories* with different
77configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:4478
sdy93387fa2016-12-01 01:03:4479```shell
80$ gn gen out/Default
81```
thakisf28551b2016-08-09 14:42:5582
sdy93387fa2016-12-01 01:03:4483* You only have to run this once for each new build directory, Ninja will
84 update the build files as needed.
85* You can replace `Default` with another name, but
86 it should be a subdirectory of `out`.
87* For other build arguments, including release settings, see [GN build
88 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:5889 The default will be a debug component build matching the current host
90 operating system and CPU.
91* For more info on GN, run `gn help` on the command line or read the
92 [quick start guide](../tools/gn/docs/quick_start.md).
thakisf28551b2016-08-09 14:42:5593
thakisf28551b2016-08-09 14:42:5594
dpranke0ae7cad2016-11-30 07:47:5895### Faster builds
andybons3322f762015-08-24 21:37:0996
andybonsad92aa32015-08-31 02:27:4497Full rebuilds are about the same speed in Debug and Release, but linking is a
98lot faster in Release builds.
andybons3322f762015-08-24 21:37:0999
thakisf28551b2016-08-09 14:42:55100Put
andybons3322f762015-08-24 21:37:09101
sdy93387fa2016-12-01 01:03:44102```
103is_debug = false
104```
andybons3322f762015-08-24 21:37:09105
sdy93387fa2016-12-01 01:03:44106in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55107
108Put
109
sdy93387fa2016-12-01 01:03:44110```
111is_component_build = true
112```
thakisf28551b2016-08-09 14:42:55113
sdy93387fa2016-12-01 01:03:44114in your `args.gn` to build many small dylibs instead of a single large
115executable. This makes incremental builds much faster, at the cost of producing
116a binary that opens less quickly. Component builds work in both debug and
117release.
thakisf28551b2016-08-09 14:42:55118
119Put
120
sdy93387fa2016-12-01 01:03:44121```
122symbol_level = 0
123```
thakisf28551b2016-08-09 14:42:55124
125in your args.gn to disable debug symbols altogether. This makes both full
126rebuilds and linking faster (at the cost of not getting symbolized backtraces
127in gdb).
andybons3322f762015-08-24 21:37:09128
philipj5a0fcb92016-01-23 23:23:40129You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09130
dpranke0ae7cad2016-11-30 07:47:58131## Run Chromium
andybons3322f762015-08-24 21:37:09132
dpranke0ae7cad2016-11-30 07:47:58133Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09134
sdy93387fa2016-12-01 01:03:44135```shell
136$ out/Default/chrome
137```
andybons3322f762015-08-24 21:37:09138
dpranke0ae7cad2016-11-30 07:47:58139## Running test targets
andybons3322f762015-08-24 21:37:09140
dpranke0ae7cad2016-11-30 07:47:58141You can run the tests in the same way. You can also limit which tests are
142run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09143
sdy93387fa2016-12-01 01:03:44144```
145$ ninja -C out/Default unit_tests --gtest_filter="PushClientTest.*"
146```
andybons3322f762015-08-24 21:37:09147
dpranke0ae7cad2016-11-30 07:47:58148You can find out more about GoogleTest at its
149[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09150
andybonsad92aa32015-08-31 02:27:44151## Debugging
andybons3322f762015-08-24 21:37:09152
andybonsad92aa32015-08-31 02:27:44153Good debugging tips can be found
154[here](http://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you
155would like to debug in a graphical environment, rather than using `lldb` at the
sdy93387fa2016-12-01 01:03:44156command line, that is possible without building in Xcode (see
157[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:09158
dpranke0ae7cad2016-11-30 07:47:58159## Update your checkout
andybonsad92aa32015-08-31 02:27:44160
dpranke0ae7cad2016-11-30 07:47:58161To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44162
sdy93387fa2016-12-01 01:03:44163```shell
164$ git rebase-update
165$ gclient sync
166```
dpranke0ae7cad2016-11-30 07:47:58167
168The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44169any of your local branches on top of tip-of-tree (aka the Git branch
170`origin/master`). If you don't want to use this script, you can also just use
171`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58172
sdy93387fa2016-12-01 01:03:44173The second command syncs dependencies to the appropriate versions and re-runs
174hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58175
176## Tips, tricks, and troubleshooting
177
178### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44179
sdy93387fa2016-12-01 01:03:44180While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55181for building, but Xcode for editing and driving compilation. Xcode is still
182slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44183build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44184
sdy93387fa2016-12-01 01:03:44185With hybrid builds, compilation is still handled by Ninja, and can be run from
186the command line (e.g. `ninja -C out/gn chrome`) or by choosing the `chrome`
187target in the hybrid workspace and choosing Build.
andybons3322f762015-08-24 21:37:09188
sdy93387fa2016-12-01 01:03:44189To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24190
191```shell
sdy93387fa2016-12-01 01:03:44192$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24193```
andybons3322f762015-08-24 21:37:09194
thakisf28551b2016-08-09 14:42:55195Open it:
tfarina59fb57ac2016-03-02 18:17:24196
197```shell
sdy93387fa2016-12-01 01:03:44198$ open out/gn/ninja/all.xcworkspace
tfarina59fb57ac2016-03-02 18:17:24199```
andybons3322f762015-08-24 21:37:09200
andybonsad92aa32015-08-31 02:27:44201You may run into a problem where http://YES is opened as a new tab every time
202you launch Chrome. To fix this, open the scheme editor for the Run scheme,
203choose the Options tab, and uncheck "Allow debugging when using document
204Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44205`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
206gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09207
andybonsad92aa32015-08-31 02:27:44208If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44209ask there. Be sure that the
210[waterfall](http://build.chromium.org/buildbot/waterfall/) is green and the
211tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09212
dpranke0ae7cad2016-11-30 07:47:58213### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37214
215`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44216to the large number of files in Chromium's checkout, `git status` performance
217can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37218default, this command:
219
sdy93387fa2016-12-01 01:03:44220```shell
221$ sysctl -a | egrep kern\..*vnodes
222```
shess1f4c3d92015-11-05 18:15:37223
224Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
225setting:
226
sdy93387fa2016-12-01 01:03:44227```shell
228$ sudo sysctl kern.maxvnodes=$((512*1024))
229```
shess1f4c3d92015-11-05 18:15:37230
231Higher values may be appropriate if you routinely move between different
232Chromium checkouts. This setting will reset on reboot, the startup setting can
233be set in `/etc/sysctl.conf`:
234
sdy93387fa2016-12-01 01:03:44235```shell
236$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
237```
shess1f4c3d92015-11-05 18:15:37238
239Or edit the file directly.
240
sdy93387fa2016-12-01 01:03:44241If `git --version` reports 2.6 or higher, the following may also improve
shess1f4c3d92015-11-05 18:15:37242performance of `git status`:
243
sdy93387fa2016-12-01 01:03:44244```shell
245$ git update-index --untracked-cache
246```
tnagelcad631692016-04-15 11:02:36247
dpranke0ae7cad2016-11-30 07:47:58248### Xcode license agreement
tnagelcad631692016-04-15 11:02:36249
250If you're getting the error
251
sdy93387fa2016-12-01 01:03:44252> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
253> root via sudo.
tnagelcad631692016-04-15 11:02:36254
255the Xcode license hasn't been accepted yet which (contrary to the message) any
256user can do by running:
257
sdy93387fa2016-12-01 01:03:44258```shell
259$ xcodebuild -license
260```
tnagelcad631692016-04-15 11:02:36261
262Only accepting for all users of the machine requires root:
263
sdy93387fa2016-12-01 01:03:44264```shell
265$ sudo xcodebuild -license
266```