blob: 26ca10fb30062fcbcf6fafbab9bee0e9fc3d64cf [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.
andybons3322f762015-08-24 21:37:0939
dpranke0ae7cad2016-11-30 07:47:5840## Install `depot_tools`
andybons3322f762015-08-24 21:37:0941
sdy93387fa2016-12-01 01:03:4442Clone the `depot_tools` repository:
andybons3322f762015-08-24 21:37:0943
sdy93387fa2016-12-01 01:03:4444```shell
45$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
46```
andybons3322f762015-08-24 21:37:0947
Gabriel Charetteb6780c12019-04-24 16:23:5248Add `depot_tools` to the end of your PATH (you will probably want to put this in
49your `~/.bash_profile` or `~/.zshrc`). Assuming you cloned `depot_tools` to
50`/path/to/depot_tools` (note: you **must** use the absolute path or Python will
51not be able to find infra tools):
dpranke0ae7cad2016-11-30 07:47:5852
sdy93387fa2016-12-01 01:03:4453```shell
54$ export PATH="$PATH:/path/to/depot_tools"
55```
dpranke0ae7cad2016-11-30 07:47:5856
57## Get the code
58
Aaron Gable94b7e2a32018-01-03 19:14:4159Ensure that unicode filenames aren't mangled by HFS:
60
61```shell
62$ git config --global core.precomposeUnicode true
63```
64
L. David Baron8d606c542021-03-05 19:56:0765In System Preferences, check that "Energy Saver" -> "Power Adapter" ->
66"Prevent computer from sleeping automatically when the display is off" is
67checked so that your laptop doesn't go to sleep and interrupt the long network
68connection needed here.
69
sdy93387fa2016-12-01 01:03:4470Create a `chromium` directory for the checkout and change to it (you can call
71this whatever you like and put it wherever you like, as long as the full path
72has no spaces):
dpranke0ae7cad2016-11-30 07:47:5873
sdy93387fa2016-12-01 01:03:4474```shell
75$ mkdir chromium && cd chromium
76```
77
78Run the `fetch` tool from `depot_tools` to check out the code and its
dpranke0ae7cad2016-11-30 07:47:5879dependencies.
80
sdy93387fa2016-12-01 01:03:4481```shell
82$ fetch chromium
83```
dpranke0ae7cad2016-11-30 07:47:5884
[email protected]1436b952018-10-26 16:35:1385If you don't need the full repo history, you can save time by using
Yannic Bonenbergera68557002019-04-29 14:13:1986`fetch --no-history chromium`. You can call `git fetch --unshallow` to retrieve
87the full history later.
dpranke0ae7cad2016-11-30 07:47:5888
sdy93387fa2016-12-01 01:03:4489Expect the command to take 30 minutes on even a fast connection, and many
90hours on slower ones.
dpranke0ae7cad2016-11-30 07:47:5891
sdy93387fa2016-12-01 01:03:4492When `fetch` completes, it will have created a hidden `.gclient` file and a
93directory called `src` in the working directory. The remaining instructions
94assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5895
sdy93387fa2016-12-01 01:03:4496```shell
97$ cd src
98```
99
100*Optional*: You can also [install API
101keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
102build to talk to some Google services, but this is not necessary for most
103development and testing purposes.
andybons3322f762015-08-24 21:37:09104
dpranke1a70d0c2016-12-01 02:42:29105## Setting up the build
andybons3322f762015-08-24 21:37:09106
Tom Bridgwatereef401542018-08-17 00:54:43107Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
Andrew Williamsbbc1a1e2021-07-21 01:51:22108a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md)
Tom Bridgwatereef401542018-08-17 00:54:43109to generate `.ninja` files. You can create any number of *build directories*
110with different configurations. To create a build directory:
andybonsad92aa32015-08-31 02:27:44111
sdy93387fa2016-12-01 01:03:44112```shell
113$ gn gen out/Default
114```
thakisf28551b2016-08-09 14:42:55115
sdy93387fa2016-12-01 01:03:44116* You only have to run this once for each new build directory, Ninja will
117 update the build files as needed.
118* You can replace `Default` with another name, but
119 it should be a subdirectory of `out`.
120* For other build arguments, including release settings, see [GN build
121 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58122 The default will be a debug component build matching the current host
123 operating system and CPU.
124* For more info on GN, run `gn help` on the command line or read the
Andrew Williamsbbc1a1e2021-07-21 01:51:22125 [quick start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md).
Reilly Grantf057adf2020-11-03 17:42:37126* Building Chromium for arm Macs requires [additional setup](mac_arm64.md).
thakisf28551b2016-08-09 14:42:55127
thakisf28551b2016-08-09 14:42:55128
dpranke0ae7cad2016-11-30 07:47:58129### Faster builds
andybons3322f762015-08-24 21:37:09130
andybonsad92aa32015-08-31 02:27:44131Full rebuilds are about the same speed in Debug and Release, but linking is a
132lot faster in Release builds.
andybons3322f762015-08-24 21:37:09133
thakisf28551b2016-08-09 14:42:55134Put
andybons3322f762015-08-24 21:37:09135
sdy93387fa2016-12-01 01:03:44136```
137is_debug = false
138```
andybons3322f762015-08-24 21:37:09139
sdy93387fa2016-12-01 01:03:44140in your `args.gn` to do a release build.
thakisf28551b2016-08-09 14:42:55141
142Put
143
sdy93387fa2016-12-01 01:03:44144```
145is_component_build = true
146```
thakisf28551b2016-08-09 14:42:55147
sdy93387fa2016-12-01 01:03:44148in your `args.gn` to build many small dylibs instead of a single large
149executable. This makes incremental builds much faster, at the cost of producing
150a binary that opens less quickly. Component builds work in both debug and
151release.
thakisf28551b2016-08-09 14:42:55152
153Put
154
sdy93387fa2016-12-01 01:03:44155```
156symbol_level = 0
157```
thakisf28551b2016-08-09 14:42:55158
159in your args.gn to disable debug symbols altogether. This makes both full
160rebuilds and linking faster (at the cost of not getting symbolized backtraces
161in gdb).
andybons3322f762015-08-24 21:37:09162
Philip Rogerseb841682017-10-09 16:08:50163#### CCache
164
philipj5a0fcb92016-01-23 23:23:40165You might also want to [install ccache](ccache_mac.md) to speed up the build.
andybons3322f762015-08-24 21:37:09166
dpranke1a70d0c2016-12-01 02:42:29167## Build Chromium
168
169Build Chromium (the "chrome" target) with Ninja using the command:
170
171```shell
Max Morozf5b31fcd2018-08-10 21:55:48172$ autoninja -C out/Default chrome
dpranke1a70d0c2016-12-01 02:42:29173```
174
Dirk Pranke8bd55f22018-10-24 21:22:10175(`autoninja` is a wrapper that automatically provides optimal values for the
176arguments passed to `ninja`.)
Max Morozf5b31fcd2018-08-10 21:55:48177
dpranke1a70d0c2016-12-01 02:42:29178You can get a list of all of the other build targets from GN by running `gn ls
179out/Default` from the command line. To compile one, pass the GN label to Ninja
Max Morozf5b31fcd2018-08-10 21:55:48180with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C
dpranke1a70d0c2016-12-01 02:42:29181out/Default chrome/test:unit_tests`).
182
dpranke0ae7cad2016-11-30 07:47:58183## Run Chromium
andybons3322f762015-08-24 21:37:09184
dpranke0ae7cad2016-11-30 07:47:58185Once it is built, you can simply run the browser:
andybons3322f762015-08-24 21:37:09186
sdy93387fa2016-12-01 01:03:44187```shell
Owen Min83eda1102017-06-28 18:47:21188$ out/Default/Chromium.app/Contents/MacOS/Chromium
sdy93387fa2016-12-01 01:03:44189```
andybons3322f762015-08-24 21:37:09190
Dominic Mazzonia7494a52020-08-06 19:19:11191## Avoiding the "incoming network connections" dialog
192
193Every time you start a new developer build of Chrome you get a system dialog
194asking "Do you want the application Chromium.app to accept incoming
195network connections?" - to avoid this, run with this command-line flag:
196
mark a. foltza25bb8c2021-11-10 20:38:48197--disable-features="DialMediaRouteProvider"
Dominic Mazzonia7494a52020-08-06 19:19:11198
wafuwafu13b6854ba52021-12-24 06:02:43199## Build and run test targets
andybons3322f762015-08-24 21:37:09200
wafuwafu13b6854ba52021-12-24 06:02:43201You can build a test in the same way, e.g.:
202
203```shell
204$ autoninja -C out/Default unit_tests
205```
206
207and can run the tests in the same way. You can also limit which tests are
dpranke0ae7cad2016-11-30 07:47:58208run using the `--gtest_filter` arg, e.g.:
andybons3322f762015-08-24 21:37:09209
sdy93387fa2016-12-01 01:03:44210```
dpranke1a70d0c2016-12-01 02:42:29211$ out/Default/unit_tests --gtest_filter="PushClientTest.*"
sdy93387fa2016-12-01 01:03:44212```
andybons3322f762015-08-24 21:37:09213
dpranke0ae7cad2016-11-30 07:47:58214You can find out more about GoogleTest at its
215[GitHub page](https://github.com/google/googletest).
andybons3322f762015-08-24 21:37:09216
andybonsad92aa32015-08-31 02:27:44217## Debugging
andybons3322f762015-08-24 21:37:09218
Robert Sesek3b731b12021-04-14 21:54:03219Good debugging tips can be found [here](mac/debugging.md).
Vaclav Brozek539499e2018-07-18 11:19:51220
dpranke0ae7cad2016-11-30 07:47:58221## Update your checkout
andybonsad92aa32015-08-31 02:27:44222
dpranke0ae7cad2016-11-30 07:47:58223To update an existing checkout, you can run
andybonsad92aa32015-08-31 02:27:44224
sdy93387fa2016-12-01 01:03:44225```shell
226$ git rebase-update
227$ gclient sync
228```
dpranke0ae7cad2016-11-30 07:47:58229
230The first command updates the primary Chromium source repository and rebases
sdy93387fa2016-12-01 01:03:44231any of your local branches on top of tip-of-tree (aka the Git branch
Andrew Williamsbbc1a1e2021-07-21 01:51:22232`origin/main`). If you don't want to use this script, you can also just use
sdy93387fa2016-12-01 01:03:44233`git pull` or other common Git commands to update the repo.
dpranke0ae7cad2016-11-30 07:47:58234
sdy93387fa2016-12-01 01:03:44235The second command syncs dependencies to the appropriate versions and re-runs
236hooks as needed.
dpranke0ae7cad2016-11-30 07:47:58237
238## Tips, tricks, and troubleshooting
239
240### Using Xcode-Ninja Hybrid
andybonsad92aa32015-08-31 02:27:44241
sdy93387fa2016-12-01 01:03:44242While using Xcode is unsupported, GN supports a hybrid approach of using Ninja
thakisf28551b2016-08-09 14:42:55243for building, but Xcode for editing and driving compilation. Xcode is still
244slow, but it runs fairly well even **with indexing enabled**. Most people
sdy93387fa2016-12-01 01:03:44245build in the Terminal and write code with a text editor, though.
andybonsad92aa32015-08-31 02:27:44246
sdy93387fa2016-12-01 01:03:44247With hybrid builds, compilation is still handled by Ninja, and can be run from
Dirk Pranke8bd55f22018-10-24 21:22:10248the command line (e.g. `autoninja -C out/gn chrome`) or by choosing the `chrome`
Sylvain Defresnefc11bcd2020-06-26 13:42:00249target in the hybrid project and choosing Build.
andybons3322f762015-08-24 21:37:09250
sdy93387fa2016-12-01 01:03:44251To use Xcode-Ninja Hybrid pass `--ide=xcode` to `gn gen`:
tfarina59fb57ac2016-03-02 18:17:24252
253```shell
sdy93387fa2016-12-01 01:03:44254$ gn gen out/gn --ide=xcode
tfarina59fb57ac2016-03-02 18:17:24255```
andybons3322f762015-08-24 21:37:09256
thakisf28551b2016-08-09 14:42:55257Open it:
tfarina59fb57ac2016-03-02 18:17:24258
259```shell
Sylvain Defresnefc11bcd2020-06-26 13:42:00260$ open out/gn/all.xcodeproj
tfarina59fb57ac2016-03-02 18:17:24261```
andybons3322f762015-08-24 21:37:09262
andybonsad92aa32015-08-31 02:27:44263You may run into a problem where http://YES is opened as a new tab every time
264you launch Chrome. To fix this, open the scheme editor for the Run scheme,
265choose the Options tab, and uncheck "Allow debugging when using document
266Versions Browser". When this option is checked, Xcode adds
sdy93387fa2016-12-01 01:03:44267`--NSDocumentRevisionsDebugMode YES` to the launch arguments, and the `YES`
268gets interpreted as a URL to open.
andybons3322f762015-08-24 21:37:09269
andybonsad92aa32015-08-31 02:27:44270If you have problems building, join us in `#chromium` on `irc.freenode.net` and
sdy93387fa2016-12-01 01:03:44271ask there. Be sure that the
xiaoyin.l1003c0b2016-12-06 02:51:17272[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the
sdy93387fa2016-12-01 01:03:44273tree is open before checking out. This will increase your chances of success.
andybons3322f762015-08-24 21:37:09274
dpranke0ae7cad2016-11-30 07:47:58275### Improving performance of `git status`
shess1f4c3d92015-11-05 18:15:37276
ishermance1d9d82017-05-12 23:10:04277#### Increase the vnode cache size
278
shess1f4c3d92015-11-05 18:15:37279`git status` is used frequently to determine the status of your checkout. Due
sdy93387fa2016-12-01 01:03:44280to the large number of files in Chromium's checkout, `git status` performance
281can be quite variable. Increasing the system's vnode cache appears to help. By
shess1f4c3d92015-11-05 18:15:37282default, this command:
283
sdy93387fa2016-12-01 01:03:44284```shell
285$ sysctl -a | egrep kern\..*vnodes
286```
shess1f4c3d92015-11-05 18:15:37287
288Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
289setting:
290
sdy93387fa2016-12-01 01:03:44291```shell
292$ sudo sysctl kern.maxvnodes=$((512*1024))
293```
shess1f4c3d92015-11-05 18:15:37294
295Higher values may be appropriate if you routinely move between different
296Chromium checkouts. This setting will reset on reboot, the startup setting can
297be set in `/etc/sysctl.conf`:
298
sdy93387fa2016-12-01 01:03:44299```shell
300$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
301```
shess1f4c3d92015-11-05 18:15:37302
303Or edit the file directly.
304
ishermance1d9d82017-05-12 23:10:04305#### Configure git to use an untracked cache
306
307If `git --version` reports 2.8 or higher, try running
308
309```shell
310$ git update-index --test-untracked-cache
311```
312
313If the output ends with `OK`, then the following may also improve performance of
314`git status`:
315
316```shell
317$ git config core.untrackedCache true
318```
319
320If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
shess1f4c3d92015-11-05 18:15:37321
sdy93387fa2016-12-01 01:03:44322```shell
323$ git update-index --untracked-cache
324```
tnagelcad631692016-04-15 11:02:36325
dpranke0ae7cad2016-11-30 07:47:58326### Xcode license agreement
tnagelcad631692016-04-15 11:02:36327
328If you're getting the error
329
sdy93387fa2016-12-01 01:03:44330> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
331> root via sudo.
tnagelcad631692016-04-15 11:02:36332
333the Xcode license hasn't been accepted yet which (contrary to the message) any
334user can do by running:
335
sdy93387fa2016-12-01 01:03:44336```shell
337$ xcodebuild -license
338```
tnagelcad631692016-04-15 11:02:36339
340Only accepting for all users of the machine requires root:
341
sdy93387fa2016-12-01 01:03:44342```shell
343$ sudo xcodebuild -license
344```