ios_build_instructions.md 11.2 KB
Newer Older
1 2
# Checking out and building Chromium for iOS

3
There are instructions for other platforms linked from the
4
[get the code](get_the_code.md) page.
5

6 7 8 9
## Instructions for Google Employees

Are you a Google employee? See
[go/building-chrome](https://goto.google.com/building-chrome) instead.
10

11
[TOC]
12

13
## System requirements
14

15 16
* A 64-bit Mac running 10.11+.
* [Xcode](https://developer.apple.com/xcode) 8.0+.
17 18
* The OS X 10.10 SDK. Run

19
    ```shell
20 21
    $ ls `xcode-select -p`/Platforms/MacOSX.platform/Developer/SDKs
    ```
22

23 24
  to check whether you have it.  Building with the 10.11 SDK works too, but
  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

29
Clone the `depot_tools` repository:
30

31 32 33
```shell
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
```
34

35 36 37
Add `depot_tools` to the end of your PATH (you will probably want to put this
in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
`/path/to/depot_tools`:
38

39 40 41
```shell
$ export PATH="$PATH:/path/to/depot_tools"
```
42

43
## Get the code
44

45
Create a `chromium` directory for the checkout and change to it (you can call
46 47 48
this whatever you like and put it wherever you like, as
long as the full path has no spaces):

49 50 51
```shell
$ mkdir chromium && cd chromium
```
52

53 54
Run the `fetch` tool from `depot_tools` to check out the code and its
dependencies.
55

56 57 58
```shell
$ fetch ios
```
59 60

If you don't want the full repo history, you can save a lot of time by
61 62 63 64
adding the `--no-history` flag to `fetch`.

Expect the command to take 30 minutes on even a fast connection, and many
hours on slower ones.
65

66 67 68
When `fetch` completes, it will have created a hidden `.gclient` file and a
directory called `src` in the working directory. The remaining instructions
assume you have switched to the `src` directory:
69

70 71 72
```shell
$ cd src
```
73

74 75 76 77
*Optional*: You can also [install API
keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
build to talk to some Google services, but this is not necessary for most
development and testing purposes.
78 79 80

## Setting up the build

81 82 83
Since the iOS build is a bit more complicated than a desktop build, we provide
`ios/build/tools/setup-gn.py`, which will create four appropriately configured
build directories under `out` for Release and Debug device and simulator
84
builds, and generates an appropriate Xcode workspace as well.
85 86

This script is run automatically by fetch (as part of `gclient runhooks`).
87

88 89
You can customize the build by editing the file `$HOME/.setup-gn` (create it if
it does not exist).  Look at `src/ios/build/tools/setup-gn.config` for
90
available configuration options.
91

92 93 94
From this point, you can either build from Xcode or from the command line using
`ninja`. `setup-gn.py` creates sub-directories named
`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
95

96
```shell
97
$ ninja -C out/Debug-iphonesimulator gn_all
98
```
99

100 101 102
Note: you need to run `setup-gn.py` script every time one of the `BUILD.gn`
file is updated (either by you or after rebasing). If you forget to run it,
the list of targets and files in the Xcode solution may be stale.
103

104
You can also follow the manual instructions on the
105
[Mac page](mac_build_instructions.md), but make sure you set the
106
GN arg `target_os="ios"`.
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
## Building for device

To be able to build and run Chromium and the tests for devices, you need to
have an Apple developer account (a free one will work) and the appropriate
provisioning profiles, then configure the build to use them.

### Code signing identity

Please refer to the Apple documentation on how to get a code signing identity
and certificates. You can check that you have a code signing identity correctly
installed by running the following command.

```shell
$ xcrun security find-identity -v -p codesigning
  1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: someone@example.com (XXXXXXXXXX)"
     1 valid identities found
```

If the command output says you have zero valid identities, then you do not
have a code signing identity installed and need to get one from Apple. If
you have more than one identity, the build system may select the wrong one
automatically, and you can use the `ios_code_signing_identity` gn variable
to control which one to use by setting it to the identity hash, e.g. to
`"0123456789ABCDEF0123456789ABCDEF01234567"`.

### Mobile provisioning profiles

Once you have the code signing identity, you need to decide on a prefix
for the application bundle identifier. This is controlled by the gn variable
`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
(the default value is `"org.chromium"`).

You then need to request provisioning profiles from Apple for your devices
for the following bundle identifiers to build and run Chromium with these
application extensions:

-   `${prefix}.chrome.ios.herebedragons`
-   `${prefix}.chrome.ios.herebedragons.ShareExtension`
-   `${prefix}.chrome.ios.herebedragons.TodayExtension`

All these certificates need to have the "App Groups"
(`com.apple.security.application-groups`) capability enabled for
the following groups:

-   `group.${prefix}.chrome`
-   `group.${prefix}.common`

The `group.${prefix}.chrome` is only shared by Chromium and its extensions
to share files and configurations while the `group.${prefix}.common` is shared
with Chromium and other applications from the same organisation and can be used
to send commands to Chromium.

### Mobile provisioning profiles for tests

In addition to that, you need provisioning profiles for the individual test
suites that you want to run. Their bundle identifier depends on whether the
gn variable `ios_automatically_manage_certs` is set to true (the default)
or false.

If set to true, then you just need a provisioning profile for the bundle
identifier `${prefix}.gtest.generic-unit-test` but you can only have a
single test application installed on the device (all the test application
will share the same bundle identifier).

If set to false, then you need a different provisioning profile for each
test application. Those provisioning profile will have a bundle identifier
matching the following pattern `${prefix}.gtest.${test-suite-name}` where
`${test-suite-name}` is the name of the test suite with underscores changed
to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests`
as bundle identifier).

To be able to run the EarlGrey tests on a device, you'll need two provisioning
profiles for EarlGrey and OCHamcrest frameworks:

-   `${prefix}.test.OCHamcrest`
-   `${prefix}.test.EarlGrey`

In addition to that, then you'll need one additional provisioning profile for
the XCTest module too. This module bundle identifier depends on whether the
gn variable `ios_automatically_manage_certs` is set to true or false. If set
to true, then `${prefix}.test.gtest.generic-unit-test.generic-unit-test-module`
will be used, otherwise it will match the following pattern:
`${prefix}.test.${test-suite-name}.${test-suite-name}-module`.

### Other applications

Other applications like `ios_web_shell` usually will require mobile provisioning
profiles with bundle identifiers that may usually match the following pattern
`${prefix}.${application-name}` and may require specific capabilities.

Generally, if the mobile provisioning profile is missing then the code signing
step will fail and will print the bundle identifier of the bundle that could not
be signed on the command line, e.g.:

```shell
$ ninja -C out/Debug-iphoneos ios_web_shell
ninja: Entering directory `out/Debug-iphoneos'
FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
python ../../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
Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
ninja: build stopped: subcommand failed.
```

Here, the build is failing because there are no mobile provisioning profiles
installed that could sign the `ios_web_shell.app` bundle with the identity
`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
request such a mobile provisioning profile from Apple.

You can inspect the file passed via the `-e` flag to the `codesign.py` script
to check which capabilites are required for the mobile provisioning profile
(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
remember that the paths are relative to the build directory, not to the source
directory).

If the required capabilities are not enabled on the mobile provisioning profile,
then it will be impossible to install the application on a device (Xcode will
display an error stating that "The application was signed with invalid
entitlements").

227
## Running apps from the commandline
228

229
Any target that is built and runs on the bots (see [below](#Troubleshooting))
230 231 232
should run successfully in a local build. To run in the simulator from the
command line, you can use `iossim`. For example, to run a debug build of
`Chromium`:
233

234
```shell
235
$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
236
```
237

238 239 240 241
## Update your checkout

To update an existing checkout, you can run

242 243 244 245
```shell
$ git rebase-update
$ gclient sync
```
246 247

The first command updates the primary Chromium source repository and rebases
248 249 250
any of your local branches on top of tip-of-tree (aka the Git branch
`origin/master`). If you don't want to use this script, you can also just use
`git pull` or other common Git commands to update the repo.
251

252 253
The second command syncs dependencies to the appropriate versions and re-runs
hooks as needed.
254 255 256 257 258

## Tips, tricks, and troubleshooting

If you have problems building, join us in `#chromium` on `irc.freenode.net` and
ask there. As mentioned above, be sure that the
259
[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
260 261 262 263 264
is open before checking out. This will increase your chances of success.

### Improving performance of `git status`

`git status` is used frequently to determine the status of your checkout.  Due
265 266 267
to the large number of files in Chromium's checkout, `git status` performance
can be quite variable.  Increasing the system's vnode cache appears to help.
By default, this command:
268

269 270 271
```shell
$ sysctl -a | egrep kern\..*vnodes
```
272 273 274 275

Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024).  To increase this
setting:

276 277 278
```shell
$ sudo sysctl kern.maxvnodes=$((512*1024))
```
279 280 281 282 283

Higher values may be appropriate if you routinely move between different
Chromium checkouts.  This setting will reset on reboot, the startup setting can
be set in `/etc/sysctl.conf`:

284 285 286
```shell
$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
```
287 288 289

Or edit the file directly.

290
If `git --version` reports 2.6 or higher, the following may also improve
291 292
performance of `git status`:

293 294 295
```shell
$ git update-index --untracked-cache
```
296 297 298 299 300

### Xcode license agreement

If you're getting the error

301 302
> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
> root via sudo.
303 304 305 306

the Xcode license hasn't been accepted yet which (contrary to the message) any
user can do by running:

307 308 309
```shell
$ xcodebuild -license
```
310

311
Only accepting for all users of the machine requires root:
312

313 314 315
```shell
$ sudo xcodebuild -license
```