blob: 3a70ff0929b36e1ae36152fa3a1f2701a371fbee [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
15* A 64-bit Mac running 10.11+.
16* [Xcode](https://developer.apple.com/xcode) 8.0+.
17* The OS X 10.10 SDK. Run
18
19 ```shell
20 $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
21 ```
22
23 to check whether you have it. Building with the 10.11 SDK works too, but
24 the releases currently use the 10.10 SDK.
25* The current version of the JDK (required for the Closure compiler).
26
27## Install `depot_tools`
28
29Clone the `depot_tools` repository:
30
31```shell
32$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
33```
34
35Add `depot_tools` to the end of your PATH (you will probably want to put this
36in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
37`/path/to/depot_tools`:
38
39```shell
40$ export PATH="$PATH:/path/to/depot_tools"
41```
42
43## Get the code
44
45Create a `chromium` directory for the checkout and change to it (you can call
46this whatever you like and put it wherever you like, as
47long as the full path has no spaces):
48
49```shell
50$ mkdir chromium && cd chromium
51```
52
53Run the `fetch` tool from `depot_tools` to check out the code and its
54dependencies.
55
56```shell
57$ fetch ios
58```
59
60If you don't want the full repo history, you can save a lot of time by
61adding the `--no-history` flag to `fetch`.
62
63Expect the command to take 30 minutes on even a fast connection, and many
64hours on slower ones.
65
66When `fetch` completes, it will have created a hidden `.gclient` file and a
67directory called `src` in the working directory. The remaining instructions
68assume you have switched to the `src` directory:
69
70```shell
71$ cd src
72```
73
74*Optional*: You can also [install API
75keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
76build to talk to some Google services, but this is not necessary for most
77development and testing purposes.
78
79## Setting up the build
80
81Since the iOS build is a bit more complicated than a desktop build, we provide
82`ios/build/tools/setup-gn.py`, which will create four appropriately configured
83build directories under `out` for Release and Debug device and simulator
ichikawa7c540a12017-05-18 05:50:3284builds, and generates an appropriate Xcode workspace
85(`out/build/all.xcworkspace`) as well.
michaeldo8cccf2142017-03-06 22:12:0286
michaeldo8cccf2142017-03-06 22:12:0287You can customize the build by editing the file `$HOME/.setup-gn` (create it if
88it does not exist). Look at `src/ios/build/tools/setup-gn.config` for
89available configuration options.
90
91From this point, you can either build from Xcode or from the command line using
92`ninja`. `setup-gn.py` creates sub-directories named
93`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
94
95```shell
96$ ninja -C out/Debug-iphonesimulator gn_all
97```
98
99Note: you need to run `setup-gn.py` script every time one of the `BUILD.gn`
100file is updated (either by you or after rebasing). If you forget to run it,
101the list of targets and files in the Xcode solution may be stale.
102
103You can also follow the manual instructions on the
104[Mac page](../mac_build_instructions.md), but make sure you set the
105GN arg `target_os="ios"`.
106
107## Building for device
108
109To be able to build and run Chromium and the tests for devices, you need to
110have an Apple developer account (a free one will work) and the appropriate
111provisioning profiles, then configure the build to use them.
112
113### Code signing identity
114
115Please refer to the Apple documentation on how to get a code signing identity
116and certificates. You can check that you have a code signing identity correctly
117installed by running the following command.
118
119```shell
120$ xcrun security find-identity -v -p codesigning
121 1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: [email protected] (XXXXXXXXXX)"
122 1 valid identities found
123```
124
125If the command output says you have zero valid identities, then you do not
126have a code signing identity installed and need to get one from Apple. If
127you have more than one identity, the build system may select the wrong one
128automatically, and you can use the `ios_code_signing_identity` gn variable
129to control which one to use by setting it to the identity hash, e.g. to
130`"0123456789ABCDEF0123456789ABCDEF01234567"`.
131
132### Mobile provisioning profiles
133
134Once you have the code signing identity, you need to decide on a prefix
135for the application bundle identifier. This is controlled by the gn variable
136`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
137(the default value is `"org.chromium"`).
138
139You then need to request provisioning profiles from Apple for your devices
140for the following bundle identifiers to build and run Chromium with these
141application extensions:
142
143- `${prefix}.chrome.ios.herebedragons`
144- `${prefix}.chrome.ios.herebedragons.ShareExtension`
145- `${prefix}.chrome.ios.herebedragons.TodayExtension`
lodf31fea5a2017-04-19 15:05:59146- `${prefix}.chrome.ios.herebedragons.SearchTodayExtension`
michaeldo8cccf2142017-03-06 22:12:02147
148All these certificates need to have the "App Groups"
149(`com.apple.security.application-groups`) capability enabled for
150the following groups:
151
152- `group.${prefix}.chrome`
153- `group.${prefix}.common`
154
155The `group.${prefix}.chrome` is only shared by Chromium and its extensions
156to share files and configurations while the `group.${prefix}.common` is shared
157with Chromium and other applications from the same organisation and can be used
158to send commands to Chromium.
159
160### Mobile provisioning profiles for tests
161
162In addition to that, you need provisioning profiles for the individual test
163suites that you want to run. Their bundle identifier depends on whether the
164gn variable `ios_automatically_manage_certs` is set to true (the default)
165or false.
166
167If set to true, then you just need a provisioning profile for the bundle
168identifier `${prefix}.gtest.generic-unit-test` but you can only have a
169single test application installed on the device (all the test application
170will share the same bundle identifier).
171
172If set to false, then you need a different provisioning profile for each
173test application. Those provisioning profile will have a bundle identifier
174matching the following pattern `${prefix}.gtest.${test-suite-name}` where
175`${test-suite-name}` is the name of the test suite with underscores changed
176to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests`
177as bundle identifier).
178
179To be able to run the EarlGrey tests on a device, you'll need two provisioning
180profiles for EarlGrey and OCHamcrest frameworks:
181
182- `${prefix}.test.OCHamcrest`
183- `${prefix}.test.EarlGrey`
184
185In addition to that, then you'll need one additional provisioning profile for
186the XCTest module too. This module bundle identifier depends on whether the
187gn variable `ios_automatically_manage_certs` is set to true or false. If set
Sylvain Defresnec63957142017-07-11 12:04:01188to true, then `${prefix}.gtest.generic-unit-test-module` will be used, otherwise
189it will match the pattern: `${prefix}.gtest.${test-suite-name}-module`.
michaeldo8cccf2142017-03-06 22:12:02190
191### Other applications
192
193Other applications like `ios_web_shell` usually will require mobile provisioning
194profiles with bundle identifiers that may usually match the following pattern
195`${prefix}.${application-name}` and may require specific capabilities.
196
197Generally, if the mobile provisioning profile is missing then the code signing
198step will fail and will print the bundle identifier of the bundle that could not
199be signed on the command line, e.g.:
200
201```shell
202$ ninja -C out/Debug-iphoneos ios_web_shell
203ninja: Entering directory `out/Debug-iphoneos'
204FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
205python ../../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
206Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
207ninja: build stopped: subcommand failed.
208```
209
210Here, the build is failing because there are no mobile provisioning profiles
211installed that could sign the `ios_web_shell.app` bundle with the identity
212`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
213request such a mobile provisioning profile from Apple.
214
215You can inspect the file passed via the `-e` flag to the `codesign.py` script
216to check which capabilites are required for the mobile provisioning profile
217(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
218remember that the paths are relative to the build directory, not to the source
219directory).
220
221If the required capabilities are not enabled on the mobile provisioning profile,
222then it will be impossible to install the application on a device (Xcode will
223display an error stating that "The application was signed with invalid
224entitlements").
225
226## Running apps from the commandline
227
228Any target that is built and runs on the bots (see [below](#Troubleshooting))
229should run successfully in a local build. To run in the simulator from the
230command line, you can use `iossim`. For example, to run a debug build of
231`Chromium`:
232
233```shell
234$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
235```
236
237## Update your checkout
238
239To update an existing checkout, you can run
240
241```shell
242$ git rebase-update
243$ gclient sync
244```
245
246The first command updates the primary Chromium source repository and rebases
247any of your local branches on top of tip-of-tree (aka the Git branch
248`origin/master`). If you don't want to use this script, you can also just use
249`git pull` or other common Git commands to update the repo.
250
251The second command syncs dependencies to the appropriate versions and re-runs
252hooks as needed.
253
254## Tips, tricks, and troubleshooting
255
256If you have problems building, join us in `#chromium` on `irc.freenode.net` and
257ask there. As mentioned above, be sure that the
258[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
259is open before checking out. This will increase your chances of success.
260
261### Improving performance of `git status`
262
ishermance1d9d82017-05-12 23:10:04263#### Increase the vnode cache size
264
michaeldo8cccf2142017-03-06 22:12:02265`git status` is used frequently to determine the status of your checkout. Due
266to the large number of files in Chromium's checkout, `git status` performance
267can be quite variable. Increasing the system's vnode cache appears to help.
268By default, this command:
269
270```shell
271$ sysctl -a | egrep kern\..*vnodes
272```
273
274Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
275setting:
276
277```shell
278$ sudo sysctl kern.maxvnodes=$((512*1024))
279```
280
281Higher values may be appropriate if you routinely move between different
282Chromium checkouts. This setting will reset on reboot, the startup setting can
283be set in `/etc/sysctl.conf`:
284
285```shell
286$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
287```
288
289Or edit the file directly.
290
ishermance1d9d82017-05-12 23:10:04291#### Configure git to use an untracked cache
292
293If `git --version` reports 2.8 or higher, try running
294
295```shell
296$ git update-index --test-untracked-cache
297```
298
299If the output ends with `OK`, then the following may also improve performance of
300`git status`:
301
302```shell
303$ git config core.untrackedCache true
304```
305
306If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
michaeldo8cccf2142017-03-06 22:12:02307
308```shell
309$ git update-index --untracked-cache
310```
311
312### Xcode license agreement
313
314If you're getting the error
315
316> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
317> root via sudo.
318
319the Xcode license hasn't been accepted yet which (contrary to the message) any
320user can do by running:
321
322```shell
323$ xcodebuild -license
324```
325
326Only accepting for all users of the machine requires root:
327
328```shell
329$ sudo xcodebuild -license
330```