dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 1 | # Checking out and building Chromium on Linux |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 3 | **See also [the old version of this page](old_linux_build_instructions.md).** |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 4 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 5 | Google employee? See [go/building-chrome](https://goto.google.com/building-chrome) instead. |
andybons | 8c02a1f | 2015-09-04 17:02:32 | [diff] [blame] | 6 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 7 | [TOC] |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 8 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 9 | ## System requirements |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 10 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 11 | * A 64-bit Intel machine with at least 8GB of RAM. More than 16GB is highly |
| 12 | recommended. |
| 13 | * At least 100GB of free disk space. |
| 14 | * You must have Git and Python installed already. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 16 | Most development is done on Ubuntu (currently 14.04, Trusty Tahr). There are |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 17 | some instructions for other distros below, but they are mostly unsupported. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 18 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 19 | ## Install `depot_tools` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 20 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 21 | Clone the `depot_tools` repository: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 22 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 23 | ```shell |
| 24 | $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 25 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 26 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 27 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 28 | in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` to |
| 29 | `/path/to/depot_tools`: |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 30 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 31 | ```shell |
| 32 | $ export PATH="$PATH:/path/to/depot_tools" |
| 33 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 34 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 35 | ## Get the code |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 36 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 37 | Create a `chromium` directory for the checkout and change to it (you can call |
| 38 | this whatever you like and put it wherever you like, as long as the full path |
| 39 | has no spaces): |
| 40 | |
| 41 | ```shell |
| 42 | $ mkdir ~/chromium && cd ~/chromium |
| 43 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 44 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 45 | Run the `fetch` tool from depot_tools to check out the code and its |
| 46 | dependencies. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 47 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 48 | ```shell |
| 49 | $ fetch --nohooks chromium |
| 50 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 51 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 52 | If you don't want the full repo history, you can save a lot of time by |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 53 | adding the `--no-history` flag to `fetch`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 54 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 55 | Expect the command to take 30 minutes on even a fast connection, and many |
| 56 | hours on slower ones. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 57 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 58 | If you've already installed the build dependencies on the machine (from another |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 59 | checkout, for example), you can omit the `--nohooks` flag and `fetch` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 60 | will automatically execute `gclient runhooks` at the end. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 61 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 62 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 63 | directory called `src` in the working directory. The remaining instructions |
| 64 | assume you have switched to the `src` directory: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 65 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 66 | ```shell |
| 67 | $ cd src |
| 68 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 69 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 70 | ### Install additional build dependencies |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 71 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 72 | Once you have checked out the code, and assuming you're using Ubuntu, run |
| 73 | [build/install-build-deps.sh](/build/install-build-deps.sh) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 74 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 75 | Here are some instructions for what to do instead for |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 76 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 77 | * [Debian](linux_debian_build_instructions.md) |
| 78 | * [Fedora](linux_fedora_build_instructions.md) |
| 79 | * [Arch Linux](linux_arch_build_instructions.md) |
| 80 | * [Open SUSE](linux_open_suse_build_instrctions.md) |
| 81 | * [Mandriva](linux_mandriva_build_instrctions.md) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 82 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 83 | For Gentoo, you can just run `emerge www-client/chromium`. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 84 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 85 | ### Run the hooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 86 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 87 | Once you've run `install-build-deps` at least once, you can now run the |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 88 | Chromium-specific hooks, which will download additional binaries and other |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 89 | things you might need: |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 90 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 91 | ```shell |
| 92 | $ gclient runhooks |
| 93 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 94 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 95 | *Optional*: You can also [install API |
| 96 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 97 | build to talk to some Google services, but this is not necessary for most |
| 98 | development and testing purposes. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 99 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 100 | ## Setting up the Build |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 101 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 102 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along |
| 103 | with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja` |
| 104 | files. You can create any number of *build directories* with different |
| 105 | configurations. To create a build directory, run: |
andybons | 8c02a1f | 2015-09-04 17:02:32 | [diff] [blame] | 106 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 107 | ```shell |
| 108 | $ gn gen out/Default |
| 109 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 110 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 111 | * You only have to run this once for each new build directory, Ninja will |
| 112 | update the build files as needed. |
| 113 | * You can replace `Default` with another name, but |
| 114 | it should be a subdirectory of `out`. |
| 115 | * For other build arguments, including release settings, see [GN build |
| 116 | configuration](https://www.chromium.org/developers/gn-build-configuration). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 117 | The default will be a debug component build matching the current host |
| 118 | operating system and CPU. |
| 119 | * For more info on GN, run `gn help` on the command line or read the |
| 120 | [quick start guide](../tools/gn/docs/quick_start.md). |
| 121 | |
| 122 | ### Faster builds |
| 123 | |
| 124 | See [faster builds on Linux](linux_faster_builds.md) for various tips and |
| 125 | settings that may speed up your build. |
| 126 | |
| 127 | ## Build Chromium |
| 128 | |
| 129 | Build Chromium (the "chrome" target) with Ninja using the command: |
| 130 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 131 | ```shell |
| 132 | $ ninja -C out/Default chrome |
| 133 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 134 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 135 | You can get a list of all of the other build targets from GN by running `gn ls |
| 136 | out/Default` from the command line. To compile one, pass the GN label to Ninja |
| 137 | with no preceding "//" (so, for `//chrome/test:unit_tests` use `ninja -C |
| 138 | out/Default chrome/test:unit_tests`). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 139 | |
| 140 | ## Run Chromium |
| 141 | |
| 142 | Once it is built, you can simply run the browser: |
| 143 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 144 | ```shell |
| 145 | $ out/Default/chrome |
| 146 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 147 | |
| 148 | ## Running test targets |
| 149 | |
| 150 | You can run the tests in the same way. You can also limit which tests are |
| 151 | run using the `--gtest_filter` arg, e.g.: |
| 152 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 153 | ```shell |
| 154 | $ ninja -C out/Default unit_tests --gtest_filter="PushClientTest.*" |
| 155 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 156 | |
| 157 | You can find out more about GoogleTest at its |
| 158 | [GitHub page](https://github.com/google/googletest). |
| 159 | |
| 160 | ## Update your checkout |
| 161 | |
| 162 | To update an existing checkout, you can run |
| 163 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 164 | ```shell |
| 165 | $ git rebase-update |
| 166 | $ gclient sync |
| 167 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 168 | |
| 169 | The first command updates the primary Chromium source repository and rebases |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 170 | any of your local branches on top of tip-of-tree (aka the Git branch |
| 171 | `origin/master`). If you don't want to use this script, you can also just use |
| 172 | `git pull` or other common Git commands to update the repo. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 173 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 174 | The second command syncs dependencies to the appropriate versions and re-runs |
| 175 | hooks as needed. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 176 | |
| 177 | ## Tips, tricks, and troubleshooting |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 178 | |
| 179 | ### Linker Crashes |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 180 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 181 | If, during the final link stage: |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 182 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 183 | ``` |
| 184 | LINK out/Debug/chrome |
| 185 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 186 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 187 | You get an error like: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 188 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 189 | ``` |
| 190 | collect2: ld terminated with signal 6 Aborted terminate called after throwing an instance of 'std::bad_alloc' |
| 191 | collect2: ld terminated with signal 11 [Segmentation fault], core dumped |
| 192 | ``` |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 193 | |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 194 | you are probably running out of memory when linking. You *must* use a 64-bit |
| 195 | system to build. Try the following build settings (see [GN build |
| 196 | configuration](https://www.chromium.org/developers/gn-build-configuration) for |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 197 | other settings): |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 198 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 199 | * Build in release mode (debugging symbols require more memory): |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 200 | `is_debug = false` |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame^] | 201 | * Turn off symbols: `symbol_level = 0` |
| 202 | * Build in component mode (this is for development only, it will be slower and |
| 203 | may have broken functionality): `is_component_build = true` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 204 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 205 | ### More links |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 206 | |
brettw | c25693b3 | 2016-05-26 01:11:52 | [diff] [blame] | 207 | * Information about [building with Clang](clang.md). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 208 | * You may want to [use a chroot](using_a_linux_chroot.md) to |
| 209 | isolate yourself from versioning or packaging conflicts. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 210 | * Cross-compiling for ARM? See [LinuxChromiumArm](linux_chromium_arm.md). |
| 211 | * Want to use Eclipse as your IDE? See |
| 212 | [LinuxEclipseDev](linux_eclipse_dev.md). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 213 | * Want to use your built version as your default browser? See |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 214 | [LinuxDevBuildAsDefaultBrowser](linux_dev_build_as_default_browser.md). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 215 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 216 | ### Next Steps |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 217 | |
| 218 | If you want to contribute to the effort toward a Chromium-based browser for |
| 219 | Linux, please check out the [Linux Development page](linux_development.md) for |
| 220 | more information. |