blob: 6a353304e7b027b91e6cc8efe4a3605ee5e66dbc [file] [log] [blame] [view]
andybonsad92aa32015-08-31 02:27:441# Mac Build Instructions
andybons3322f762015-08-24 21:37:092
andybonsad92aa32015-08-31 02:27:443[TOC]
andybons3322f762015-08-24 21:37:094
andybonsad92aa32015-08-31 02:27:445## Prerequisites
andybons3322f762015-08-24 21:37:096
erikchen64a06c222015-09-25 18:35:367* A Mac running 10.9+.
andybonsad92aa32015-08-31 02:27:448* http://developer.apple.com/tools/xcode/XCode, 5+
9* Install
10 [gclient](http://dev.chromium.org/developers/how-tos/install-depot-tools),
11 part of the
12 [depot_tools](http://dev.chromium.org/developers/how-tos/depottools) package
13 ([download](http://dev.chromium.org/developers/how-tos/install-depot-tools)).
14 gclient is a wrapper around svn that we use to manage our working copies.
erikchen64a06c222015-09-25 18:35:3615* Install Xcode's "Command Line Tools" via Xcode menu -> Preferences ->
andybonsad92aa32015-08-31 02:27:4416 Downloads
erikchen64a06c222015-09-25 18:35:3617* The OSX 10.10 SDK. Run
18 ```sh
19 ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
20 ```
21 to check whether you have it. If you don't have it, you need to get one from
22 an install of Xcode 6, and place it in the above directory.
andybons3322f762015-08-24 21:37:0923
andybonsad92aa32015-08-31 02:27:4424## Getting the code
andybons3322f762015-08-24 21:37:0925
andybonsad92aa32015-08-31 02:27:4426[Check out the source code](http://dev.chromium.org/developers/how-tos/get-the-code)
27using Git. If you're new to the project, you can skip all the information about
28git-svn, since you will not be committing directly to the repository.
andybons3322f762015-08-24 21:37:0929
andybonsad92aa32015-08-31 02:27:4430Before checking out, go to the
31[waterfall](http://build.chromium.org/buildbot/waterfall/) and check that the
32source tree is open (to avoid pulling a broken tree).
andybons3322f762015-08-24 21:37:0933
andybonsad92aa32015-08-31 02:27:4434The path to the build directory should not contain spaces (e.g. not
35`~/Mac OS X/chromium`), as this will cause the build to fail. This includes your
36drive name, the default "Macintosh HD2" for a second drive has a space.
andybons3322f762015-08-24 21:37:0937
andybonsad92aa32015-08-31 02:27:4438## Building
andybons3322f762015-08-24 21:37:0939
andybonsad92aa32015-08-31 02:27:4440Chromium on OS X can only be built using the [Ninja](ninja_build.md) tool and
41the [Clang](clang.md) compiler. See both of those pages for further details on
42how to tune the build.
43
44Before you build, you may want to
45[install API keys](https://sites.google.com/a/chromium.org/dev/developers/how-tos/api-keys)
46so that Chrome-integrated Google services work. This step is optional if you
47aren't testing those features.
48
49### Raising system-wide and per-user process limits
andybons3322f762015-08-24 21:37:0950
51If you see errors like the following:
52
53```
54clang: error: unable to execute command: posix_spawn failed: Resource temporarily unavailable
55clang: error: clang frontend command failed due to signal (use -v to see invocation)
56```
57
andybonsad92aa32015-08-31 02:27:4458you may be running into too-low limits on the number of concurrent processes
59allowed on the machine. Check:
andybons3322f762015-08-24 21:37:0960
andybonsad92aa32015-08-31 02:27:4461 sysctl kern.maxproc
62 sysctl kern.maxprocperuid
andybons3322f762015-08-24 21:37:0963
64You can increase them with e.g.:
65
andybonsad92aa32015-08-31 02:27:4466 sudo sysctl -w kern.maxproc=2500
67 sudo sysctl -w kern.maxprocperuid=2500
andybons3322f762015-08-24 21:37:0968
andybonsad92aa32015-08-31 02:27:4469But normally this shouldn't be necessary if you're building on 10.7 or higher.
70If you see this, check if some rogue program spawned hundreds of processes and
71kill them first.
andybons3322f762015-08-24 21:37:0972
andybonsad92aa32015-08-31 02:27:4473## Faster builds
andybons3322f762015-08-24 21:37:0974
andybonsad92aa32015-08-31 02:27:4475Full rebuilds are about the same speed in Debug and Release, but linking is a
76lot faster in Release builds.
andybons3322f762015-08-24 21:37:0977
78Run
andybons3322f762015-08-24 21:37:0979
andybonsad92aa32015-08-31 02:27:4480 GYP_DEFINES=fastbuild=1 build/gyp_chromium
andybons3322f762015-08-24 21:37:0981
andybonsad92aa32015-08-31 02:27:4482to disable debug symbols altogether, this makes both full rebuilds and linking
83faster (at the cost of not getting symbolized backtraces in gdb).
andybons3322f762015-08-24 21:37:0984
philipj5a0fcb92016-01-23 23:23:4085You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:0986
andybonsad92aa32015-08-31 02:27:4487## Running
andybons3322f762015-08-24 21:37:0988
andybonsad92aa32015-08-31 02:27:4489All build output is located in the `out` directory (in the example above,
90`~/chromium/src/out`). You can find the applications at
91`{Debug|Release}/ContentShell.app` and `{Debug|Release}/Chromium.app`, depending
92on the selected configuration.
andybons3322f762015-08-24 21:37:0993
andybonsad92aa32015-08-31 02:27:4494## Unit Tests
andybons3322f762015-08-24 21:37:0995
andybonsad92aa32015-08-31 02:27:4496We have several unit test targets that build, and tests that run and pass. A
97small subset of these is:
andybons3322f762015-08-24 21:37:0998
andybonsad92aa32015-08-31 02:27:4499* `unit_tests` from `chrome/chrome.gyp`
100* `base_unittests` from `base/base.gyp`
101* `net_unittests` from `net/net.gyp`
102* `url_unittests` from `url/url.gyp`
andybons3322f762015-08-24 21:37:09103
andybonsad92aa32015-08-31 02:27:44104When these tests are built, you will find them in the `out/{Debug|Release}`
105directory. You can run them from the command line:
andybons3322f762015-08-24 21:37:09106
andybonsad92aa32015-08-31 02:27:44107 ~/chromium/src/out/Release/unit_tests
andybons3322f762015-08-24 21:37:09108
andybons3322f762015-08-24 21:37:09109
andybonsad92aa32015-08-31 02:27:44110## Coding
andybons3322f762015-08-24 21:37:09111
andybonsad92aa32015-08-31 02:27:44112According to the
113[Chromium style guide](http://dev.chromium.org/developers/coding-style) code is
114[not allowed to have whitespace on the ends of lines](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Horizontal_Whitespace).
115If you edit in Xcode, know that it loves adding whitespace to the ends of lines
116which can make editing in Xcode more painful than it should be. The
117[GTM Xcode Plugin](http://code.google.com/p/google-toolbox-for-mac/downloads/list)
118adds a preference panel to Xcode that allows you to strip whitespace off of the
119ends of lines on save. Documentation on how to install it is
120[here](http://code.google.com/p/google-toolbox-for-mac/wiki/GTMXcodePlugin).
andybons3322f762015-08-24 21:37:09121
andybonsad92aa32015-08-31 02:27:44122## Debugging
andybons3322f762015-08-24 21:37:09123
andybonsad92aa32015-08-31 02:27:44124Good debugging tips can be found
125[here](http://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you
126would like to debug in a graphical environment, rather than using `lldb` at the
127command line, that is possible without building in Xcode. See
128[Debugging in Xcode](http://www.chromium.org/developers/debugging-on-os-x/building-with-ninja-debugging-with-xcode)
129for information on how.
andybons3322f762015-08-24 21:37:09130
andybonsad92aa32015-08-31 02:27:44131## Contributing
132
133Once youre comfortable with building Chromium, check out
134[Contributing Code](http://dev.chromium.org/developers/contributing-code) for
135information about writing code for Chromium and contributing it.
136
137## Using Xcode-Ninja Hybrid
138
139While using Xcode is unsupported, GYP supports a hybrid approach of using ninja
140for building, but Xcode for editing and driving compliation. Xcode can still be
141slow, but it runs fairly well even **with indexing enabled**.
142
143With hybrid builds, compilation is still handled by ninja, and can be run by the
144command line (e.g. ninja -C out/Debug chrome) or by choosing the chrome target
145in the hybrid workspace and choosing build.
andybons3322f762015-08-24 21:37:09146
147To use Xcode-Ninja Hybrid, set `GYP_GENERATORS=ninja,xcode-ninja`.
148
andybonsad92aa32015-08-31 02:27:44149Due to the way Xcode parses ninja output paths, it's also necessary to change
150the main gyp location to anything two directories deep. Otherwise Xcode build
151output will not be clickable. Adding
152`xcode_ninja_main_gyp=src/build/ninja/all.ninja.gyp` to your
153`GYP_GENERATOR_FLAGS` will fix this.
andybons3322f762015-08-24 21:37:09154
andybonsad92aa32015-08-31 02:27:44155After generating the project files with gclient runhooks, open
156`src/build/ninja/all.ninja.xcworkspace`.
andybons3322f762015-08-24 21:37:09157
andybonsad92aa32015-08-31 02:27:44158You may run into a problem where http://YES is opened as a new tab every time
159you launch Chrome. To fix this, open the scheme editor for the Run scheme,
160choose the Options tab, and uncheck "Allow debugging when using document
161Versions Browser". When this option is checked, Xcode adds
162`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES` gets
163interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09164
andybonsad92aa32015-08-31 02:27:44165If you want to limit the number of targets visible, which is known to improve
166Xcode performance, add `xcode_ninja_executable_target_pattern=%target%` where
167`%target%` is a regular expression matching executable targets you'd like to
168include.
andybons3322f762015-08-24 21:37:09169
170To include non-executable targets, use `xcode_ninja_target_pattern=All_iOS`.
171
andybonsad92aa32015-08-31 02:27:44172If you have problems building, join us in `#chromium` on `irc.freenode.net` and
173ask there. As mentioned above, be sure that the
174[waterfall](http://build.chromium.org/buildbot/waterfall/) is green and the tree
175is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09176
andybonsad92aa32015-08-31 02:27:44177## Using Emacs as `EDITOR` for `git commit`
andybons3322f762015-08-24 21:37:09178
andybonsad92aa32015-08-31 02:27:44179Using the [Cocoa version of Emacs](http://emacsformacosx.com/) as the `EDITOR`
180environment variable on Mac OS will cause `git commit` to open the message in a
181window underneath all the others. To fix this, create a shell script somewhere
182(call it `$HOME/bin/EmacsEditor` in this example) containing the following:
andybons3322f762015-08-24 21:37:09183
184```
185#!/bin/sh
186
187# All of these hacks are needed to get "git commit" to launch a new
188# instance of Emacs on top of everything else, properly pointing to
189# the COMMIT_EDITMSG.
190
191realpath() {
192 [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
193}
194
195i=0
196full_paths=()
197for arg in "$@"
198do
199 full_paths[$i]=$(realpath $arg)
200 ((++i))
201done
202
andybonsad92aa32015-08-31 02:27:44203open -nWa /Applications/Emacs.app/Contents/MacOS/Emacs --args --no-desktop \
204 "${full_paths[@]}"
andybons3322f762015-08-24 21:37:09205```
206
andybonsad92aa32015-08-31 02:27:44207and in your `.bashrc` or similar,
andybons3322f762015-08-24 21:37:09208
andybonsad92aa32015-08-31 02:27:44209 export EDITOR=$HOME/bin/EmacsEditor
shess1f4c3d92015-11-05 18:15:37210
211## Improving performance of `git status`
212
213`git status` is used frequently to determine the status of your checkout. Due
214to the number of files in Chromium's checkout, `git status` performance can be
215quite variable. Increasing the system's vnode cache appears to help. By
216default, this command:
217
218 sysctl -a | egrep kern\..*vnodes
219
220Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
221setting:
222
223 sudo sysctl kern.maxvnodes=$((512*1024))
224
225Higher values may be appropriate if you routinely move between different
226Chromium checkouts. This setting will reset on reboot, the startup setting can
227be set in `/etc/sysctl.conf`:
228
229 echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
230
231Or edit the file directly.
232
233If your `git --version` reports 2.6 or higher, the following may also improve
234performance of `git status`:
235
236 git update-index --untracked-cache