blob: c042169fc98f5f143178b687158454ee9c048017 [file] [log] [blame] [view]
andybons22afb312015-08-31 02:24:511# Common Build Tasks
andybons3322f762015-08-24 21:37:092
andybons22afb312015-08-31 02:24:513The Chromium build system is a complicated beast of a system, and it is not very
4well documented beyond the basics of getting the source and building the
5Chromium product. This page has more advanced information about the build
6system.
andybons3322f762015-08-24 21:37:097
andybons22afb312015-08-31 02:24:518If you're new to Chromium development, read the
tfarina5f2d8e2f2016-03-04 09:57:339[getting started guides](https://www.chromium.org/developers/how-tos/get-the-code).
andybons3322f762015-08-24 21:37:0910
andybons8c02a1f2015-09-04 17:02:3211There is some additional documentation on
xiaoyin.l1003c0b2016-12-06 02:51:1712[setting GYP build parameters](https://dev.chromium.org/developers/gyp-environment-variables).
andybons8c02a1f2015-09-04 17:02:3213
andybons22afb312015-08-31 02:24:5114[TOC]
andybons3322f762015-08-24 21:37:0915
andybons22afb312015-08-31 02:24:5116## Faster Builds
andybons3322f762015-08-24 21:37:0917
andybons22afb312015-08-31 02:24:5118### Components Build
andybons3322f762015-08-24 21:37:0919
andybons22afb312015-08-31 02:24:5120A non-standard build configuration is to use dynamic linking instead of static
21linking for the various modules in the Chromium codebase. This results in
22significantly faster link times, but is a divergence from what is shipped and
23primarily tested. To enable the
xiaoyin.l1003c0b2016-12-06 02:51:1724[component build](https://www.chromium.org/developers/how-tos/component-build):
andybons3322f762015-08-24 21:37:0925
andybons22afb312015-08-31 02:24:5126 $ GYP_DEFINES="component=shared_library" gclient runhooks
andybons3322f762015-08-24 21:37:0927
28or
29
30```
31C:\...\src>set GYP_DEFINES=component=shared_library
32C:\...\src>gclient runhooks
33```
34
andybons22afb312015-08-31 02:24:5135### Windows: Debug Builds Link Faster
andybons3322f762015-08-24 21:37:0936
andybons22afb312015-08-31 02:24:5137On Windows if using the components build, building in debug mode will generally
38link faster. This is because in debug mode, the linker works incrementally. In
39release mode, a full link is performed each time.
andybons3322f762015-08-24 21:37:0940
andybons22afb312015-08-31 02:24:5141### Mac: Disable Release Mode Stripping
andybons3322f762015-08-24 21:37:0942
andybons22afb312015-08-31 02:24:5143On Mac, if building in release mode, one of the final build steps will be to
44strip the build products and create dSYM files. This process can slow down your
45incremental builds, but it can be disabled with the following define:
andybons3322f762015-08-24 21:37:0946
andybons22afb312015-08-31 02:24:5147 $ GYP_DEFINES="mac_strip_release=0" gclient runhooks
andybons3322f762015-08-24 21:37:0948
andybons22afb312015-08-31 02:24:5149### Mac: DCHECKs in Release Mode
andybons3322f762015-08-24 21:37:0950
andybons22afb312015-08-31 02:24:5151DCHECKs are only designed to be run in debug builds. But building in release
52mode on Mac is significantly faster. You can have your cake and eat it too by
53building release mode with DCHECKs enabled using the following define:
andybons3322f762015-08-24 21:37:0954
andybons22afb312015-08-31 02:24:5155 $ GYP_DEFINES="dcheck_always_on=1" gclient runhooks
andybons3322f762015-08-24 21:37:0956
andybons22afb312015-08-31 02:24:5157### Linux
andybons3322f762015-08-24 21:37:0958
amoylana6db977a2016-12-08 02:07:5459The Linux build instructions page has its own section on [making the build
60faster](linux_build_instructions.md#faster-builds).
andybons3322f762015-08-24 21:37:0961
andybons22afb312015-08-31 02:24:5162## Configuring the Build
andybons3322f762015-08-24 21:37:0963
andybons22afb312015-08-31 02:24:5164### Environment Variables
andybons3322f762015-08-24 21:37:0965
andybons22afb312015-08-31 02:24:5166There are various environment variables that can be passed to the metabuild
67system GYP when generating project files. This is a summary of them:
andybons3322f762015-08-24 21:37:0968
andybons22afb312015-08-31 02:24:5169TODO(andybons): Convert to list.
andybons3322f762015-08-24 21:37:0970
sbc9f033f82015-11-26 00:50:5271|:-------------|:--------------------------------------------------------------|
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 |
andybons3322f762015-08-24 21:37:0976
andybons22afb312015-08-31 02:24:5177Note also that GYP uses CPPFLAGS, CFLAGS, and CXXFLAGS when generating ninja
78files (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).
andybons3322f762015-08-24 21:37:0980
andybons22afb312015-08-31 02:24:5181### Variable Files
andybons3322f762015-08-24 21:37:0982
andybons22afb312015-08-31 02:24:5183If you want to keep a set of variables established, there are a couple of magic
84files that GYP reads:
andybons3322f762015-08-24 21:37:0985
andybons22afb312015-08-31 02:24:5186#### chromium.gyp\_env
andybons3322f762015-08-24 21:37:0987
andybons22afb312015-08-31 02:24:5188Next 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
90above environment variables. For the full list of supported keys, see
91[/src/build/gyp_helper.py](/build/gyp_helper.py).
andybons3322f762015-08-24 21:37:0992
sbc9f033f82015-11-26 00:50:5293```
94{
andybons3322f762015-08-24 21:37:0995 'variables': {
96 'mac_strip_release': 0,
andybons22afb312015-08-31 02:24:5197 }, 'GYP_DEFINES':
98 'clang=1 ' 'component=shared_library ' 'dcheck_always_on=1 '
sbc9f033f82015-11-26 00:50:5299}
100```
andybons3322f762015-08-24 21:37:09101
andybons22afb312015-08-31 02:24:51102#### include.gyp
andybons3322f762015-08-24 21:37:09103
104Or globally in your home directory, create a file `~/.gyp/include.gypi`.
105
andybons22afb312015-08-31 02:24:51106#### supplement.gypi
andybons3322f762015-08-24 21:37:09107
andybons22afb312015-08-31 02:24:51108The build system will also include any files named `/src/*/supplement.gypi`,
109which should be in the same format as include.gyp above.
andybons3322f762015-08-24 21:37:09110
andybons22afb312015-08-31 02:24:51111### Change the Build System
andybons3322f762015-08-24 21:37:09112
andybons22afb312015-08-31 02:24:51113Most platforms support multiple build systems (Windows: different Visual Studios
114versions and ninja, Mac: Xcode and ninja, etc.). A sensible default is selected,
115but it can be overridden:
andybons3322f762015-08-24 21:37:09116
andybons22afb312015-08-31 02:24:51117 $ GYP_GENERATORS=ninja gclient runhooks
andybons3322f762015-08-24 21:37:09118
andybons22afb312015-08-31 02:24:51119[Ninja](ninja_build.md) is generally the fastest way to build anything on any
120platform.
andybons3322f762015-08-24 21:37:09121
andybons22afb312015-08-31 02:24:51122### Change Build Output Directory
andybons3322f762015-08-24 21:37:09123
andybons22afb312015-08-31 02:24:51124If you need to change a compile-time flag and do not want to touch your current
125build output, you can re-run GYP and place output into a new directory, like so,
126assuming you are using ninja:
andybons3322f762015-08-24 21:37:09127
andybons22afb312015-08-31 02:24:51128```shell
andybons3322f762015-08-24 21:37:09129$ GYP_GENERATOR_FLAGS="output_dir=out_other_ninja" gclient runhooks
130$ ninja -C out_other_ninja/Release chrome
131```
132
andybons22afb312015-08-31 02:24:51133Alternatively, you can do the following, which should work with all GYP
134generators, but the out directory is nested as `out_other/out/`.
andybons3322f762015-08-24 21:37:09135
andybons22afb312015-08-31 02:24:51136```shell
andybons3322f762015-08-24 21:37:09137$ GYP_GENERATOR_OUTPUT="out_other" gclient runhooks
138$ ninja -C out_other/out/Release chrome
139```
140
andybons22afb312015-08-31 02:24:51141**Note:** If you wish to run the WebKit layout tests, make sure you specify the
142new directory using `--build-directory=out_other_ninja` (don't include the
143`Release` part).
andybons3322f762015-08-24 21:37:09144
andybons22afb312015-08-31 02:24:51145### Building Google Chrome
andybons3322f762015-08-24 21:37:09146
andybons22afb312015-08-31 02:24:51147To 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
149checkout is set up, you can run gclient like so:
andybons3322f762015-08-24 21:37:09150
andybons22afb312015-08-31 02:24:51151 $ GYP_DEFINES="branding=Chrome buildtype=Official" gclient runhooks
andybons3322f762015-08-24 21:37:09152
andybons22afb312015-08-31 02:24:51153Then building the `chrome` target will produce the official build. This tip can
154be used in conjunction with changing the output directory, since changing these
155defines will rebuild the world.
andybons3322f762015-08-24 21:37:09156
andybons22afb312015-08-31 02:24:51157Also note that some GYP\_DEFINES flags are incompatible with the official build.
158If you get an error when you try to build, try removing all your flags and start
159with just the above ones.