andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 1 | # Common Build Tasks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 3 | The Chromium build system is a complicated beast of a system, and it is not very |
| 4 | well documented beyond the basics of getting the source and building the |
| 5 | Chromium product. This page has more advanced information about the build |
| 6 | system. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 7 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 8 | If you're new to Chromium development, read the |
tfarina | 5f2d8e2f | 2016-03-04 09:57:33 | [diff] [blame] | 9 | [getting started guides](https://www.chromium.org/developers/how-tos/get-the-code). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 10 | |
andybons | 8c02a1f | 2015-09-04 17:02:32 | [diff] [blame] | 11 | There is some additional documentation on |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 12 | [setting GYP build parameters](https://dev.chromium.org/developers/gyp-environment-variables). |
andybons | 8c02a1f | 2015-09-04 17:02:32 | [diff] [blame] | 13 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 14 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 16 | ## Faster Builds |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 17 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 18 | ### Components Build |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 19 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 20 | A non-standard build configuration is to use dynamic linking instead of static |
| 21 | linking for the various modules in the Chromium codebase. This results in |
| 22 | significantly faster link times, but is a divergence from what is shipped and |
| 23 | primarily tested. To enable the |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 24 | [component build](https://www.chromium.org/developers/how-tos/component-build): |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 25 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 26 | $ GYP_DEFINES="component=shared_library" gclient runhooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 27 | |
| 28 | or |
| 29 | |
| 30 | ``` |
| 31 | C:\...\src>set GYP_DEFINES=component=shared_library |
| 32 | C:\...\src>gclient runhooks |
| 33 | ``` |
| 34 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 35 | ### Windows: Debug Builds Link Faster |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 36 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 37 | On Windows if using the components build, building in debug mode will generally |
| 38 | link faster. This is because in debug mode, the linker works incrementally. In |
| 39 | release mode, a full link is performed each time. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 40 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 41 | ### Mac: Disable Release Mode Stripping |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 42 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 43 | On Mac, if building in release mode, one of the final build steps will be to |
| 44 | strip the build products and create dSYM files. This process can slow down your |
| 45 | incremental builds, but it can be disabled with the following define: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 46 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 47 | $ GYP_DEFINES="mac_strip_release=0" gclient runhooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 48 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 49 | ### Mac: DCHECKs in Release Mode |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 50 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 51 | DCHECKs are only designed to be run in debug builds. But building in release |
| 52 | mode on Mac is significantly faster. You can have your cake and eat it too by |
| 53 | building release mode with DCHECKs enabled using the following define: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 54 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 55 | $ GYP_DEFINES="dcheck_always_on=1" gclient runhooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 56 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 57 | ### Linux |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 58 | |
amoylan | a6db977a | 2016-12-08 02:07:54 | [diff] [blame] | 59 | The Linux build instructions page has its own section on [making the build |
| 60 | faster](linux_build_instructions.md#faster-builds). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 61 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 62 | ## Configuring the Build |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 63 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 64 | ### Environment Variables |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 65 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 66 | There are various environment variables that can be passed to the metabuild |
| 67 | system GYP when generating project files. This is a summary of them: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 68 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 69 | TODO(andybons): Convert to list. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 70 | |
sbc | 9f033f8 | 2015-11-26 00:50:52 | [diff] [blame] | 71 | |:-------------|:--------------------------------------------------------------| |
| 72 | | `GYP_DEFINES` | A set of key=value pairs separated by space that will set default values of variables used in .gyp and .gypi files | |
| 73 | | `GYP_GENERATORS` | The specific generator that creates build-system specific files | |
| 74 | | `GYP_GENERATOR_FLAGS` | Flags that are passed down to the tool that generates the build-system specific files | |
| 75 | | `GYP_GENERATOR_OUTPUT` | The directory that the top-level build output directory is relative to | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 76 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 77 | Note also that GYP uses CPPFLAGS, CFLAGS, and CXXFLAGS when generating ninja |
| 78 | files (the values at build time = ninja run time are _not_ used); see |
| 79 | [gyp/generator/ninja.py](https://code.google.com/p/chromium/codesearch#chromium/src/tools/gyp/pylib/gyp/generator/ninja.py&q=cxxflags). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 80 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 81 | ### Variable Files |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 82 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 83 | If you want to keep a set of variables established, there are a couple of magic |
| 84 | files that GYP reads: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 85 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 86 | #### chromium.gyp\_env |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 87 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 88 | Next to your top-level `/src/` directory, create a file called |
| 89 | `chromium.gyp_env`. This holds a JSON dictionary, with the keys being any of the |
| 90 | above environment variables. For the full list of supported keys, see |
| 91 | [/src/build/gyp_helper.py](/build/gyp_helper.py). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 92 | |
sbc | 9f033f8 | 2015-11-26 00:50:52 | [diff] [blame] | 93 | ``` |
| 94 | { |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 95 | 'variables': { |
| 96 | 'mac_strip_release': 0, |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 97 | }, 'GYP_DEFINES': |
| 98 | 'clang=1 ' 'component=shared_library ' 'dcheck_always_on=1 ' |
sbc | 9f033f8 | 2015-11-26 00:50:52 | [diff] [blame] | 99 | } |
| 100 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 101 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 102 | #### include.gyp |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 103 | |
| 104 | Or globally in your home directory, create a file `~/.gyp/include.gypi`. |
| 105 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 106 | #### supplement.gypi |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 107 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 108 | The build system will also include any files named `/src/*/supplement.gypi`, |
| 109 | which should be in the same format as include.gyp above. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 110 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 111 | ### Change the Build System |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 112 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 113 | Most platforms support multiple build systems (Windows: different Visual Studios |
| 114 | versions and ninja, Mac: Xcode and ninja, etc.). A sensible default is selected, |
| 115 | but it can be overridden: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 116 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 117 | $ GYP_GENERATORS=ninja gclient runhooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 118 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 119 | [Ninja](ninja_build.md) is generally the fastest way to build anything on any |
| 120 | platform. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 121 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 122 | ### Change Build Output Directory |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 123 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 124 | If you need to change a compile-time flag and do not want to touch your current |
| 125 | build output, you can re-run GYP and place output into a new directory, like so, |
| 126 | assuming you are using ninja: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 127 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 128 | ```shell |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 129 | $ GYP_GENERATOR_FLAGS="output_dir=out_other_ninja" gclient runhooks |
| 130 | $ ninja -C out_other_ninja/Release chrome |
| 131 | ``` |
| 132 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 133 | Alternatively, you can do the following, which should work with all GYP |
| 134 | generators, but the out directory is nested as `out_other/out/`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 135 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 136 | ```shell |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 137 | $ GYP_GENERATOR_OUTPUT="out_other" gclient runhooks |
| 138 | $ ninja -C out_other/out/Release chrome |
| 139 | ``` |
| 140 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 141 | **Note:** If you wish to run the WebKit layout tests, make sure you specify the |
| 142 | new directory using `--build-directory=out_other_ninja` (don't include the |
| 143 | `Release` part). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 144 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 145 | ### Building Google Chrome |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 146 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 147 | To build Chrome, you need to be a Google employee and have access to the |
| 148 | [src-internal](https://goto.google.com/src-internal) repository. Once your |
| 149 | checkout is set up, you can run gclient like so: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 150 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 151 | $ GYP_DEFINES="branding=Chrome buildtype=Official" gclient runhooks |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 152 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 153 | Then building the `chrome` target will produce the official build. This tip can |
| 154 | be used in conjunction with changing the output directory, since changing these |
| 155 | defines will rebuild the world. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 156 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 157 | Also note that some GYP\_DEFINES flags are incompatible with the official build. |
| 158 | If you get an error when you try to build, try removing all your flags and start |
| 159 | with just the above ones. |