blob: 93ccccb9505b9dd33a4397a01ddc74c294fe0177 [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 Defresne991d8e22023-11-29 17:15:3015* A 64-bit Mac capable of running the required version of Xcode.
16* [Xcode](https://developer.apple.com/xcode) 15.0 or higher.
17
18Note: after installing Xcode, you need to launch it and to let it install
19the iOS simulator. This is required as part of the build, see [this discussion](
20https://groups.google.com/a/chromium.org/g/chromium-dev/c/98d6MyLoYHM/m/A_HyOGxPAgAJ)
21on chromium-dev.
michaeldo8cccf2142017-03-06 22:12:0222
23## Install `depot_tools`
24
25Clone the `depot_tools` repository:
26
27```shell
28$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
29```
30
31Add `depot_tools` to the end of your PATH (you will probably want to put this
32in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to
33`/path/to/depot_tools`:
34
35```shell
36$ export PATH="$PATH:/path/to/depot_tools"
37```
38
39## Get the code
40
41Create a `chromium` directory for the checkout and change to it (you can call
42this whatever you like and put it wherever you like, as
43long as the full path has no spaces):
44
45```shell
46$ mkdir chromium && cd chromium
47```
48
49Run the `fetch` tool from `depot_tools` to check out the code and its
50dependencies.
51
52```shell
53$ fetch ios
54```
55
56If you don't want the full repo history, you can save a lot of time by
57adding the `--no-history` flag to `fetch`.
58
59Expect the command to take 30 minutes on even a fast connection, and many
60hours on slower ones.
61
62When `fetch` completes, it will have created a hidden `.gclient` file and a
63directory called `src` in the working directory. The remaining instructions
64assume you have switched to the `src` directory:
65
66```shell
67$ cd src
68```
69
70*Optional*: You can also [install API
71keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
72build to talk to some Google services, but this is not necessary for most
73development and testing purposes.
74
75## Setting up the build
76
77Since the iOS build is a bit more complicated than a desktop build, we provide
78`ios/build/tools/setup-gn.py`, which will create four appropriately configured
79build directories under `out` for Release and Debug device and simulator
Sylvain Defresnefc11bcd2020-06-26 13:42:0080builds, and generates an appropriate Xcode project (`out/build/all.xcodeproj`)
81as well.
michaeldo8cccf2142017-03-06 22:12:0282
Sylvain Defresnefc11bcd2020-06-26 13:42:0083More information about [developing with Xcode](xcode_tips.md). *Xcode project
84is an artifact, any changes made in the project itself will be ignored.*
Mike Doughertyd8947a592020-05-07 19:43:4685
michaeldo8cccf2142017-03-06 22:12:0286You can customize the build by editing the file `$HOME/.setup-gn` (create it if
87it does not exist). Look at `src/ios/build/tools/setup-gn.config` for
88available configuration options.
89
90From this point, you can either build from Xcode or from the command line using
Dirk Pranke8bd55f22018-10-24 21:22:1091`autoninja`. `setup-gn.py` creates sub-directories named
michaeldo8cccf2142017-03-06 22:12:0292`out/${configuration}-${platform}`, so for a `Debug` build for simulator use:
93
94```shell
Dirk Pranke8bd55f22018-10-24 21:22:1095$ autoninja -C out/Debug-iphonesimulator gn_all
michaeldo8cccf2142017-03-06 22:12:0296```
97
Dirk Pranke8bd55f22018-10-24 21:22:1098(`autoninja` is a wrapper that automatically provides optimal values for the
99arguments passed to `ninja`.)
100
Mike Doughertyd8947a592020-05-07 19:43:46101Note: The `setup-gn.py` script needs to run every time one of the `BUILD.gn`
102files is updated (either by you or after rebasing). If you forget to run it,
103the list of targets and files in the Xcode solution may be stale. You can run
104the script directly or use either `gclient sync` or `gclient runhooks` which
105will run `setup-gn.py` for you as part of the update hooks.
michaeldo8cccf2142017-03-06 22:12:02106
Sylvain Defresne9932328e2020-07-09 10:44:40107You can add a custom hook to `.gclient` file to configure `setup-gn.py` to
108be run as part of `gclient runhooks`. In that case, your `.gclient` file
109would look like this:
110
111```
112solutions = [
113 {
114 "name" : "src",
115 "url" : "https://chromium.googlesource.com/chromium/src.git",
116 "deps_file" : "DEPS",
117 "managed" : False,
118 "custom_deps" : {},
119 "custom_vars" : {},
120 "custom_hooks": [{
121 "name": "setup_gn",
122 "pattern": ".",
123 "action": [
Takuto Ikutad36eb352022-03-01 01:39:48124 "python3",
Sylvain Defresne9932328e2020-07-09 10:44:40125 "src/ios/build/tools/setup-gn.py",
126 ]
127 }],
128 "safesync_url": "",
129 },
130]
131target_os = ["ios"]
132target_os_only = True
133```
134
michaeldo8cccf2142017-03-06 22:12:02135You can also follow the manual instructions on the
136[Mac page](../mac_build_instructions.md), but make sure you set the
137GN arg `target_os="ios"`.
138
139## Building for device
140
141To be able to build and run Chromium and the tests for devices, you need to
142have an Apple developer account (a free one will work) and the appropriate
143provisioning profiles, then configure the build to use them.
144
145### Code signing identity
146
147Please refer to the Apple documentation on how to get a code signing identity
148and certificates. You can check that you have a code signing identity correctly
149installed by running the following command.
150
151```shell
152$ xcrun security find-identity -v -p codesigning
153 1) 0123456789ABCDEF0123456789ABCDEF01234567 "iPhone Developer: [email protected] (XXXXXXXXXX)"
154 1 valid identities found
155```
156
157If the command output says you have zero valid identities, then you do not
158have a code signing identity installed and need to get one from Apple. If
159you have more than one identity, the build system may select the wrong one
160automatically, and you can use the `ios_code_signing_identity` gn variable
161to control which one to use by setting it to the identity hash, e.g. to
162`"0123456789ABCDEF0123456789ABCDEF01234567"`.
163
164### Mobile provisioning profiles
165
166Once you have the code signing identity, you need to decide on a prefix
167for the application bundle identifier. This is controlled by the gn variable
168`ios_app_bundle_id_prefix` and usually corresponds to a reversed domain name
169(the default value is `"org.chromium"`).
170
171You then need to request provisioning profiles from Apple for your devices
172for the following bundle identifiers to build and run Chromium with these
173application extensions:
174
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34175- `${prefix}.chrome.ios.dev`
176- `${prefix}.chrome.ios.dev.ContentTodayExtension`
177- `${prefix}.chrome.ios.dev.CredentialProviderExtension`
Sylvain Defresnec2117082021-10-29 10:05:48178- `${prefix}.chrome.ios.dev.IntentsExtension`
Henrique Ferreirodbd08652023-11-09 10:24:54179- `${prefix}.chrome.ios.dev.OpenExtension`
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34180- `${prefix}.chrome.ios.dev.ShareExtension`
181- `${prefix}.chrome.ios.dev.TodayExtension`
182- `${prefix}.chrome.ios.dev.WidgetKitExtension`
michaeldo8cccf2142017-03-06 22:12:02183
184All these certificates need to have the "App Groups"
185(`com.apple.security.application-groups`) capability enabled for
186the following groups:
187
188- `group.${prefix}.chrome`
189- `group.${prefix}.common`
190
191The `group.${prefix}.chrome` is only shared by Chromium and its extensions
192to share files and configurations while the `group.${prefix}.common` is shared
193with Chromium and other applications from the same organisation and can be used
194to send commands to Chromium.
195
Takuto Ikutad36eb352022-03-01 01:39:48196`${prefix}.chrome.ios.dev.CredentialProviderExtension` needs the AutoFill
197Credential Provider Entitlement, which corresponds to the key
Javier Ernesto Flores Roblese68ab7e52021-01-20 18:14:34198`com.apple.developer.authentication-services.autofill-credential-provider`
199Please refer to Apple's documentation on how to set this up.
200
michaeldo8cccf2142017-03-06 22:12:02201### Mobile provisioning profiles for tests
202
Justin Cohena819c112019-08-17 02:19:19203In addition to that, you need a different provisioning profile for each
michaeldo8cccf2142017-03-06 22:12:02204test application. Those provisioning profile will have a bundle identifier
205matching the following pattern `${prefix}.gtest.${test-suite-name}` where
206`${test-suite-name}` is the name of the test suite with underscores changed
Tiago Vignatticdb9de42023-06-28 16:15:54207to dashes (e.g. `base_unittests` app will use `${prefix}.gtest.base-unittests`
michaeldo8cccf2142017-03-06 22:12:02208as bundle identifier).
209
210To be able to run the EarlGrey tests on a device, you'll need two provisioning
211profiles for EarlGrey and OCHamcrest frameworks:
212
213- `${prefix}.test.OCHamcrest`
214- `${prefix}.test.EarlGrey`
215
216In addition to that, then you'll need one additional provisioning profile for
Justin Cohena819c112019-08-17 02:19:19217the XCTest module too. It must match the pattern:
218`${prefix}.gtest.${test-suite-name}-module`.
michaeldo8cccf2142017-03-06 22:12:02219
220### Other applications
221
222Other applications like `ios_web_shell` usually will require mobile provisioning
223profiles with bundle identifiers that may usually match the following pattern
224`${prefix}.${application-name}` and may require specific capabilities.
225
226Generally, if the mobile provisioning profile is missing then the code signing
227step will fail and will print the bundle identifier of the bundle that could not
228be signed on the command line, e.g.:
229
230```shell
Dirk Pranke8bd55f22018-10-24 21:22:10231$ autoninja -C out/Debug-iphoneos ios_web_shell
michaeldo8cccf2142017-03-06 22:12:02232ninja: Entering directory `out/Debug-iphoneos'
233FAILED: ios_web_shell.app/ios_web_shell ios_web_shell.app/_CodeSignature/CodeResources ios_web_shell.app/embedded.mobileprovision
234python ../../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
235Error: no mobile provisioning profile found for "org.chromium.ios-web-shell".
236ninja: build stopped: subcommand failed.
237```
238
239Here, the build is failing because there are no mobile provisioning profiles
240installed that could sign the `ios_web_shell.app` bundle with the identity
241`0123456789ABCDEF0123456789ABCDEF01234567`. To fix the build, you'll need to
242request such a mobile provisioning profile from Apple.
243
244You can inspect the file passed via the `-e` flag to the `codesign.py` script
Quinten Yearsley317532d2021-10-20 17:10:31245to check which capabilities are required for the mobile provisioning profile
michaeldo8cccf2142017-03-06 22:12:02246(e.g. `src/build/config/ios/entitlements.plist` for the above build error,
247remember that the paths are relative to the build directory, not to the source
248directory).
249
250If the required capabilities are not enabled on the mobile provisioning profile,
251then it will be impossible to install the application on a device (Xcode will
252display an error stating that "The application was signed with invalid
253entitlements").
254
Dave Tapuskafeb0745b2023-02-07 21:47:47255## Building Blink for iOS
256
257The iOS build supports compiling the blink web platform. To compile blink
258set a gn arg in your `.setup-gn` file. Note the blink web platform is
259experimental code and should only be used for analysis.
260
261```
262[gn_args]
263use_blink = true
264```
265Note that only certain targets support blink. `content_shell` being the
266most useful.
267
268```shell
269$ autoninja -C out/Debug-iphonesimulator content_shell
270```
271
272To run on a live device you will need to set the
Abhijeet Kandalkar4ab961e2023-02-08 17:13:43273`com.apple.developer.kernel.extended-virtual-addressing` entitlement.
Dave Tapuskafeb0745b2023-02-07 21:47:47274
Mark Cogan0abda9652020-04-15 11:22:07275## Running apps from the command line
michaeldo8cccf2142017-03-06 22:12:02276
277Any target that is built and runs on the bots (see [below](#Troubleshooting))
278should run successfully in a local build. To run in the simulator from the
279command line, you can use `iossim`. For example, to run a debug build of
280`Chromium`:
281
282```shell
283$ out/Debug-iphonesimulator/iossim out/Debug-iphonesimulator/Chromium.app
284```
285
Antonio Gomes627d0de32023-02-20 17:30:48286From Xcode 9 on, `iossim` no longer automatically launches the Simulator. This must now
Mike Pinkerton90553fe2017-12-13 16:40:30287be done manually from within Xcode (`Xcode > Open Developer Tool > Simulator`), and
288also must be done *after* running `iossim`.
289
Vaclav Brozek09fe5ec2017-07-18 11:13:16290### Passing arguments
291
292Arguments needed to be passed to the test application through `iossim`, such as
293`--gtest_filter=SomeTest.FooBar` should be passed through the `-c` flag:
294
295```shell
Sylvain Defresned019a702018-02-01 10:11:51296$ out/Debug-iphonesimulator/iossim \
Vaclav Brozek09fe5ec2017-07-18 11:13:16297 -c "--gtest_filter=SomeTest.FooBar --gtest_repeat=3" \
298 out/Debug-iphonesimulator/base_unittests.app
299```
300
Mike Baxleycb99a9f2017-07-12 15:16:11301### Running EarlGrey tests
302
303EarlGrey tests are run differently than other test targets, as there is an
304XCTest bundle that is injected into the target application. Therefore you must
305also pass in the test bundle:
306
307```shell
308$ out/Debug-iphonesimulator/iossim \
309 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app \
310 out/Debug-iphonesimulator/ios_chrome_ui_egtests.app/PlugIns/ios_chrome_ui_egtests_module.xctest
311```
312
Gyuyoung Kim9497f0eb2023-09-19 05:32:04313### Running Web Tests on Blink for iOS
314
315The current Blink for iOS only supports running Web Tests on the simulator
316environment now. Before you run the web tests, you need to build the blink_tests
317target to get content_shell and all of the other needed binaries for the
318simulator test environment.
319
320```shell
321$ autoninja -C out/Debug-iphonesimulator blink_tests
322```
323
324When the blink_tests target is complete you can then run the test runner script
325(third_party/blink/tools/run_web_tests.py) as below. See [Web Tests](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/web_tests.md) document
326for more information.
327
328```shell
329$ third_party/blink/tools/run_web_tests.py -t Debug-iphonesimulator \
330 --platform ios
331```
332
Sylvain Defresned019a702018-02-01 10:11:51333### Running on specific simulator
334
335By default, `iossim` will pick an arbitrary simulator to run the tests. If
336you want to run them on a specific simulator, you can use `-d` to pick the
337simulated device and `-s` to select the iOS version.
338
339For example, to run the tests on a simulated iPhone 6s running iOS 10.0,
340you would invoke `iossim` like this.
341
342```shell
343$ out/Debug-iphonesimulator/iossim -d 'iPhone 6s' -s '10.0' \
344 out/Debug-iphonesimulator/base_unittests.app
345```
346
347Please note that by default only a subset of simulator devices are installed
348with Xcode. You may have to install additional simulators in Xcode (or even
349an older version of Xcode) to be able to run on a specific configuration.
350
351Go to "Preferences > Components" tab in Xcode to install other simulator images
352(this is the location the setting is in Xcode 9.2; it may be different in other
353version of the tool).
354
Tiago Vignattie1599c52023-04-21 07:14:46355### Remote debugging with DevTools (on Blink for iOS)
356
357Developers are able to remotely use DevTools in a host machine (e.g. Mac) and
358inspect `content_shell` for development.
359
360On the simulator, one just needs to pass the `--remote-debugging-port=9222`
361argument for `content_shell` and in the host machine access it via
362`chrome://inspect`. It is possible to change the default port listening (9222)
363and configure another one via the "Configure…" button and then "Target
364discovery settings" dialog.
365
366To use DevTools in the remote device it is necessary to also pass the remote
367debugging address argument to `content-shell` so any address could bind for
368debugging: ` --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222`.
369Then in the host machine one needs to configure the IP address of the device in
370the "Target discovery settings" dialog e.g. `192.168.0.102:9222`.
371
michaeldo8cccf2142017-03-06 22:12:02372## Update your checkout
373
374To update an existing checkout, you can run
375
376```shell
377$ git rebase-update
378$ gclient sync
379```
380
381The first command updates the primary Chromium source repository and rebases
382any of your local branches on top of tip-of-tree (aka the Git branch
Andrew Williamsbbc1a1e2021-07-21 01:51:22383`origin/main`). If you don't want to use this script, you can also just use
michaeldo8cccf2142017-03-06 22:12:02384`git pull` or other common Git commands to update the repo.
385
386The second command syncs dependencies to the appropriate versions and re-runs
387hooks as needed.
388
389## Tips, tricks, and troubleshooting
390
Mark Cogan0abda9652020-04-15 11:22:07391Remember that the XCode project you interact with while working on Chromium is a
392build artifact, generated from the `BUILD.gn` files. Do not use it to add new
393files; instead see the procedures for [working with
394files](working_with_files.md).
395
michaeldo8cccf2142017-03-06 22:12:02396If you have problems building, join us in `#chromium` on `irc.freenode.net` and
397ask there. As mentioned above, be sure that the
398[waterfall](https://build.chromium.org/buildbot/waterfall/) is green and the tree
399is open before checking out. This will increase your chances of success.
400
Sylvain Defresne01e2ded2020-12-02 11:18:30401### Debugging
402
403To help with deterministic builds, and to work with Goma, the path to source
404files in debugging symbols are relative to source directory. To allow Xcode
405to find the source files, you need to ensure to have an `~/.lldbinit-Xcode`
406file with the following lines into it (substitute {SRC} for your actual path
407to the root of Chromium's sources):
408
409```
410script sys.path[:0] = ['{SRC}/tools/lldb']
411script import lldbinit
412```
413
414This will also allow you to see the content of some of Chromium types in the
Jan Wilken Dörrie85285b02021-03-11 23:38:47415debugger like `std::u16string`, ... If you want to use `lldb` directly, name
Sylvain Defresne01e2ded2020-12-02 11:18:30416the file `~/.lldbinit` instead of `~/.lldbinit-Xcode`.
417
Sylvain Defresne1d01bff02021-01-29 01:13:10418Note: if you are using `ios/build/tools/setup-gn.py` to generate the Xcode
419project, the script also generate an `.lldbinit` file next to the project and
420configure Xcode to use that file instead of the global one.
421
Sylvain Defresne7080fe3b2020-11-16 15:57:51422### Changing the version of Xcode
423
424To change the version of Xcode used to build Chromium on iOS, please follow
425the steps below:
426
4271. Launch the new version of Xcode.app.
428
429 This is required as Xcode may need to install some components into
430 the system before the new version can be used from the command-line.
431
4321. Reboot your computer.
433
434 This is required as some of Xcode components are daemons that are not
435 automatically stopped when updating Xcode, and command-line tools will
436 fail if the daemon version is incompatible (usually `actool` fails).
437
4381. Run `gn gen`.
439
440 This is required as the `ninja` files generated by `gn` encodes some
441 information about Xcode (notably the path to the SDK, ...) that will
442 change with each version. It is not possible to have `ninja` re-run
443 `gn gen` automatically when those changes unfortunately.
444
445 If you have a downstream chekout, run `gclient runhooks` instead of
446 `gn gen` as it will ensure that `gn gen` will be run automatically
447 for all possible combination of target and configuration from within
448 Xcode.
449
450If you skip some of those steps, the build may occasionally succeed, but
451it has been observed in the past that those steps are required in the
452vast majority of the situation. Please save yourself some painful build
453debugging and follow them.
454
455If you use `xcode-select` to switch between multiple version of Xcode,
456you will have to follow the same steps.
457
Bruce Dawson425d4ab2023-06-25 01:36:15458### Improving performance of git commands
michaeldo8cccf2142017-03-06 22:12:02459
ishermance1d9d82017-05-12 23:10:04460#### Increase the vnode cache size
461
michaeldo8cccf2142017-03-06 22:12:02462`git status` is used frequently to determine the status of your checkout. Due
463to the large number of files in Chromium's checkout, `git status` performance
464can be quite variable. Increasing the system's vnode cache appears to help.
465By default, this command:
466
467```shell
468$ sysctl -a | egrep kern\..*vnodes
469```
470
471Outputs `kern.maxvnodes: 263168` (263168 is 257 * 1024). To increase this
472setting:
473
474```shell
475$ sudo sysctl kern.maxvnodes=$((512*1024))
476```
477
478Higher values may be appropriate if you routinely move between different
479Chromium checkouts. This setting will reset on reboot, the startup setting can
480be set in `/etc/sysctl.conf`:
481
482```shell
483$ echo kern.maxvnodes=$((512*1024)) | sudo tee -a /etc/sysctl.conf
484```
485
486Or edit the file directly.
487
ishermance1d9d82017-05-12 23:10:04488#### Configure git to use an untracked cache
489
Bruce Dawson2154274a2023-06-17 22:24:29490Try running
ishermance1d9d82017-05-12 23:10:04491
492```shell
493$ git update-index --test-untracked-cache
494```
495
496If the output ends with `OK`, then the following may also improve performance of
497`git status`:
498
499```shell
500$ git config core.untrackedCache true
501```
502
Tiago Vignatti760b0c02023-05-29 19:45:24503#### Configure git to use fsmonitor
504
Bruce Dawson2154274a2023-06-17 22:24:29505You can significantly speed up git by using [fsmonitor.](https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/)
506You should enable fsmonitor in large repos, such as Chromium and v8. Enabling
Avi Drissman9908ae442023-09-29 16:31:11507it globally will launch many processes and probably isn't worthwhile. Be sure
508you have at least version 2.43 (fsmonitor on the Mac is broken before then). The
Bruce Dawson2154274a2023-06-17 22:24:29509command to enable fsmonitor in the current repo is:
Tiago Vignatti760b0c02023-05-29 19:45:24510
511```shell
512$ git config core.fsmonitor true
513```
514
michaeldo8cccf2142017-03-06 22:12:02515### Xcode license agreement
516
517If you're getting the error
518
519> Agreeing to the Xcode/iOS license requires admin privileges, please re-run as
520> root via sudo.
521
522the Xcode license hasn't been accepted yet which (contrary to the message) any
523user can do by running:
524
525```shell
526$ xcodebuild -license
527```
528
529Only accepting for all users of the machine requires root:
530
531```shell
532$ sudo xcodebuild -license
533```