blob: a16f976642dc25eab68a0e5a93a20da0959744a9 [file] [log] [blame] [view]
dpranke1a70d0c2016-12-01 02:42:291# Checking out and building Chromium for Mac
andybons3322f762015-08-24 21:37:092
erikchen7d7509a2017-10-02 23:40:363There are instructions for other platforms linked from the
dpranke1a70d0c2016-12-01 02:42:294[get the code](get_the_code.md) page.
5
dpranke1a70d0c2016-12-01 02:42:296## Instructions for Google Employees
7
8Are you a Google employee? See
9[go/building-chrome](https://goto.google.com/building-chrome) instead.
dpranke0ae7cad2016-11-30 07:47:5810
andybonsad92aa32015-08-31 02:27:4411[TOC]
andybons3322f762015-08-24 21:37:0912
dpranke0ae7cad2016-11-30 07:47:5813## System requirements
sdya8197bd22016-09-14 19:06:4214
Nico Weber3c9befa2021-11-03 17:07:1115* A Mac, Intel or Arm.
Avi Drissmanab7729b2021-06-10 19:17:1516 ([More details about Arm Macs](https://chromium.googlesource.com/chromium/src.git/+/main/docs/mac_arm64.md).)
Nico Weber3c9befa2021-11-03 17:07:1117* [Xcode](https://developer.apple.com/xcode/). Xcode comes with...
18* The macOS SDK. Run
sdy93387fa2016-12-01 01:03:4419
erikchen7d7509a2017-10-02 23:40:3620 ```shell
sdy93387fa2016-12-01 01:03:4421 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
dominicca4e4c992016-05-23 22:08:0322 ```
erikchen7d7509a2017-10-02 23:40:3623
Nico Weber3c9befa2021-11-03 17:07:1124 to check whether you have it, and what version you have.
25 `mac_sdk_official_version` in [mac_sdk.gni](../build/config/mac/mac_sdk.gni)
26 is the SDK version used on all the bots and for
27 [official builds](https://source.chromium.org/search?q=MAC_BINARIES_LABEL&ss=chromium),
28 so that version is guaranteed to work. Building with a newer SDK usually
29 works too (please fix or file a bug if it doesn't).
wafuwafu13b6854ba52021-12-24 06:02:4330
Nico Weber3c9befa2021-11-03 17:07:1131 Building with an older SDK might also work, but if it doesn't then we won't
32 accept changes for making it work.
wafuwafu13b6854ba52021-12-24 06:02:4333
Nico Weber3c9befa2021-11-03 17:07:1134 The easiest way to get the newest SDK is to use the newest version of Xcode,
35 which often requires using the newest version of macOS. We don't use Xcode
36 itself much, so if you're know what you're doing, you can likely get the
37 build working with an older version of macOS as long as you get a new
38 version of the macOS SDK on it.
Nico Weber36cd0a552022-01-18 16:31:4939* An APFS-formatted volume (this is the default format for macOS volumes).
andybons3322f762015-08-24 21:37:0940
dpranke0ae7cad2016-11-30 07:47:5841## Install `depot_tools`
andybons3322f762015-08-24 21:37:0942
sdy93387fa2016-12-01 01:03:4443Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0944
sdy93387fa2016-12-01 01:03:4445```shell
46$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
47```
andybons3322f762015-08-24 21:37:0948
Gabriel Charetteb6780c12019-04-24 16:23:5249Add `depot_tools` to the end of your PATH (you will probably want to put this in
50your `~/.bash_profile` or `~/.zshrc`). Assuming you cloned `depot_tools` to
51`/path/to/depot_tools` (note: you **must** use the absolute path or Python will
52not be able to find infra tools):
dpranke0ae7cad2016-11-30 07:47:5853
sdy93387fa2016-12-01 01:03:4454```shell
55$ export PATH="$PATH:/path/to/depot_tools"
56```
dpranke0ae7cad2016-11-30 07:47:5857
58## Get the code
59
Aaron Gable94b7e2a32018-01-03 19:14:4160Ensure that unicode filenames aren't mangled by HFS:
61
62```shell
63$ git config --global core.precomposeUnicode true
64```
65
L. David Baron8d606c542021-03-05 19:56:0766In System Preferences, check that "Energy Saver" -> "Power Adapter" ->
67"Prevent computer from sleeping automatically when the display is off" is
68checked so that your laptop doesn't go to sleep and interrupt the long network
69connection needed here.
70
sdy93387fa2016-12-01 01:03:4471Create a `chromium` directory for the checkout and change to it (you can call
72this whatever you like and put it wherever you like, as long as the full path
73has no spaces):
dpranke0ae7cad2016-11-30 07:47:5874
sdy93387fa2016-12-01 01:03:4475```shell
76$ mkdir chromium && cd chromium
77```
78
79Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5880dependencies.
81
sdy93387fa2016-12-01 01:03:4482```shell
83$ fetch chromium
84```
dpranke0ae7cad2016-11-30 07:47:5885
[email protected]1436b952018-10-26 16:35:1386If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1987`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
88the full history later.
dpranke0ae7cad2016-11-30 07:47:5889
sdy93387fa2016-12-01 01:03:4490Expect the command to take 30 minutes on even a fast connection, and many
91hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5892
sdy93387fa2016-12-01 01:03:4493When `fetch` completes, it will have created a hidden `.gclient` file and a
94directory called `src` in the working directory. The remaining instructions
95assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5896
sdy93387fa2016-12-01 01:03:4497```shell
98$ cd src
99```
100
101*Optional*: You can also [install API
102keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
103build to talk to some Google services, but this is not necessary for most
104development and testing purposes.
andybons3322f762015-08-24 21:37:09105
dpranke1a70d0c2016-12-01 02:42:29106## Setting up the build
andybons3322f762015-08-24 21:37:09107
Tom Bridgwatereef401542018-08-17 00:54:43108Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
Andrew Williamsbbc1a1e2021-07-21 01:51:22109a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md)
Tom Bridgwatereef401542018-08-17 00:54:43110to generate `.ninja` files. You can create any number of *build directories*
111with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:44112
sdy93387fa2016-12-01 01:03:44113```shell
114$ gn gen out/Default
115```
thakisf28551b2016-08-09 14:42:55116
sdy93387fa2016-12-01 01:03:44117* You only have to run this once for each new build directory, Ninja will
118 update the build files as needed.
119* You can replace `Default` with another name, but
120 it should be a subdirectory of `out`.
121* For other build arguments, including release settings, see [GN build
122 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58123 The default will be a debug component build matching the current host
124 operating system and CPU.
125* For more info on GN, run `gn help` on the command line or read the
Andrew Williamsbbc1a1e2021-07-21 01:51:22126 [quick start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
Reilly Grantf057adf2020-11-03 17:42:37127* Building Chromium for arm Macs requires [additional setup](mac_arm64.md).
thakisf28551b2016-08-09 14:42:55128
thakisf28551b2016-08-09 14:42:55129
dpranke0ae7cad2016-11-30 07:47:58130### Faster builds
andybons3322f762015-08-24 21:37:09131
andybonsad92aa32015-08-31 02:27:44132Full rebuilds are about the same speed in Debug and Release, but linking is a
133lot faster in Release builds.
andybons3322f762015-08-24 21:37:09134
thakisf28551b2016-08-09 14:42:55135Put
andybons3322f762015-08-24 21:37:09136
sdy93387fa2016-12-01 01:03:44137```
138is_debug = false
139```
andybons3322f762015-08-24 21:37:09140
sdy93387fa2016-12-01 01:03:44141in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55142
143Put
144
sdy93387fa2016-12-01 01:03:44145```
146is_component_build = true
147```
thakisf28551b2016-08-09 14:42:55148
sdy93387fa2016-12-01 01:03:44149in your `args.gn` to build many small dylibs instead of a single large
150executable. This makes incremental builds much faster, at the cost of producing
151a binary that opens less quickly. Component builds work in both debug and
152release.
thakisf28551b2016-08-09 14:42:55153
154Put
155
sdy93387fa2016-12-01 01:03:44156```
157symbol_level = 0
158```
thakisf28551b2016-08-09 14:42:55159
160in your args.gn to disable debug symbols altogether. This makes both full
161rebuilds and linking faster (at the cost of not getting symbolized backtraces
162in gdb).
andybons3322f762015-08-24 21:37:09163
Philip Rogerseb841682017-10-09 16:08:50164#### CCache
165
philipj5a0fcb92016-01-23 23:23:40166You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09167
dpranke1a70d0c2016-12-01 02:42:29168## Build Chromium
169
170Build Chromium (the "chrome" target) with Ninja using the command:
171
172```shell
Max Morozf5b31fcd2018-08-10 21:55:48173$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29174```
175
Dirk Pranke8bd55f22018-10-24 21:22:10176(`autoninja` is a wrapper that automatically provides optimal values for the
177arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48178
dpranke1a70d0c2016-12-01 02:42:29179You can get a list of all of the other build targets from GN by running `gn ls
180out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48181with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29182out/Default chrome/test:unit_tests`).
183
dpranke0ae7cad2016-11-30 07:47:58184## Run Chromium
andybons3322f762015-08-24 21:37:09185
dpranke0ae7cad2016-11-30 07:47:58186Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09187
sdy93387fa2016-12-01 01:03:44188```shell
Owen Min83eda1102017-06-28 18:47:21189$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44190```
andybons3322f762015-08-24 21:37:09191
Dominic Mazzonia7494a52020-08-06 19:19:11192## Avoiding the "incoming network connections" dialog
193
194Every time you start a new developer build of Chrome you get a system dialog
195asking "Do you want the application Chromium.app to accept incoming
196network connections?" - to avoid this, run with this command-line flag:
197
mark a. foltza25bb8c2021-11-10 20:38:48198--disable-features="DialMediaRouteProvider"
Dominic Mazzonia7494a52020-08-06 19:19:11199
wafuwafu13b6854ba52021-12-24 06:02:43200## Build and run test targets
andybons3322f762015-08-24 21:37:09201
wafuwafu13b6854ba52021-12-24 06:02:43202You can build a test in the same way, e.g.:
203
204```shell
205$ autoninja -C out/Default unit_tests
206```
207
208and can run the tests in the same way. You can also limit which tests are
dpranke0ae7cad2016-11-30 07:47:58209run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09210
sdy93387fa2016-12-01 01:03:44211```
dpranke1a70d0c2016-12-01 02:42:29212$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44213```
andybons3322f762015-08-24 21:37:09214
dpranke0ae7cad2016-11-30 07:47:58215You can find out more about GoogleTest at its
216[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09217
andybonsad92aa32015-08-31 02:27:44218## Debugging
andybons3322f762015-08-24 21:37:09219
Robert Sesek3b731b12021-04-14 21:54:03220Good debugging tips can be found [here](mac/debugging.md).
Vaclav Brozek539499e2018-07-18 11:19:51221
dpranke0ae7cad2016-11-30 07:47:58222## Update your checkout
andybonsad92aa32015-08-31 02:27:44223
dpranke0ae7cad2016-11-30 07:47:58224To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44225
sdy93387fa2016-12-01 01:03:44226```shell
227$ git rebase-update
228$ gclient sync
229```
dpranke0ae7cad2016-11-30 07:47:58230
231The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44232any of your local branches on top of tip-of-tree (aka the Git branch
Andrew Williamsbbc1a1e2021-07-21 01:51:22233`origin/main`). If you don't want to use this script, you can also just use
sdy93387fa2016-12-01 01:03:44234`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58235
sdy93387fa2016-12-01 01:03:44236The second command syncs dependencies to the appropriate versions and re-runs
237hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58238
239## Tips, tricks, and troubleshooting
240
241### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44242
sdy93387fa2016-12-01 01:03:44243While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55244for building, but Xcode for editing and driving compilation. Xcode is still
245slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44246build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44247
sdy93387fa2016-12-01 01:03:44248With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10249the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00250target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09251
sdy93387fa2016-12-01 01:03:44252To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24253
254```shell
sdy93387fa2016-12-01 01:03:44255$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24256```
andybons3322f762015-08-24 21:37:09257
thakisf28551b2016-08-09 14:42:55258Open it:
tfarina59fb57ac2016-03-02 18:17:24259
260```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00261$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24262```
andybons3322f762015-08-24 21:37:09263
andybonsad92aa32015-08-31 02:27:44264You may run into a problem where http://YES is opened as a new tab every time
265you launch Chrome. To fix this, open the scheme editor for the Run scheme,
266choose the Options tab, and uncheck "Allow debugging when using document
267Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44268`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
269gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09270
andybonsad92aa32015-08-31 02:27:44271If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44272ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17273[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44274tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09275
dpranke0ae7cad2016-11-30 07:47:58276### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37277
ishermance1d9d82017-05-12 23:10:04278#### Increase the vnode cache size
279
shess1f4c3d92015-11-05 18:15:37280`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44281to the large number of files in Chromium's checkout, `git status` performance
282can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37283default, this command:
284
sdy93387fa2016-12-01 01:03:44285```shell
286$ sysctl -a | egrep kern\..*vnodes
287```
shess1f4c3d92015-11-05 18:15:37288
289Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
290setting:
291
sdy93387fa2016-12-01 01:03:44292```shell
293$ sudo sysctl kern.maxvnodes=$((512*1024))
294```
shess1f4c3d92015-11-05 18:15:37295
296Higher values may be appropriate if you routinely move between different
297Chromium checkouts. This setting will reset on reboot, the startup setting can
298be set in `/etc/sysctl.conf`:
299
sdy93387fa2016-12-01 01:03:44300```shell
301$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
302```
shess1f4c3d92015-11-05 18:15:37303
304Or edit the file directly.
305
ishermance1d9d82017-05-12 23:10:04306#### Configure git to use an untracked cache
307
308If `git --version` reports 2.8 or higher, try running
309
310```shell
311$ git update-index --test-untracked-cache
312```
313
314If the output ends with `OK`, then the following may also improve performance of
315`git status`:
316
317```shell
318$ git config core.untrackedCache true
319```
320
321If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
shess1f4c3d92015-11-05 18:15:37322
sdy93387fa2016-12-01 01:03:44323```shell
324$ git update-index --untracked-cache
325```
tnagelcad631692016-04-15 11:02:36326
dpranke0ae7cad2016-11-30 07:47:58327### Xcode license agreement
tnagelcad631692016-04-15 11:02:36328
329If you're getting the error
330
sdy93387fa2016-12-01 01:03:44331> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
332> root via sudo.
tnagelcad631692016-04-15 11:02:36333
334the Xcode license hasn't been accepted yet which (contrary to the message) any
335user can do by running:
336
sdy93387fa2016-12-01 01:03:44337```shell
338$ xcodebuild -license
339```
tnagelcad631692016-04-15 11:02:36340
341Only accepting for all users of the machine requires root:
342
sdy93387fa2016-12-01 01:03:44343```shell
344$ sudo xcodebuild -license
345```