dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame^] | 1 | # Checking out and building Chromium for Mac |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame^] | 3 | There 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 | |
| 10 | Are you a Google employee? See |
| 11 | [go/building-chrome](https://goto.google.com/building-chrome) instead. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 12 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 13 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 14 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 15 | ## System requirements |
sdy | a8197bd2 | 2016-09-14 19:06:42 | [diff] [blame] | 16 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 17 | * A 64-bit Mac running 10.9+. |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 18 | * [Xcode](https://developer.apple.com/xcode) 7.3+. |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 19 | * The OS X 10.10 SDK. Run |
| 20 | |
| 21 | ```shell |
| 22 | $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs |
dominicc | a4e4c99 | 2016-05-23 22:08:03 | [diff] [blame] | 23 | ``` |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 24 | |
| 25 | to check whether you have it. Building with a newer SDK works too, but |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 26 | the releases currently use the 10.10 SDK. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 27 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 28 | ## Install `depot_tools` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 30 | Clone the `depot_tools` repository: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 31 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 32 | ```shell |
| 33 | $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 34 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 35 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 36 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 37 | in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to |
| 38 | `/path/to/depot_tools`: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 39 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 40 | ```shell |
| 41 | $ export PATH="$PATH:/path/to/depot_tools" |
| 42 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 43 | |
| 44 | ## Get the code |
| 45 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 46 | Create a `chromium` directory for the checkout and change to it (you can call |
| 47 | this whatever you like and put it wherever you like, as long as the full path |
| 48 | has no spaces): |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 49 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 50 | ```shell |
| 51 | $ mkdir chromium && cd chromium |
| 52 | ``` |
| 53 | |
| 54 | Run the `fetch` tool from `depot_tools` to check out the code and its |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 55 | dependencies. |
| 56 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 57 | ```shell |
| 58 | $ fetch chromium |
| 59 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 60 | |
| 61 | If you don't want the full repo history, you can save a lot of time by |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 62 | adding the `--no-history` flag to `fetch`. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 63 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 64 | Expect the command to take 30 minutes on even a fast connection, and many |
| 65 | hours on slower ones. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 66 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 67 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 68 | directory called `src` in the working directory. The remaining instructions |
| 69 | assume you have switched to the `src` directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 70 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 71 | ```shell |
| 72 | $ cd src |
| 73 | ``` |
| 74 | |
| 75 | *Optional*: You can also [install API |
| 76 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 77 | build to talk to some Google services, but this is not necessary for most |
| 78 | development and testing purposes. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 79 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame^] | 80 | ## Setting up the build |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 81 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 82 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along |
| 83 | with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja` |
| 84 | files. You can create any number of *build directories* with different |
| 85 | configurations. To create a build directory: |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 86 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 87 | ```shell |
| 88 | $ gn gen out/Default |
| 89 | ``` |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 90 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 91 | * 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). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 97 | 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). |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 101 | |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 102 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 103 | ### Faster builds |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 104 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 105 | Full rebuilds are about the same speed in Debug and Release, but linking is a |
| 106 | lot faster in Release builds. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 107 | |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 108 | Put |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 109 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 110 | ``` |
| 111 | is_debug = false |
| 112 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 113 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 114 | in your `args.gn` to do a release build. |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 115 | |
| 116 | Put |
| 117 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 118 | ``` |
| 119 | is_component_build = true |
| 120 | ``` |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 121 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 122 | in your `args.gn` to build many small dylibs instead of a single large |
| 123 | executable. This makes incremental builds much faster, at the cost of producing |
| 124 | a binary that opens less quickly. Component builds work in both debug and |
| 125 | release. |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 126 | |
| 127 | Put |
| 128 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 129 | ``` |
| 130 | symbol_level = 0 |
| 131 | ``` |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 132 | |
| 133 | in your args.gn to disable debug symbols altogether. This makes both full |
| 134 | rebuilds and linking faster (at the cost of not getting symbolized backtraces |
| 135 | in gdb). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 136 | |
philipj | 5a0fcb9 | 2016-01-23 23:23:40 | [diff] [blame] | 137 | You might also want to [install ccache](ccache_mac.md) to speed up the build. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 138 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame^] | 139 | ## Build Chromium |
| 140 | |
| 141 | Build Chromium (the "chrome" target) with Ninja using the command: |
| 142 | |
| 143 | ```shell |
| 144 | $ ninja -C out/Default chrome |
| 145 | ``` |
| 146 | |
| 147 | You can get a list of all of the other build targets from GN by running `gn ls |
| 148 | out/Default` from the command line. To compile one, pass the GN label to Ninja |
| 149 | with no preceding "//" (so, for `//chrome/test:unit_tests` use `ninja -C |
| 150 | out/Default chrome/test:unit_tests`). |
| 151 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 152 | ## Run Chromium |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 153 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 154 | Once it is built, you can simply run the browser: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 155 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 156 | ```shell |
| 157 | $ out/Default/chrome |
| 158 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 159 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 160 | ## Running test targets |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 161 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 162 | You can run the tests in the same way. You can also limit which tests are |
| 163 | run using the `--gtest_filter` arg, e.g.: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 164 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 165 | ``` |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame^] | 166 | $ out/Default/unit_tests --gtest_filter="PushClientTest.*" |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 167 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 168 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 169 | You can find out more about GoogleTest at its |
| 170 | [GitHub page](https://github.com/google/googletest). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 171 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 172 | ## Debugging |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 173 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 174 | Good debugging tips can be found |
| 175 | [here](http://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you |
| 176 | would like to debug in a graphical environment, rather than using `lldb` at the |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 177 | command 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)). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 179 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 180 | ## Update your checkout |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 181 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 182 | To update an existing checkout, you can run |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 183 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 184 | ```shell |
| 185 | $ git rebase-update |
| 186 | $ gclient sync |
| 187 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 188 | |
| 189 | The first command updates the primary Chromium source repository and rebases |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 190 | any 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. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 193 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 194 | The second command syncs dependencies to the appropriate versions and re-runs |
| 195 | hooks as needed. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 196 | |
| 197 | ## Tips, tricks, and troubleshooting |
| 198 | |
| 199 | ### Using Xcode-Ninja Hybrid |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 200 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 201 | While using Xcode is unsupported, GN supports a hybrid approach of using Ninja |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 202 | for building, but Xcode for editing and driving compilation. Xcode is still |
| 203 | slow, but it runs fairly well even **with indexing enabled**. Most people |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 204 | build in the Terminal and write code with a text editor, though. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 205 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 206 | With hybrid builds, compilation is still handled by Ninja, and can be run from |
| 207 | the command line (e.g. `ninja -C out/gn chrome`) or by choosing the `chrome` |
| 208 | target in the hybrid workspace and choosing Build. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 209 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 210 | To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`: |
tfarina | 59fb57ac | 2016-03-02 18:17:24 | [diff] [blame] | 211 | |
| 212 | ```shell |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 213 | $ gn gen out/gn --ide=xcode |
tfarina | 59fb57ac | 2016-03-02 18:17:24 | [diff] [blame] | 214 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 215 | |
thakis | f28551b | 2016-08-09 14:42:55 | [diff] [blame] | 216 | Open it: |
tfarina | 59fb57ac | 2016-03-02 18:17:24 | [diff] [blame] | 217 | |
| 218 | ```shell |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 219 | $ open out/gn/ninja/all.xcworkspace |
tfarina | 59fb57ac | 2016-03-02 18:17:24 | [diff] [blame] | 220 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 221 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 222 | You may run into a problem where http://YES is opened as a new tab every time |
| 223 | you launch Chrome. To fix this, open the scheme editor for the Run scheme, |
| 224 | choose the Options tab, and uncheck "Allow debugging when using document |
| 225 | Versions Browser". When this option is checked, Xcode adds |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 226 | `--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES` |
| 227 | gets interpreted as a URL to open. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 228 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 229 | If you have problems building, join us in `#chromium` on `irc.freenode.net` and |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 230 | ask there. Be sure that the |
| 231 | [waterfall](http://build.chromium.org/buildbot/waterfall/) is green and the |
| 232 | tree is open before checking out. This will increase your chances of success. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 233 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 234 | ### Improving performance of `git status` |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 235 | |
| 236 | `git status` is used frequently to determine the status of your checkout. Due |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 237 | to the large number of files in Chromium's checkout, `git status` performance |
| 238 | can be quite variable. Increasing the system's vnode cache appears to help. By |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 239 | default, this command: |
| 240 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 241 | ```shell |
| 242 | $ sysctl -a | egrep kern\..*vnodes |
| 243 | ``` |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 244 | |
| 245 | Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this |
| 246 | setting: |
| 247 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 248 | ```shell |
| 249 | $ sudo sysctl kern.maxvnodes=$((512*1024)) |
| 250 | ``` |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 251 | |
| 252 | Higher values may be appropriate if you routinely move between different |
| 253 | Chromium checkouts. This setting will reset on reboot, the startup setting can |
| 254 | be set in `/etc/sysctl.conf`: |
| 255 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 256 | ```shell |
| 257 | $ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf |
| 258 | ``` |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 259 | |
| 260 | Or edit the file directly. |
| 261 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 262 | If `git --version` reports 2.6 or higher, the following may also improve |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 263 | performance of `git status`: |
| 264 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 265 | ```shell |
| 266 | $ git update-index --untracked-cache |
| 267 | ``` |
tnagel | cad63169 | 2016-04-15 11:02:36 | [diff] [blame] | 268 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 269 | ### Xcode license agreement |
tnagel | cad63169 | 2016-04-15 11:02:36 | [diff] [blame] | 270 | |
| 271 | If you're getting the error |
| 272 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 273 | > Agreeing to the Xcode/iOS license requires admin privileges, please re-run as |
| 274 | > root via sudo. |
tnagel | cad63169 | 2016-04-15 11:02:36 | [diff] [blame] | 275 | |
| 276 | the Xcode license hasn't been accepted yet which (contrary to the message) any |
| 277 | user can do by running: |
| 278 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 279 | ```shell |
| 280 | $ xcodebuild -license |
| 281 | ``` |
tnagel | cad63169 | 2016-04-15 11:02:36 | [diff] [blame] | 282 | |
| 283 | Only accepting for all users of the machine requires root: |
| 284 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 285 | ```shell |
| 286 | $ sudo xcodebuild -license |
| 287 | ``` |