Saturday, March 3, 2012

Build Chromium in Windows using Visual Studio 2010

This is the second post in a series of "Browser development" articles. In this one, I will outline the basic steps necessary to get a working build of the open source Chromium browser (known as Google Chrome) on Windows. For details about building and debugging Firefox, head over to Debugging Firefox in Windows with VS2010.

First, you will need the prerequisites. Chromium will require a hefty amount of "juice" from your hardware. The minimum required RAM is 8GB, but more is better. Here are a few "build environment" recommendations:

1. Get a "true" multicore PC, such as one having an Intel "Core" series processor (i7 would be great :))

2. Have at least 8GB RAM. I've seen people talking about still needing more, as much as 16GB!

3. Better if you build on a separate HDD than your Windows installation. YES, THAT MEANS ON A DIFFERENT PHYSICAL DISK, NOT A DIFFERENT PARTITION.

4. Disable your Anti-virus, or at least, pause it.

Now on to the actual build process. We start by downloading a few stuff that are mandatory:

1. Like Mozilla's MozillaBuild, Chrome developers have also made a custom set of tools that basically does the pre-build processing of the source tree. So you need to download the depot_tools.
2. Download and install VS2010SP1.
3. Download and install Windows7.1SDK.
4. Download and install the DirectX SDK.

Assuming that the above steps went smoothly, lets move on to the real deal. We will be building Chromium from a tarball download, rather than an SVN checkout.

1. Download the latest Chromium tarball from here: Chromium Source tarball.

2. Extract the source using a zip utility, such as 7-zip to a folder of your choice (e.g., C:\chromium). CAUTION: you need ample free space, the extraction takes about 4.5 GB.

3. Assuming you have extracted the depot_tools downloaded earlier to: C:\depot_tools, set the PATH environment variable of Windows (Start Menu>Computer>Properties>Advanced System Settings>Advanced>Environment Variables>System Variables>PATH>Edit). Append this line to the end of your path: "C:\depot_tools\". You may need to restart your computer for updating the PATH.

4. Open command prompt. Type echo %USERPROFILE%. Head over to the folder and create a .gyp folder there (note the beginning dot). Windows will not let you build a folder with a beginning dot. So, from command prompt, cd to the %USERPROFILE% folder and type: mkdir .gyp. In the .gyp folder, create a blank text file and name it include.gypi.

5. Paste these following lines to include.gypi:
{
'variables': {
'msbuild_toolset': 'Windows7.1SDK',
'chromium_win_pch': 1,
'component': 'shared_library',
},
}

6. In command prompt, type: echo %LOCALAPPDATA%. Head over to the folder. You will see two files: Microsoft.Cpp.Win32.user.props and Microsoft.Cpp.x64.user.props. Open notepad (or any text editor) in "administrator mode". Then edit these two files by appending these lines in the <Project> node :
<PropertyGroup> $(DXSDK_DIR)\include;$(IncludePath) $(DXSDK_DIR)\lib\x86;$(LibraryPath)
</PropertyGroup>

7. From the command prompt, go to the Chromium source directory where you extracted the source files. cd to the src directory (e.g., ~\chromium\src). Run the following commands:

a) set GYP_MSVS_VERSION=2010
b) gclient sync --force
c) gclient runhooks --force

You should now have a chrome.sln (visual studio solution file) in the chrome\ folder of the source tree.

1. Open the sln file in VS2010.

2. IMPORTANT: set the maximum number of parallel builds (tools>options>projects and solutions>build and run>maximum number of parallel builds) to this value NUMBER_OF_CORES_OF_YOUR_PROCESSOR-1 (this is not a hard rule, btw). This is supposed to speed up the build process.

3. Build Chromium from VS2010. Build times will vary, but will mostly be anything from 30 mins (really fast PC) to 2.5hrs.

4. Test/debug your build from VS2010.