andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 1 | # Mac Build Instructions |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 3 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 4 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 5 | ## Prerequisites |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 6 | |
erikchen | 64a06c22 | 2015-09-25 18:35:36 | [diff] [blame] | 7 | * A Mac running 10.9+. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 8 | * 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. |
erikchen | 64a06c22 | 2015-09-25 18:35:36 | [diff] [blame] | 15 | * Install Xcode's "Command Line Tools" via Xcode menu -> Preferences -> |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 16 | Downloads |
erikchen | 64a06c22 | 2015-09-25 18:35:36 | [diff] [blame] | 17 | * 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. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 23 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 24 | ## Getting the code |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 25 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 26 | [Check out the source code](http://dev.chromium.org/developers/how-tos/get-the-code) |
| 27 | using Git. If you're new to the project, you can skip all the information about |
| 28 | git-svn, since you will not be committing directly to the repository. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 30 | Before checking out, go to the |
| 31 | [waterfall](http://build.chromium.org/buildbot/waterfall/) and check that the |
| 32 | source tree is open (to avoid pulling a broken tree). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 33 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 34 | The 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 |
| 36 | drive name, the default "Macintosh HD2" for a second drive has a space. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 37 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 38 | ## Building |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 39 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 40 | Chromium on OS X can only be built using the [Ninja](ninja_build.md) tool and |
| 41 | the [Clang](clang.md) compiler. See both of those pages for further details on |
| 42 | how to tune the build. |
| 43 | |
| 44 | Before you build, you may want to |
| 45 | [install API keys](https://sites.google.com/a/chromium.org/dev/developers/how-tos/api-keys) |
| 46 | so that Chrome-integrated Google services work. This step is optional if you |
| 47 | aren't testing those features. |
| 48 | |
| 49 | ### Raising system-wide and per-user process limits |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 50 | |
| 51 | If you see errors like the following: |
| 52 | |
| 53 | ``` |
| 54 | clang: error: unable to execute command: posix_spawn failed: Resource temporarily unavailable |
| 55 | clang: error: clang frontend command failed due to signal (use -v to see invocation) |
| 56 | ``` |
| 57 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 58 | you may be running into too-low limits on the number of concurrent processes |
| 59 | allowed on the machine. Check: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 60 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 61 | sysctl kern.maxproc |
| 62 | sysctl kern.maxprocperuid |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 63 | |
| 64 | You can increase them with e.g.: |
| 65 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 66 | sudo sysctl -w kern.maxproc=2500 |
| 67 | sudo sysctl -w kern.maxprocperuid=2500 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 68 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 69 | But normally this shouldn't be necessary if you're building on 10.7 or higher. |
| 70 | If you see this, check if some rogue program spawned hundreds of processes and |
| 71 | kill them first. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 72 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 73 | ## Faster builds |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 74 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 75 | Full rebuilds are about the same speed in Debug and Release, but linking is a |
| 76 | lot faster in Release builds. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 77 | |
| 78 | Run |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 79 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 80 | GYP_DEFINES=fastbuild=1 build/gyp_chromium |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 81 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 82 | to disable debug symbols altogether, this makes both full rebuilds and linking |
| 83 | faster (at the cost of not getting symbolized backtraces in gdb). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 84 | |
philipj | 5a0fcb9 | 2016-01-23 23:23:40 | [diff] [blame^] | 85 | 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] | 86 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 87 | ## Running |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 88 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 89 | All 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 |
| 92 | on the selected configuration. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 93 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 94 | ## Unit Tests |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 95 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 96 | We have several unit test targets that build, and tests that run and pass. A |
| 97 | small subset of these is: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 98 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 99 | * `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` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 103 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 104 | When these tests are built, you will find them in the `out/{Debug|Release}` |
| 105 | directory. You can run them from the command line: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 106 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 107 | ~/chromium/src/out/Release/unit_tests |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 108 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 109 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 110 | ## Coding |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 111 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 112 | According 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). |
| 115 | If you edit in Xcode, know that it loves adding whitespace to the ends of lines |
| 116 | which 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) |
| 118 | adds a preference panel to Xcode that allows you to strip whitespace off of the |
| 119 | ends of lines on save. Documentation on how to install it is |
| 120 | [here](http://code.google.com/p/google-toolbox-for-mac/wiki/GTMXcodePlugin). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 121 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 122 | ## Debugging |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 123 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 124 | Good debugging tips can be found |
| 125 | [here](http://dev.chromium.org/developers/how-tos/debugging-on-os-x). If you |
| 126 | would like to debug in a graphical environment, rather than using `lldb` at the |
| 127 | command 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) |
| 129 | for information on how. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 130 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 131 | ## Contributing |
| 132 | |
| 133 | Once you’re comfortable with building Chromium, check out |
| 134 | [Contributing Code](http://dev.chromium.org/developers/contributing-code) for |
| 135 | information about writing code for Chromium and contributing it. |
| 136 | |
| 137 | ## Using Xcode-Ninja Hybrid |
| 138 | |
| 139 | While using Xcode is unsupported, GYP supports a hybrid approach of using ninja |
| 140 | for building, but Xcode for editing and driving compliation. Xcode can still be |
| 141 | slow, but it runs fairly well even **with indexing enabled**. |
| 142 | |
| 143 | With hybrid builds, compilation is still handled by ninja, and can be run by the |
| 144 | command line (e.g. ninja -C out/Debug chrome) or by choosing the chrome target |
| 145 | in the hybrid workspace and choosing build. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 146 | |
| 147 | To use Xcode-Ninja Hybrid, set `GYP_GENERATORS=ninja,xcode-ninja`. |
| 148 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 149 | Due to the way Xcode parses ninja output paths, it's also necessary to change |
| 150 | the main gyp location to anything two directories deep. Otherwise Xcode build |
| 151 | output 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. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 154 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 155 | After generating the project files with gclient runhooks, open |
| 156 | `src/build/ninja/all.ninja.xcworkspace`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 157 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 158 | You may run into a problem where http://YES is opened as a new tab every time |
| 159 | you launch Chrome. To fix this, open the scheme editor for the Run scheme, |
| 160 | choose the Options tab, and uncheck "Allow debugging when using document |
| 161 | Versions Browser". When this option is checked, Xcode adds |
| 162 | `--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES` gets |
| 163 | interpreted as a URL to open. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 164 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 165 | If you want to limit the number of targets visible, which is known to improve |
| 166 | Xcode performance, add `xcode_ninja_executable_target_pattern=%target%` where |
| 167 | `%target%` is a regular expression matching executable targets you'd like to |
| 168 | include. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 169 | |
| 170 | To include non-executable targets, use `xcode_ninja_target_pattern=All_iOS`. |
| 171 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 172 | If you have problems building, join us in `#chromium` on `irc.freenode.net` and |
| 173 | ask there. As mentioned above, be sure that the |
| 174 | [waterfall](http://build.chromium.org/buildbot/waterfall/) is green and the tree |
| 175 | is open before checking out. This will increase your chances of success. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 176 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 177 | ## Using Emacs as `EDITOR` for `git commit` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 178 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 179 | Using the [Cocoa version of Emacs](http://emacsformacosx.com/) as the `EDITOR` |
| 180 | environment variable on Mac OS will cause `git commit` to open the message in a |
| 181 | window underneath all the others. To fix this, create a shell script somewhere |
| 182 | (call it `$HOME/bin/EmacsEditor` in this example) containing the following: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 183 | |
| 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 | |
| 191 | realpath() { |
| 192 | [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" |
| 193 | } |
| 194 | |
| 195 | i=0 |
| 196 | full_paths=() |
| 197 | for arg in "$@" |
| 198 | do |
| 199 | full_paths[$i]=$(realpath $arg) |
| 200 | ((++i)) |
| 201 | done |
| 202 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 203 | open -nWa /Applications/Emacs.app/Contents/MacOS/Emacs --args --no-desktop \ |
| 204 | "${full_paths[@]}" |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 205 | ``` |
| 206 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 207 | and in your `.bashrc` or similar, |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 208 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 209 | export EDITOR=$HOME/bin/EmacsEditor |
shess | 1f4c3d9 | 2015-11-05 18:15:37 | [diff] [blame] | 210 | |
| 211 | ## Improving performance of `git status` |
| 212 | |
| 213 | `git status` is used frequently to determine the status of your checkout. Due |
| 214 | to the number of files in Chromium's checkout, `git status` performance can be |
| 215 | quite variable. Increasing the system's vnode cache appears to help. By |
| 216 | default, this command: |
| 217 | |
| 218 | sysctl -a | egrep kern\..*vnodes |
| 219 | |
| 220 | Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this |
| 221 | setting: |
| 222 | |
| 223 | sudo sysctl kern.maxvnodes=$((512*1024)) |
| 224 | |
| 225 | Higher values may be appropriate if you routinely move between different |
| 226 | Chromium checkouts. This setting will reset on reboot, the startup setting can |
| 227 | be set in `/etc/sysctl.conf`: |
| 228 | |
| 229 | echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf |
| 230 | |
| 231 | Or edit the file directly. |
| 232 | |
| 233 | If your `git --version` reports 2.6 or higher, the following may also improve |
| 234 | performance of `git status`: |
| 235 | |
| 236 | git update-index --untracked-cache |