Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 1 | # Checking out and building on Fuchsia |
| 2 | |
| 3 | ***Note that the Fuchsia port is in the early stages, and things are likely to |
Fabrice de Gans-Riberi | 4468e91 | 2019-08-23 23:43:54 | [diff] [blame] | 4 | frequently be broken. Try #cr-fuchsia on Freenode or Slack if something seems |
| 5 | awry.*** |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 6 | |
Scott Graham | 6b17c652 | 2018-09-25 20:39:36 | [diff] [blame] | 7 | There are instructions for other platforms linked from the |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 8 | [get the code](get_the_code.md) page. |
| 9 | |
Fabrice de Gans-Riberi | 4468e91 | 2019-08-23 23:43:54 | [diff] [blame] | 10 | [TOC] |
| 11 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 12 | ## System requirements |
| 13 | |
| 14 | * A 64-bit Intel machine with at least 8GB of RAM. More than 16GB is highly |
| 15 | recommended. |
| 16 | * At least 100GB of free disk space. |
| 17 | * You must have Git and Python installed already. |
| 18 | |
Fabrice de Gans-Riberi | bbc67a1b | 2018-08-30 13:19:21 | [diff] [blame] | 19 | Most development is done on Ubuntu. Mac build is supported on a best-effort |
| 20 | basis. |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 21 | |
| 22 | ## Install `depot_tools` |
| 23 | |
| 24 | Clone the `depot_tools` repository: |
| 25 | |
| 26 | ```shell |
| 27 | $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 28 | ``` |
| 29 | |
| 30 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 31 | in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to |
| 32 | `/path/to/depot_tools`: |
| 33 | |
| 34 | ```shell |
| 35 | $ export PATH="$PATH:/path/to/depot_tools" |
| 36 | ``` |
| 37 | |
| 38 | ## Get the code |
| 39 | |
| 40 | Create a `chromium` directory for the checkout and change to it (you can call |
| 41 | this whatever you like and put it wherever you like, as long as the full path |
| 42 | has no spaces): |
| 43 | |
| 44 | ```shell |
| 45 | $ mkdir ~/chromium && cd ~/chromium |
| 46 | ``` |
| 47 | |
| 48 | Run the `fetch` tool from depot_tools to check out the code and its |
| 49 | dependencies. |
| 50 | |
| 51 | ```shell |
| 52 | $ fetch --nohooks chromium |
| 53 | ``` |
| 54 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 55 | Expect the command to take 30 minutes on even a fast connection, and many |
| 56 | hours on slower ones. |
| 57 | |
| 58 | If you've already installed the build dependencies on the machine (from another |
| 59 | checkout, for example), you can omit the `--nohooks` flag and `fetch` |
| 60 | will automatically execute `gclient runhooks` at the end. |
| 61 | |
| 62 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
Adam MacBeth | c6fc88b5 | 2017-06-30 17:26:31 | [diff] [blame] | 63 | directory called `src` in the working directory. |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 64 | |
| 65 | ### Configure for building on Fuchsia |
| 66 | |
| 67 | Edit `.gclient` to include (this is a list, so it could also include `android`, |
| 68 | etc. if necessary.) |
| 69 | |
| 70 | ``` |
| 71 | target_os = ['fuchsia'] |
| 72 | ``` |
| 73 | |
Scott Graham | 9ffcea6 | 2017-06-30 21:31:37 | [diff] [blame] | 74 | Note that this should be added as a top-level statement in the `.gclient` file, |
Sharon Yang | 66f3cee | 2019-03-19 21:16:52 | [diff] [blame] | 75 | not an entry inside the `solutions` dict. An example `.gclient` file would look |
| 76 | as follows: |
| 77 | |
| 78 | ``` |
| 79 | solutions = [ |
| 80 | { |
| 81 | "url": "https://chromium.googlesource.com/chromium/src.git", |
| 82 | "managed": False, |
| 83 | "name": "src", |
| 84 | "custom_deps": {}, |
| 85 | "custom_vars": {} |
| 86 | } |
| 87 | ] |
| 88 | target_os = ['fuchsia'] |
| 89 | ``` |
Scott Graham | 9ffcea6 | 2017-06-30 21:31:37 | [diff] [blame] | 90 | |
Scott Graham | 6b17c652 | 2018-09-25 20:39:36 | [diff] [blame] | 91 | You will then need to run: |
| 92 | |
| 93 | ```shell |
Kevin Marshall | 173a180 | 2020-06-09 18:03:32 | [diff] [blame] | 94 | $ gclient sync |
Scott Graham | 6b17c652 | 2018-09-25 20:39:36 | [diff] [blame] | 95 | ``` |
| 96 | |
| 97 | This makes sure the Fuchsia SDK is available in third\_party and keeps it up to |
| 98 | date. |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 99 | |
Adam MacBeth | c6fc88b5 | 2017-06-30 17:26:31 | [diff] [blame] | 100 | The remaining instructions assume you have switched to the `src` directory: |
| 101 | |
| 102 | ```shell |
| 103 | $ cd src |
| 104 | ``` |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 105 | |
Wez | c03808e | 2018-11-06 06:27:35 | [diff] [blame] | 106 | ### (Linux-only) Install any required host packages |
| 107 | |
| 108 | Chromium relies on some platform packages to be present in order to build. |
| 109 | You can install the current set of required packages with: |
| 110 | |
| 111 | ```shell |
| 112 | $ build/install-build-deps.sh |
| 113 | ``` |
| 114 | |
| 115 | Note that you need to do this only once, and thereafter only if new dependencies |
| 116 | are added - these will be announced to the chromium-dev@ group. |
| 117 | |
Scott Graham | 6b17c652 | 2018-09-25 20:39:36 | [diff] [blame] | 118 | ### Update your checkout |
| 119 | |
| 120 | To update an existing checkout, you can run |
| 121 | |
| 122 | ```shell |
| 123 | $ git rebase-update |
| 124 | $ gclient sync |
| 125 | ``` |
| 126 | |
| 127 | The first command updates the primary Chromium source repository and rebases |
| 128 | any of your local branches on top of tip-of-tree (aka the Git branch |
| 129 | `origin/master`). If you don't want to use this script, you can also just use |
| 130 | `git pull` or other common Git commands to update the repo. |
| 131 | |
| 132 | The second command syncs dependencies to the appropriate versions and re-runs |
| 133 | hooks as needed. `gclient sync` updates dependencies to the versions specified |
| 134 | in `DEPS`, so any time that file is modified (pulling, changing branches, etc.) |
| 135 | `gclient sync` should be run. |
| 136 | |
Fabrice de Gans-Riberi | bbc67a1b | 2018-08-30 13:19:21 | [diff] [blame] | 137 | ## (Mac-only) Download additional required Clang binaries |
| 138 | |
| 139 | Go to [this page](https://chrome-infra-packages.appspot.com/p/fuchsia/clang/mac-amd64/+/) |
| 140 | and download the most recent build. Extract `bin/llvm-ar` to the clang folder |
| 141 | in Chromium: |
| 142 | |
| 143 | ```shell |
| 144 | $ unzip /path/to/clang.zip bin/llvm-ar -d ${CHROMIUM_SRC}/third_party/llvm-build/Release+Asserts |
| 145 | ``` |
| 146 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 147 | ## Setting up the build |
| 148 | |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 149 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with |
| 150 | a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) |
| 151 | to generate `.ninja` files. You can create any number of *build directories* |
| 152 | with different configurations. To create a build directory, run: |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 153 | |
| 154 | ```shell |
Adam MacBeth | ddd50f3 | 2017-07-10 01:42:26 | [diff] [blame] | 155 | $ gn gen out/fuchsia --args="is_debug=false dcheck_always_on=true is_component_build=false target_os=\"fuchsia\"" |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 156 | ``` |
| 157 | |
Wez | 2102c3be | 2017-07-12 01:09:26 | [diff] [blame] | 158 | You can also build for Debug, with `is_debug=true`, but since we don't currently |
| 159 | have any Debug build-bots, it may be more broken than Release. |
| 160 | |
Scott Graham | b69a2f6 | 2017-06-26 19:32:20 | [diff] [blame] | 161 | `use_goma=true` is fine to use also if you're a Googler. |
| 162 | |
Sharon Yang | f6e51ee | 2020-09-25 14:59:51 | [diff] [blame] | 163 | Architecture options are x64 (default) and arm64. This can be set with |
| 164 | `target_cpu=arm64`. |
| 165 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 166 | ## Build |
| 167 | |
Scott Graham | 4c9dc31 | 2018-11-07 19:52:41 | [diff] [blame] | 168 | All targets included in the GN build should build successfully. You can also |
| 169 | build a specific binary, for example, base\_unittests: |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 170 | |
| 171 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 172 | $ autoninja -C out/fuchsia base_unittests |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 173 | ``` |
| 174 | |
Dirk Pranke | 8bd55f2 | 2018-10-24 21:22:10 | [diff] [blame] | 175 | (`autoninja` is a wrapper that automatically provides optimal values for the |
| 176 | arguments passed to `ninja`.) |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 177 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 178 | ## Run |
| 179 | |
Wez | c03808e | 2018-11-06 06:27:35 | [diff] [blame] | 180 | Once you've built a package, you'll want to run it! |
| 181 | |
| 182 | ### (Recommended)(Linux-only) Enable KVM acceleration |
| 183 | |
| 184 | Under Linux, if your host and target CPU architectures are the same (e.g. you're |
| 185 | building for Fuchsia/x64 on a Linux/x64 host) then you can benefit from QEMU's |
| 186 | support for the KVM hypervisor: |
| 187 | |
| 188 | 1. Install the KVM module for your kernel, to get a /dev/kvm device. |
| 189 | 2. Ensure that your system has a "kvm" group, and it owns /dev/kvm. |
| 190 | You can do that by installing the QEMU system common package: |
| 191 | ```shell |
| 192 | $ sudo apt-get install qemu-system-common |
| 193 | ``` |
| 194 | 3. Add users to the "kvm" group, and have them login again, to pick-up the new |
| 195 | group. |
Mukesh Agrawal | 7f69540 | 2020-03-11 16:43:15 | [diff] [blame] | 196 | ```shell |
| 197 | $ sudo adduser <user> kvm |
| 198 | $ exit |
| 199 | [log in again] |
| 200 | ``` |
Wez | c03808e | 2018-11-06 06:27:35 | [diff] [blame] | 201 | |
Fabrice de Gans-Riberi | cfa0fb7d8 | 2019-07-02 18:23:09 | [diff] [blame] | 202 | ### Running test suites |
| 203 | |
Chong Gu | 9ad904d | 2019-09-26 23:24:02 | [diff] [blame] | 204 | Building test suites generate a launcher script to run them on an emulator |
Fabrice de Gans-Riberi | cfa0fb7d8 | 2019-07-02 18:23:09 | [diff] [blame] | 205 | or a physical device. These scripts are generated at `out/fuchsia/bin`. For |
| 206 | instance,to run the `base_unittests` target, launch: |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 207 | |
| 208 | ```shell |
Wez | 2102c3be | 2017-07-12 01:09:26 | [diff] [blame] | 209 | $ out/fuchsia/bin/run_base_unittests |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 210 | ``` |
| 211 | |
Scott Graham | f94d84d | 2017-06-26 18:24:40 | [diff] [blame] | 212 | Common gtest arguments such as `--gtest_filter=...` are supported by the run |
Fabrice de Gans-Riberi | cfa0fb7d8 | 2019-07-02 18:23:09 | [diff] [blame] | 213 | script. The launcher script also symbolizes backtraces. |
Fabrice de Gans-Riberi | 4468e91 | 2019-08-23 23:43:54 | [diff] [blame] | 214 | |
Chong Gu | 9ad904d | 2019-09-26 23:24:02 | [diff] [blame] | 215 | The test suite, by default, will run on QEMU. AEMU can be used for running |
| 216 | tests that interact with Fuchsia's window manager, Scenic. To change the device |
| 217 | that Fuchsia will run on, use `--device={aemu|qemu|device}`. |
| 218 | |
Fabrice de Gans-Riberi | 4468e91 | 2019-08-23 23:43:54 | [diff] [blame] | 219 | To run a test suite on an *unprovisioned device* in a zedboot state, simply add |
| 220 | `-d` to the test runner script arguments. Subsequent runs of the test runner |
| 221 | script will be able to pick up the same device. |
| 222 | |
| 223 | To run a test suite on a device that is *already provisioned*, add the following |
| 224 | arguments to the test runner script: |
| 225 | |
| 226 | * `-d` to run the test suite on a device. |
| 227 | * `--fuchsia-out-dir=[/path/to/fuchsia/out/directory]` or |
| 228 | `--ssh-config=[/path/to/ssh_config]` to specify the SSH configuration used for |
| 229 | connecting to the target device. |
| 230 | * (Optional) `--host=[IP]` to specify the test device IP. Typically, this is the |
| 231 | value obtained from the command `fx netaddr --fuchsia`. |
| 232 | * (Optional) `--port=[port]` to specify the SSH port, if different from 22. |
| 233 | |
| 234 | ### Troubleshooting a test |
| 235 | |
| 236 | To troubleshoot a specific test, consider a combination of the following |
| 237 | arguments to the test runner script: |
| 238 | |
| 239 | * `--gtest_filter="[TestSuite.TestName]"` to only run a specific test, or a |
| 240 | comma-separated list to run a set of tests. Wildcards can also be used to run |
| 241 | a set of tests or an entire test suite, e.g. `--gtest_filter="[TestSuite.*]"`. |
| 242 | * `--test-launcher-jobs=1` to only have one batch of tests running at a time. |
| 243 | This bypasses the test launcher buffering of test log output, making it |
| 244 | possible to access the log output from successful test runs. |
| 245 | * `--single-process-tests` to run all the tests in the same process. Unlike the |
| 246 | above option, this will run the tests directly in the test launcher process, |
| 247 | making it easier to attach a debugger. |
| 248 | * `system-log-file=[/path/to/syslog]` to specify the file to write system logs |
| 249 | to. Or `system-log-file=-` to write the system logs to stdout. By default, |
| 250 | Chromium logs are written to the system log on Fuchsia. This argument is known |
| 251 | to cause `IOError` python exceptions with a QEMU target. |
| 252 | * `--gtest_repeat=[number] --gtest_break_on_failure` to run a test or test suite |
| 253 | a certain number of times until it fails. This is useful to investigate flaky |
| 254 | tests. |