blob: 547a6b5eb0f3c32fd3af1a97cebe90dc0194a460 [file] [log] [blame] [view]
michaeldo8cccf2142017-03-06 22:12:021# Checking out and building Chromium for iOS
2
3There are instructions for other platforms linked from the
4[get the code](../get_the_code.md) page.
5
6## Instructions for Google Employees
7
8Are you a Google employee? See
9[go/building-chrome](https://goto.google.com/building-chrome) instead.
10
11[TOC]
12
13## System requirements
14
Mike Pinkerton90553fe2017-12-13 16:40:3015* A 64-bit Mac running 10.12.6 or later.
Justin Cohen6a42e082018-08-30 03:39:1416* [Xcode](https://developer.apple.com/xcode) 10.0+.
michaeldo8cccf2142017-03-06 22:12:0217* The current version of the JDK (required for the Closure compiler).
18
19## Install `depot_tools`
20
21Clone the `depot_tools` repository:
22
23```shell
24$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
25```
26
27Add `depot_tools` to the end of your PATH (you will probably want to put this
28in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
29`/path/to/depot_tools`:
30
31```shell
32$ export PATH="$PATH:/path/to/depot_tools"
33```
34
35## Get the code
36
37Create a `chromium` directory for the checkout and change to it (you can call
38this whatever you like and put it wherever you like, as
39long as the full path has no spaces):
40
41```shell
42$ mkdir chromium && cd chromium
43```
44
45Run the `fetch` tool from `depot_tools` to check out the code and its
46dependencies.
47
48```shell
49$ fetch ios
50```
51
52If you don't want the full repo history, you can save a lot of time by
53adding the `--no-history` flag to `fetch`.
54
55Expect the command to take 30 minutes on even a fast connection, and many
56hours on slower ones.
57
58When `fetch` completes, it will have created a hidden `.gclient` file and a
59directory called `src` in the working directory. The remaining instructions
60assume you have switched to the `src` directory:
61
62```shell
63$ cd src
64```
65
66*Optional*: You can also [install API
67keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
68build to talk to some Google services, but this is not necessary for most
69development and testing purposes.
70
71## Setting up the build
72
73Since the iOS build is a bit more complicated than a desktop build, we provide
74`ios/build/tools/setup-gn.py`, which will create four appropriately configured
75build directories under `out` for Release and Debug device and simulator
ichikawa7c540a12017-05-18 05:50:3276builds, and generates an appropriate Xcode workspace
77(`out/build/all.xcworkspace`) as well.
michaeldo8cccf2142017-03-06 22:12:0278
michaeldo8cccf2142017-03-06 22:12:0279You can customize the build by editing the file `$HOME/.setup-gn` (create it if
80it does not exist). Look at `src/ios/build/tools/setup-gn.config` for
81available configuration options.
82
83From this point, you can either build from Xcode or from the command line using
Dirk Pranke8bd55f22018-10-24 21:22:1084`autoninja`. `setup-gn.py` creates sub-directories named
michaeldo8cccf2142017-03-06 22:12:0285`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
86
87```shell
Dirk Pranke8bd55f22018-10-24 21:22:1088$ autoninja -C out/Debug-iphonesimulator gn_all
michaeldo8cccf2142017-03-06 22:12:0289```
90
Dirk Pranke8bd55f22018-10-24 21:22:1091(`autoninja` is a wrapper that automatically provides optimal values for the
92arguments passed to `ninja`.)
93
michaeldo8cccf2142017-03-06 22:12:0294Note: you need to run `setup-gn.py` script every time one of the `BUILD.gn`
95file is updated (either by you or after rebasing). If you forget to run it,
96the list of targets and files in the Xcode solution may be stale.
97
98You can also follow the manual instructions on the
99[Mac page](../mac_build_instructions.md), but make sure you set the
100GN arg `target_os="ios"`.
101
102## Building for device
103
104To be able to build and run Chromium and the tests for devices, you need to
105have an Apple developer account (a free one will work) and the appropriate
106provisioning profiles, then configure the build to use them.
107
108### Code signing identity
109
110Please refer to the Apple documentation on how to get a code signing identity
111and certificates. You can check that you have a code signing identity correctly
112installed by running the following command.
113
114```shell
115$ xcrun security find-identity -v -p codesigning
116 1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: [email protected] (XXXXXXXXXX)"
117 1 valid identities found
118```
119
120If the command output says you have zero valid identities, then you do not
121have a code signing identity installed and need to get one from Apple. If
122you have more than one identity, the build system may select the wrong one
123automatically, and you can use the `ios_code_signing_identity` gn variable
124to control which one to use by setting it to the identity hash, e.g. to
125`"0123456789ABCDEF0123456789ABCDEF01234567"`.
126
127### Mobile provisioning profiles
128
129Once you have the code signing identity, you need to decide on a prefix
130for the application bundle identifier. This is controlled by the gn variable
131`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
132(the default value is `"org.chromium"`).
133
134You then need to request provisioning profiles from Apple for your devices
135for the following bundle identifiers to build and run Chromium with these
136application extensions:
137
138- `${prefix}.chrome.ios.herebedragons`
139- `${prefix}.chrome.ios.herebedragons.ShareExtension`
140- `${prefix}.chrome.ios.herebedragons.TodayExtension`
lodf31fea5a2017-04-19 15:05:59141- `${prefix}.chrome.ios.herebedragons.SearchTodayExtension`
michaeldo8cccf2142017-03-06 22:12:02142
143All these certificates need to have the "App Groups"
144(`com.apple.security.application-groups`) capability enabled for
145the following groups:
146
147- `group.${prefix}.chrome`
148- `group.${prefix}.common`
149
150The `group.${prefix}.chrome` is only shared by Chromium and its extensions
151to share files and configurations while the `group.${prefix}.common` is shared
152with Chromium and other applications from the same organisation and can be used
153to send commands to Chromium.
154
155### Mobile provisioning profiles for tests
156
157In addition to that, you need provisioning profiles for the individual test
158suites that you want to run. Their bundle identifier depends on whether the
159gn variable `ios_automatically_manage_certs` is set to true (the default)
160or false.
161
162If set to true, then you just need a provisioning profile for the bundle
163identifier `${prefix}.gtest.generic-unit-test` but you can only have a
164single test application installed on the device (all the test application
165will share the same bundle identifier).
166
167If set to false, then you need a different provisioning profile for each
168test application. Those provisioning profile will have a bundle identifier
169matching the following pattern `${prefix}.gtest.${test-suite-name}` where
170`${test-suite-name}` is the name of the test suite with underscores changed
171to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests`
172as bundle identifier).
173
174To be able to run the EarlGrey tests on a device, you'll need two provisioning
175profiles for EarlGrey and OCHamcrest frameworks:
176
177- `${prefix}.test.OCHamcrest`
178- `${prefix}.test.EarlGrey`
179
180In addition to that, then you'll need one additional provisioning profile for
181the XCTest module too. This module bundle identifier depends on whether the
182gn variable `ios_automatically_manage_certs` is set to true or false. If set
Sylvain Defresnec63957142017-07-11 12:04:01183to true, then `${prefix}.gtest.generic-unit-test-module` will be used, otherwise
184it will match the pattern: `${prefix}.gtest.${test-suite-name}-module`.
michaeldo8cccf2142017-03-06 22:12:02185
186### Other applications
187
188Other applications like `ios_web_shell` usually will require mobile provisioning
189profiles with bundle identifiers that may usually match the following pattern
190`${prefix}.${application-name}` and may require specific capabilities.
191
192Generally, if the mobile provisioning profile is missing then the code signing
193step will fail and will print the bundle identifier of the bundle that could not
194be signed on the command line, e.g.:
195
196```shell
Dirk Pranke8bd55f22018-10-24 21:22:10197$ autoninja -C out/Debug-iphoneos ios_web_shell
michaeldo8cccf2142017-03-06 22:12:02198ninja: Entering directory `out/Debug-iphoneos'
199FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
200python ../../build/config/ios/codesign.py code-sign-bundle -t=iphoneos -i=0123456789ABCDEF0123456789ABCDEF01234567 -e=../../build/config/ios/entitlements.plist -b=obj/ios/web/shell/ios_web_shell ios_web_shell.app
201Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
202ninja: build stopped: subcommand failed.
203```
204
205Here, the build is failing because there are no mobile provisioning profiles
206installed that could sign the `ios_web_shell.app` bundle with the identity
207`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
208request such a mobile provisioning profile from Apple.
209
210You can inspect the file passed via the `-e` flag to the `codesign.py` script
211to check which capabilites are required for the mobile provisioning profile
212(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
213remember that the paths are relative to the build directory, not to the source
214directory).
215
216If the required capabilities are not enabled on the mobile provisioning profile,
217then it will be impossible to install the application on a device (Xcode will
218display an error stating that "The application was signed with invalid
219entitlements").
220
221## Running apps from the commandline
222
223Any target that is built and runs on the bots (see [below](#Troubleshooting))
224should run successfully in a local build. To run in the simulator from the
225command line, you can use `iossim`. For example, to run a debug build of
226`Chromium`:
227
228```shell
229$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
230```
231
Mike Pinkerton90553fe2017-12-13 16:40:30232With Xcode 9, `iossim` no longer automatically launches the Simulator. This must now
233be done manually from within Xcode (`Xcode > Open Developer Tool > Simulator`), and
234also must be done *after* running `iossim`.
235
Vaclav Brozek09fe5ec2017-07-18 11:13:16236### Passing arguments
237
238Arguments needed to be passed to the test application through `iossim`, such as
239`--gtest_filter=SomeTest.FooBar` should be passed through the `-c` flag:
240
241```shell
Sylvain Defresned019a702018-02-01 10:11:51242$ out/Debug-iphonesimulator/iossim \
Vaclav Brozek09fe5ec2017-07-18 11:13:16243 -c "--gtest_filter=SomeTest.FooBar --gtest_repeat=3" \
244 out/Debug-iphonesimulator/base_unittests.app
245```
246
Mike Baxleycb99a9f2017-07-12 15:16:11247### Running EarlGrey tests
248
249EarlGrey tests are run differently than other test targets, as there is an
250XCTest bundle that is injected into the target application. Therefore you must
251also pass in the test bundle:
252
253```shell
254$ out/Debug-iphonesimulator/iossim \
255 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app \
256 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app/PlugIns/ios_chrome_ui_egtests_module.xctest
257```
258
Sylvain Defresned019a702018-02-01 10:11:51259### Running on specific simulator
260
261By default, `iossim` will pick an arbitrary simulator to run the tests. If
262you want to run them on a specific simulator, you can use `-d` to pick the
263simulated device and `-s` to select the iOS version.
264
265For example, to run the tests on a simulated iPhone 6s running iOS 10.0,
266you would invoke `iossim` like this.
267
268```shell
269$ out/Debug-iphonesimulator/iossim -d 'iPhone 6s' -s '10.0' \
270 out/Debug-iphonesimulator/base_unittests.app
271```
272
273Please note that by default only a subset of simulator devices are installed
274with Xcode. You may have to install additional simulators in Xcode (or even
275an older version of Xcode) to be able to run on a specific configuration.
276
277Go to "Preferences > Components" tab in Xcode to install other simulator images
278(this is the location the setting is in Xcode 9.2; it may be different in other
279version of the tool).
280
michaeldo8cccf2142017-03-06 22:12:02281## Update your checkout
282
283To update an existing checkout, you can run
284
285```shell
286$ git rebase-update
287$ gclient sync
288```
289
290The first command updates the primary Chromium source repository and rebases
291any of your local branches on top of tip-of-tree (aka the Git branch
292`origin/master`). If you don't want to use this script, you can also just use
293`git pull` or other common Git commands to update the repo.
294
295The second command syncs dependencies to the appropriate versions and re-runs
296hooks as needed.
297
298## Tips, tricks, and troubleshooting
299
300If you have problems building, join us in `#chromium` on `irc.freenode.net` and
301ask there. As mentioned above, be sure that the
302[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
303is open before checking out. This will increase your chances of success.
304
305### Improving performance of `git status`
306
ishermance1d9d82017-05-12 23:10:04307#### Increase the vnode cache size
308
michaeldo8cccf2142017-03-06 22:12:02309`git status` is used frequently to determine the status of your checkout. Due
310to the large number of files in Chromium's checkout, `git status` performance
311can be quite variable. Increasing the system's vnode cache appears to help.
312By default, this command:
313
314```shell
315$ sysctl -a | egrep kern\..*vnodes
316```
317
318Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
319setting:
320
321```shell
322$ sudo sysctl kern.maxvnodes=$((512*1024))
323```
324
325Higher values may be appropriate if you routinely move between different
326Chromium checkouts. This setting will reset on reboot, the startup setting can
327be set in `/etc/sysctl.conf`:
328
329```shell
330$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
331```
332
333Or edit the file directly.
334
ishermance1d9d82017-05-12 23:10:04335#### Configure git to use an untracked cache
336
337If `git --version` reports 2.8 or higher, try running
338
339```shell
340$ git update-index --test-untracked-cache
341```
342
343If the output ends with `OK`, then the following may also improve performance of
344`git status`:
345
346```shell
347$ git config core.untrackedCache true
348```
349
350If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
michaeldo8cccf2142017-03-06 22:12:02351
352```shell
353$ git update-index --untracked-cache
354```
355
356### Xcode license agreement
357
358If you're getting the error
359
360> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
361> root via sudo.
362
363the Xcode license hasn't been accepted yet which (contrary to the message) any
364user can do by running:
365
366```shell
367$ xcodebuild -license
368```
369
370Only accepting for all users of the machine requires root:
371
372```shell
373$ sudo xcodebuild -license
374```