blob: ab1815cd125f59e8f6f476c293e7fd4bcce02385 [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
Sylvain Defresne92455aa2021-09-29 15:01:3615* A 64-bit Mac running 11.3 or later.
16* [Xcode](https://developer.apple.com/xcode) 13.0 or higher.
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
Sylvain Defresnefc11bcd2020-06-26 13:42:0076builds, and generates an appropriate Xcode project (`out/build/all.xcodeproj`)
77as well.
michaeldo8cccf2142017-03-06 22:12:0278
Sylvain Defresnefc11bcd2020-06-26 13:42:0079More information about [developing with Xcode](xcode_tips.md). *Xcode project
80is an artifact, any changes made in the project itself will be ignored.*
Mike Doughertyd8947a592020-05-07 19:43:4681
michaeldo8cccf2142017-03-06 22:12:0282You can customize the build by editing the file `$HOME/.setup-gn` (create it if
83it does not exist). Look at `src/ios/build/tools/setup-gn.config` for
84available configuration options.
85
86From this point, you can either build from Xcode or from the command line using
Dirk Pranke8bd55f22018-10-24 21:22:1087`autoninja`. `setup-gn.py` creates sub-directories named
michaeldo8cccf2142017-03-06 22:12:0288`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
89
90```shell
Dirk Pranke8bd55f22018-10-24 21:22:1091$ autoninja -C out/Debug-iphonesimulator gn_all
michaeldo8cccf2142017-03-06 22:12:0292```
93
Dirk Pranke8bd55f22018-10-24 21:22:1094(`autoninja` is a wrapper that automatically provides optimal values for the
95arguments passed to `ninja`.)
96
Mike Doughertyd8947a592020-05-07 19:43:4697Note: The `setup-gn.py` script needs to run every time one of the `BUILD.gn`
98files is updated (either by you or after rebasing). If you forget to run it,
99the list of targets and files in the Xcode solution may be stale. You can run
100the script directly or use either `gclient sync` or `gclient runhooks` which
101will run `setup-gn.py` for you as part of the update hooks.
michaeldo8cccf2142017-03-06 22:12:02102
Sylvain Defresne9932328e2020-07-09 10:44:40103You can add a custom hook to `.gclient` file to configure `setup-gn.py` to
104be run as part of `gclient runhooks`. In that case, your `.gclient` file
105would look like this:
106
107```
108solutions = [
109 {
110 "name" : "src",
111 "url" : "https://chromium.googlesource.com/chromium/src.git",
112 "deps_file" : "DEPS",
113 "managed" : False,
114 "custom_deps" : {},
115 "custom_vars" : {},
116 "custom_hooks": [{
117 "name": "setup_gn",
118 "pattern": ".",
119 "action": [
120 "python",
121 "src/ios/build/tools/setup-gn.py",
122 ]
123 }],
124 "safesync_url": "",
125 },
126]
127target_os = ["ios"]
128target_os_only = True
129```
130
michaeldo8cccf2142017-03-06 22:12:02131You can also follow the manual instructions on the
132[Mac page](../mac_build_instructions.md), but make sure you set the
133GN arg `target_os="ios"`.
134
135## Building for device
136
137To be able to build and run Chromium and the tests for devices, you need to
138have an Apple developer account (a free one will work) and the appropriate
139provisioning profiles, then configure the build to use them.
140
141### Code signing identity
142
143Please refer to the Apple documentation on how to get a code signing identity
144and certificates. You can check that you have a code signing identity correctly
145installed by running the following command.
146
147```shell
148$ xcrun security find-identity -v -p codesigning
149 1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: [email protected] (XXXXXXXXXX)"
150 1 valid identities found
151```
152
153If the command output says you have zero valid identities, then you do not
154have a code signing identity installed and need to get one from Apple. If
155you have more than one identity, the build system may select the wrong one
156automatically, and you can use the `ios_code_signing_identity` gn variable
157to control which one to use by setting it to the identity hash, e.g. to
158`"0123456789ABCDEF0123456789ABCDEF01234567"`.
159
160### Mobile provisioning profiles
161
162Once you have the code signing identity, you need to decide on a prefix
163for the application bundle identifier. This is controlled by the gn variable
164`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
165(the default value is `"org.chromium"`).
166
167You then need to request provisioning profiles from Apple for your devices
168for the following bundle identifiers to build and run Chromium with these
169application extensions:
170
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34171- `${prefix}.chrome.ios.dev`
172- `${prefix}.chrome.ios.dev.ContentTodayExtension`
173- `${prefix}.chrome.ios.dev.CredentialProviderExtension`
Sylvain Defresnec2117082021-10-29 10:05:48174- `${prefix}.chrome.ios.dev.IntentsExtension`
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34175- `${prefix}.chrome.ios.dev.SearchTodayExtension`
176- `${prefix}.chrome.ios.dev.ShareExtension`
177- `${prefix}.chrome.ios.dev.TodayExtension`
178- `${prefix}.chrome.ios.dev.WidgetKitExtension`
michaeldo8cccf2142017-03-06 22:12:02179
180All these certificates need to have the "App Groups"
181(`com.apple.security.application-groups`) capability enabled for
182the following groups:
183
184- `group.${prefix}.chrome`
185- `group.${prefix}.common`
186
187The `group.${prefix}.chrome` is only shared by Chromium and its extensions
188to share files and configurations while the `group.${prefix}.common` is shared
189with Chromium and other applications from the same organisation and can be used
190to send commands to Chromium.
191
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34192`${prefix}.chrome.ios.dev.CredentialProviderExtension` needs the AutoFill
193Credential Provider Entitlement, which corresponds to the key
194`com.apple.developer.authentication-services.autofill-credential-provider`
195Please refer to Apple's documentation on how to set this up.
196
michaeldo8cccf2142017-03-06 22:12:02197### Mobile provisioning profiles for tests
198
Justin Cohena819c112019-08-17 02:19:19199In addition to that, you need a different provisioning profile for each
michaeldo8cccf2142017-03-06 22:12:02200test application. Those provisioning profile will have a bundle identifier
201matching the following pattern `${prefix}.gtest.${test-suite-name}` where
202`${test-suite-name}` is the name of the test suite with underscores changed
203to dashes (e.g. `base_unittests` app will use `${prefix}.gest.base-unittests`
204as bundle identifier).
205
206To be able to run the EarlGrey tests on a device, you'll need two provisioning
207profiles for EarlGrey and OCHamcrest frameworks:
208
209- `${prefix}.test.OCHamcrest`
210- `${prefix}.test.EarlGrey`
211
212In addition to that, then you'll need one additional provisioning profile for
Justin Cohena819c112019-08-17 02:19:19213the XCTest module too. It must match the pattern:
214`${prefix}.gtest.${test-suite-name}-module`.
michaeldo8cccf2142017-03-06 22:12:02215
216### Other applications
217
218Other applications like `ios_web_shell` usually will require mobile provisioning
219profiles with bundle identifiers that may usually match the following pattern
220`${prefix}.${application-name}` and may require specific capabilities.
221
222Generally, if the mobile provisioning profile is missing then the code signing
223step will fail and will print the bundle identifier of the bundle that could not
224be signed on the command line, e.g.:
225
226```shell
Dirk Pranke8bd55f22018-10-24 21:22:10227$ autoninja -C out/Debug-iphoneos ios_web_shell
michaeldo8cccf2142017-03-06 22:12:02228ninja: Entering directory `out/Debug-iphoneos'
229FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
230python ../../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
231Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
232ninja: build stopped: subcommand failed.
233```
234
235Here, the build is failing because there are no mobile provisioning profiles
236installed that could sign the `ios_web_shell.app` bundle with the identity
237`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
238request such a mobile provisioning profile from Apple.
239
240You can inspect the file passed via the `-e` flag to the `codesign.py` script
Quinten Yearsley317532d2021-10-20 17:10:31241to check which capabilities are required for the mobile provisioning profile
michaeldo8cccf2142017-03-06 22:12:02242(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
243remember that the paths are relative to the build directory, not to the source
244directory).
245
246If the required capabilities are not enabled on the mobile provisioning profile,
247then it will be impossible to install the application on a device (Xcode will
248display an error stating that "The application was signed with invalid
249entitlements").
250
Mark Cogan0abda9652020-04-15 11:22:07251## Running apps from the command line
michaeldo8cccf2142017-03-06 22:12:02252
253Any target that is built and runs on the bots (see [below](#Troubleshooting))
254should run successfully in a local build. To run in the simulator from the
255command line, you can use `iossim`. For example, to run a debug build of
256`Chromium`:
257
258```shell
259$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
260```
261
Mike Pinkerton90553fe2017-12-13 16:40:30262With Xcode 9, `iossim` no longer automatically launches the Simulator. This must now
263be done manually from within Xcode (`Xcode > Open Developer Tool > Simulator`), and
264also must be done *after* running `iossim`.
265
Vaclav Brozek09fe5ec2017-07-18 11:13:16266### Passing arguments
267
268Arguments needed to be passed to the test application through `iossim`, such as
269`--gtest_filter=SomeTest.FooBar` should be passed through the `-c` flag:
270
271```shell
Sylvain Defresned019a702018-02-01 10:11:51272$ out/Debug-iphonesimulator/iossim \
Vaclav Brozek09fe5ec2017-07-18 11:13:16273 -c "--gtest_filter=SomeTest.FooBar --gtest_repeat=3" \
274 out/Debug-iphonesimulator/base_unittests.app
275```
276
Mike Baxleycb99a9f2017-07-12 15:16:11277### Running EarlGrey tests
278
279EarlGrey tests are run differently than other test targets, as there is an
280XCTest bundle that is injected into the target application. Therefore you must
281also pass in the test bundle:
282
283```shell
284$ out/Debug-iphonesimulator/iossim \
285 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app \
286 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app/PlugIns/ios_chrome_ui_egtests_module.xctest
287```
288
Sylvain Defresned019a702018-02-01 10:11:51289### Running on specific simulator
290
291By default, `iossim` will pick an arbitrary simulator to run the tests. If
292you want to run them on a specific simulator, you can use `-d` to pick the
293simulated device and `-s` to select the iOS version.
294
295For example, to run the tests on a simulated iPhone 6s running iOS 10.0,
296you would invoke `iossim` like this.
297
298```shell
299$ out/Debug-iphonesimulator/iossim -d 'iPhone 6s' -s '10.0' \
300 out/Debug-iphonesimulator/base_unittests.app
301```
302
303Please note that by default only a subset of simulator devices are installed
304with Xcode. You may have to install additional simulators in Xcode (or even
305an older version of Xcode) to be able to run on a specific configuration.
306
307Go to "Preferences > Components" tab in Xcode to install other simulator images
308(this is the location the setting is in Xcode 9.2; it may be different in other
309version of the tool).
310
michaeldo8cccf2142017-03-06 22:12:02311## Update your checkout
312
313To update an existing checkout, you can run
314
315```shell
316$ git rebase-update
317$ gclient sync
318```
319
320The first command updates the primary Chromium source repository and rebases
321any of your local branches on top of tip-of-tree (aka the Git branch
Andrew Williamsbbc1a1e2021-07-21 01:51:22322`origin/main`). If you don't want to use this script, you can also just use
michaeldo8cccf2142017-03-06 22:12:02323`git pull` or other common Git commands to update the repo.
324
325The second command syncs dependencies to the appropriate versions and re-runs
326hooks as needed.
327
328## Tips, tricks, and troubleshooting
329
Mark Cogan0abda9652020-04-15 11:22:07330Remember that the XCode project you interact with while working on Chromium is a
331build artifact, generated from the `BUILD.gn` files. Do not use it to add new
332files; instead see the procedures for [working with
333files](working_with_files.md).
334
michaeldo8cccf2142017-03-06 22:12:02335If you have problems building, join us in `#chromium` on `irc.freenode.net` and
336ask there. As mentioned above, be sure that the
337[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
338is open before checking out. This will increase your chances of success.
339
Sylvain Defresne01e2ded2020-12-02 11:18:30340### Debugging
341
342To help with deterministic builds, and to work with Goma, the path to source
343files in debugging symbols are relative to source directory. To allow Xcode
344to find the source files, you need to ensure to have an `~/.lldbinit-Xcode`
345file with the following lines into it (substitute {SRC} for your actual path
346to the root of Chromium's sources):
347
348```
349script sys.path[:0] = ['{SRC}/tools/lldb']
350script import lldbinit
351```
352
353This will also allow you to see the content of some of Chromium types in the
Jan Wilken Dörrie85285b02021-03-11 23:38:47354debugger like `std::u16string`, ... If you want to use `lldb` directly, name
Sylvain Defresne01e2ded2020-12-02 11:18:30355the file `~/.lldbinit` instead of `~/.lldbinit-Xcode`.
356
Sylvain Defresne1d01bff02021-01-29 01:13:10357Note: if you are using `ios/build/tools/setup-gn.py` to generate the Xcode
358project, the script also generate an `.lldbinit` file next to the project and
359configure Xcode to use that file instead of the global one.
360
Sylvain Defresne7080fe3b2020-11-16 15:57:51361### Changing the version of Xcode
362
363To change the version of Xcode used to build Chromium on iOS, please follow
364the steps below:
365
3661. Launch the new version of Xcode.app.
367
368 This is required as Xcode may need to install some components into
369 the system before the new version can be used from the command-line.
370
3711. Reboot your computer.
372
373 This is required as some of Xcode components are daemons that are not
374 automatically stopped when updating Xcode, and command-line tools will
375 fail if the daemon version is incompatible (usually `actool` fails).
376
3771. Run `gn gen`.
378
379 This is required as the `ninja` files generated by `gn` encodes some
380 information about Xcode (notably the path to the SDK, ...) that will
381 change with each version. It is not possible to have `ninja` re-run
382 `gn gen` automatically when those changes unfortunately.
383
384 If you have a downstream chekout, run `gclient runhooks` instead of
385 `gn gen` as it will ensure that `gn gen` will be run automatically
386 for all possible combination of target and configuration from within
387 Xcode.
388
389If you skip some of those steps, the build may occasionally succeed, but
390it has been observed in the past that those steps are required in the
391vast majority of the situation. Please save yourself some painful build
392debugging and follow them.
393
394If you use `xcode-select` to switch between multiple version of Xcode,
395you will have to follow the same steps.
396
michaeldo8cccf2142017-03-06 22:12:02397### Improving performance of `git status`
398
ishermance1d9d82017-05-12 23:10:04399#### Increase the vnode cache size
400
michaeldo8cccf2142017-03-06 22:12:02401`git status` is used frequently to determine the status of your checkout. Due
402to the large number of files in Chromium's checkout, `git status` performance
403can be quite variable. Increasing the system's vnode cache appears to help.
404By default, this command:
405
406```shell
407$ sysctl -a | egrep kern\..*vnodes
408```
409
410Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
411setting:
412
413```shell
414$ sudo sysctl kern.maxvnodes=$((512*1024))
415```
416
417Higher values may be appropriate if you routinely move between different
418Chromium checkouts. This setting will reset on reboot, the startup setting can
419be set in `/etc/sysctl.conf`:
420
421```shell
422$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
423```
424
425Or edit the file directly.
426
ishermance1d9d82017-05-12 23:10:04427#### Configure git to use an untracked cache
428
429If `git --version` reports 2.8 or higher, try running
430
431```shell
432$ git update-index --test-untracked-cache
433```
434
435If the output ends with `OK`, then the following may also improve performance of
436`git status`:
437
438```shell
439$ git config core.untrackedCache true
440```
441
442If `git --version` reports 2.6 or higher, but below 2.8, you can instead run
michaeldo8cccf2142017-03-06 22:12:02443
444```shell
445$ git update-index --untracked-cache
446```
447
448### Xcode license agreement
449
450If you're getting the error
451
452> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
453> root via sudo.
454
455the Xcode license hasn't been accepted yet which (contrary to the message) any
456user can do by running:
457
458```shell
459$ xcodebuild -license
460```
461
462Only accepting for all users of the machine requires root:
463
464```shell
465$ sudo xcodebuild -license
466```