Build Instructions (Windows) – The Chromium Projects

转自:http://121.199.54.6/wordpress/?p=1156

原始地址:http://www.chromium.org/developers/how-tos/build-instructions-windows#TOC-Building-Chromium

This page has detailed information on building Chromium on Windows, including tips for troubleshooting and for speeding up the build.

Build environment
Setting up the environment for Visual Studio 2013

You must have Windows 7 x64 or later.  x86 OSs are unsupported.

  1. .
  2. If you are a Googler, run: download_from_google_storage –config and follow the authentication instructions. You can just press Enter when asked for a "project-id". This makes downloads faster, and you’ll get the the Pro edition of the toolchain.
  3. Follow the steps to check out the code:  (largely "fetch chromium"). gclient runhooks that is run as part of the fetch will get or update the VS2013 toolchain as necessary.

If you’re primarily going to be doing debug dev builds, you’ll want to set GYP_DEFINES=component=shared_library, which uses a DLL build and incremental linking, which makes linking much faster in Debug.

No IDE is installed, however windbg is available in  depot_toolswin_toolchainvs2013_fileswin8sdkDebuggersx86.

Details:

The toolchain script does not modify the system environment in any way, so can be side-by-side installed with VS2013 or any older versions if desired.

The toolchain files are stored in depot_toolswin_toolchainvs2013_files . It is not expected that this toolchain is suitable for building anything other than Chromium and its tools. The contents of that directory are tracked by SHA1.

If you do a system install of VS2013, you can use it for editing and debugging. ninja will still use the depot_tools version to build. This is preferred as it’s automatically kept up-to-date as build requirements change. If you would like to use your own toolchain to build, you can disable this behavior by setting DEPOT_TOOLS_WIN_TOOLCHAIN=0 in the environment .  If you disable the default behavior, you’ll likely need to do some of the steps below in the VS2010 section, at least setting GYP_MSVS_VERSION=2013.

Setting up the environment for Visual Studio 2010

      • A 64 bit OS is recommended as building on 32 bit OS is constantly becoming harder, is a lot slower and is not actively maintained.
    • Visual Studio 2010 Professional or Standard.
    • .
    • .
    • (Optional) or  , to provide a more UNIX-like development environment. Msysgit is supported as part of depot_tools; cygwin is supported in a more ad-hoc manner.
  1. Visual Studio 2010
    1. Make sure "X64 Compilers and Tools" are installed
    2. .
  2. Install the .

    : If you install the SDK in a path different than C:Program Files (x86)Windows Kits8.0 you need to set the following following environment variable:
    GYP_DEFINES=windows_sdk_path="path to sdk"

  3. Install the 
    Note: If your install fails with the "Error Code: S1023" you may need to uninstall "Microsoft Visual C++ 2010 x64 Redistributable". See this tip from stackoverflow: 
    1. Parts of Chromium build using the winrt headers included with the Windows 8 SDK. All the headers we use, including the WRL, can be compiled with Visual C++ 2010 with the exception of one file, asyncinfo.h. This file uses a strongly typed enum which the VS2010 compiler doesn’t understand. To workaround this for the time being, a small patch needs to be applied to the Windows 8 SDK to build with the winrt headers in VS2010: Patch for Includewinrtasyncinfo.h : By default the Windows 8 SDK will install to C:Program Files (x86)Windows Kits8.0. This directory will require admin privileges to write to. Easiest way to do apply this patch is to , cd to  C:Program Files (x86)Windows Kits8.0Includewinrt\, run notepad.exe asyncinfo.h and comment out or delete the word "class" on line 66.

      : For Googlers, this patch has already been applied to your SDK, everything should Just Work.

  4. (Optional) Install the Git for Windows shell and/or Install cygwin.

Setting up the environment for building with Visual C++ 2010 Express or Windows 7.1 SDK

    • Windows 7 or later.
      • A 64 bit OS is highly recommended as building on 32 bit OS is constantly becoming harder, is a lot slower and is not actively maintained.
      • At least 60 GB of free space in an NTFS volume. Tip: having the chromium source in a SSD drive greatly speeds build times.
    • Both  and .
    • .
    • Windows Driver Kit 7.1.
    • (Optional) Visual Studio 2010 Express.
    • (Optional) Git for Windows (aka msysgit) or Cygwin , to provide a more UNIX-like development environment. Msysgit is supported as part of depot_tools; cygwin is supported in a more ad-hoc manner.
  1. Install Visual C++ 2010 Express and Windows 7.1 SDK. The installation order is important.
    1. (Optional) Install Visual C++ 2010 Express
    2.  Windows SDK 7.1. Make sure x64 compiler and tools are installed.
    3. (Optional, only if you use Visual C++ 2010 Express)  VS2010 SP1.
    4.  Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1.
    5. Create an empty "C:Program Files (x86)Microsoft Visual Studio 10.0VCincludeammintrin.h" file. The update installed on the previous step does not include this standard header for some reason. The header should declare AMD-specific SSE intrinsic functions that are not used by Chromium code. Run the following command as administrator to create the file:

      echo. > "C:Program Files (x86)Microsoft Visual Studio 10.0VCincludeammintrin.h"

  2. Install the Windows 8 SDK.

    : If you install the SDK in a path different than C:Program Files (x86)Windows Kits8.0 you need to set the following following environment variable:

    GYP_DEFINES=windows_sdk_path="path to sdk"

  3. Patch the Windows 8 SDK to build with Visual C++ 2010
    1. Parts of Chromium build using the winrt headers included with the Windows 8 SDK. All the headers we use, including the WRL, can be compiled with Visual C++ 2010 with the exception of one file, asyncinfo.h. This file uses a strongly typed enum which the VS2010 compiler doesn’t understand. To workaround this for the time being, a small patch needs to be applied to the Windows 8 SDK to build with the winrt headers in VS2010: Patch for Includewinrtasyncinfo.h

      Index: asyncinfo.h

      ===================================================================

      — asyncinfo.h

      +++ asyncinfo.h

      @@ -63,7 +63,7 @@

       #pragma once

       #ifdef __cplusplus

       namespace ABI { namespace Windows { namespace Foundation {

      -enum class AsyncStatus {

      +enum /*class*/ AsyncStatus {

         Started = 0,

         Completed, 

         Canceled, 

      This patch should be applied to the file "Includewinrtasyncinfo.h" located in your Windows 8 SDK directory. If this patch is not applied, the parts of Chromium that use the Winrt headers will not compile.

      : By default the Windows 8 SDK will install to C:Program Files (x86)Windows Kits8.0. This directory will require admin privileges to write to. Easiest way to do apply this patch is to  start an administrative command prompt, cd to  C:Program Files (x86)Windows Kits8.0Includewinrt\, run  notepad.exe asyncinfo.h  and comment out or delete the word "class" on line 66.

      Note: For Googlers, this patch has already been applied to your SDK, everything should Just Work.

  4. Install the June 2010 DirectX SDK
    Note: If your install fails with the "Error Code: S1023" you may need to uninstall "Microsoft Visual C++ 2010 x64 Redistributable". See this tip from stackoverflow: http://stackoverflow.com/questions/4102259/directx-sdk-june-2010-installation-problems-error-code-s1023
  5. Install Windows Driver Kit and create a system-wide environment variable named WDK_DIR via Run…->SystemPropertiesAdvanced->Environment Variables…->New…(in System variables), with the name of WDK_DIR and the location you installed the WDK (e.g. C:WinDDK7600.16385.1).
  6. Set the following environment variable:

    GYP_MSVS_VERSION=2010e

  7. (Optional) See Build Chromium with MSBuild below for instructions how to build from the command line, Ninja build works as well.

Automatic simplified toolchain setup

These instructions are deprecated. They are here only for reference if you want to build an old revision.

This method is an automated version of the one above. It installs the compiler, SDKs, and patches automatically, but does not install any IDE.

You can only build with ninja using these steps.

If you have Visual Studio installed, you can still use it to debug, but not to build.

    Prerequisite software:

    • Windows 7 x64 or later. An x86 OS is unsupported.
  1. .
  2. Run "gclient" once. This ensures you have python, git, and svn available.
  3. Follow the steps to check out the code, using either the Subversion instructions or the Git instructions,  but don’t "gclient sync" yet.
    1. Subversion: http://dev.chromium.org/developers/how-tos/get-the-code
    2. Git: https://code.google.com/p/chromium/wiki/UsingGit
  4. Run 
    • python src oolswin oolchain oolchain.py
    • This cannot be run inside cygwin due to permissions issue.
    • This will take 2-15 minutes depending on download speed, and creates a win_toolchain folder containing the tools and headers required to build Chromium.
  5. win_toolchainenv.bat
  6. cd src
  7. gclient sync
  8. ninja -C outDebug chrome

Building Chromium

  1. Get the Chromium depot_tools.
  2. Check out the source code using a direct svn or git checkout. Do not use a tarball since it is not compatible with Windows’ svn client.
  3. Install API keys.

Then use 
ninja to build:

ninja -C outDebug chrome

(ninja should come with the depot_tools), and run the result:

outDebugchrome.exe

Building in Visual Studio

    set GYP_GENERATORS=msvs-ninja,ninja

and then

        gclient runhooks

to build a wrapper Visual Studio solution that shells to the ninja build to accomplish the actual build. This solution can be useful for browsing.

Building (natively) in Visual Studio

You can attempt to build in Visual Studio. This configuration is untested and definitely does not work to build all of chrome. Some small sub-targets may work. This is also useful just for browsing if you prefer Visual Studio, but generally building does not work.

  1. Set the GYP generator in your environment (otherwise, it will make ninja files instead of .sln). From the command-prompt:

        set GYP_GENERATORS=msvs

  2. Set up the component build (or else creating chrome_dll.pdb may fail laterl):

        set GYP_DEFINES=component=shared_library

  3. Regenerate the build files by running:

        gclient runhooks –force

  4. Open the chrome/chrome.sln solution file in Visual Studio and build the solution. This can take from 10 minutes to 2 hours. More likely 1 hour.
  5. If you just want the Chromium browser, and none of the tests, you can speed up your build by right-clicking the chrome project in the solution explorer and selecting Build. You may want to make sure this project is the Startup project (which will display as bold) by right-clicking it and selecting Set as Startup Project. This will make Chromium (as opposed to some random test) build and run when you press F5.

Accelerating the build

Be prepared: the build of whole solution can take hour(s) longer if not configured correctly.

In decreasing order of speedup:

  • Use a true multicore processor, i.e. an Intel Core Duo or later (not a Pentium 4 HT).
  • Have at least 8 GB RAM.  If you have less than 4 GB, you may find builds to be prohibitively slow.
  • Disable your anti-virus software for .ilk, .pdb, .cc, .h files and only check for viruses on modify. Disable scanning the directory where your sources reside.
  • Store and build the Chromium code on an SSD.
  • Store and build the Chromium code on a second hard drive that does not have swap (Control Panel->System and Security->System->Advanced->Performance/Settings->Advanced->Virtual memory/Change). Compilation and linking use a lot of memory and disk I/O.  It’s not a good idea to have the I/O happening on the same disk that the memory manager is using for swap.
  • Defragment your hard drive regularly.


Official/WPO/LTCG build:
To enable whole program optimization / link-time code generation, make sure to set the environment variable:

  1. set GYP_DEFINES=branding=Chromium buildtype=Official
    1. If you have the internal checkout, use Chrome instead of Chromium to get the Google Chrome resources.
  2. gclient runhooks
  3. ninja -C outRelease chrome

The WPO configuration settings are defined in
release_impl_official.gypi.
Unit tests Some unit tests (such as gfx_unittests) require at least Vista/2008 with
Platform Update installed or Windows 7 to execute all of the tests completely.
Other tricks
Blog post on setting a right-hand print margin
Running Chromium

The chrome.exe executable can be found at src/out/Debug/chrome.exe or src/out/Release/chrome.exe, depending on the selected build configuration.

Because of Chromium’s unique architecture, there are a number of special challenges associated with development. See Debugging Chromium for more information.

Once you’re comfortable with building Chromium, read the Contributing Code page for information about writing code for Chromium and contributing it.

Packaging If you want to package your build into a zip file, do the following:

cd /path/to/src
./chrome/tools/build/win/make_zip.sh build/Release my-chromium

This will create my-chromium.zip . You can change Release to Debug if you want to zip up the debug build instead.

Installing a built version of Chromium

To install a built version of Chromium, build ‘setup’ and ‘mini_installer’ then run ‘setup.exe':

ninja -C out/Release chrome setup mini_installer

outReleasesetup.exe –chrome –multi-install

Running in Windows 8 mode

In order to switch to Windows 8 mode (‘Relaunch Chrome in Windows 8 mode’ from the Browser menu), you need to have your build version of Chromium installed as described above.

Troubleshooting
Build failures on Vista If you build on Vista, watch out for security issues. Make sure that the folder where you checked out your files is writable for users and not only for admins.
Compilation failures

These are probably only relevant for previous-to-VS2013 toolchains and builds.

Some common things to think about when you have weird compilation failures:

  1. If you happen to have checked out the source code before installing the build prerequisites (Visual Studio, the SDK, and all the patches), you’ll need to re-generate the VS solution files by quitting Visual Studio and then running "gclient runhooks".
  2. Sometimes Visual Studio does the wrong thing when building Chromium and gets stuck on a bogus error. A good indication of this is if it is only failing for one person but others (including the Buildbots) are not complaining. To resolve this, try the following steps:
    1. Close Visual Studio.
    2. Sync to the tip of tree and ensure there are no conflicts ("svn status" should not show any "C"s in front of files that you’ve changed). 
    3. If there were conflicts, sync again after resolving them. 
    4. Manually erase the output directory (chromeDebug and chromeRelease. Using the command line, you can use "erase /S /Q Debug Release" from the chrome directory to do this, or "rm -rf Debug Release" if you have Unix-like tools installed. 
    5. Restart Visual Studio and open the Chromium solution. 
    6. Rebuild the solution.
  3. If you get errors like these:
    * C:Program FilesMicrosoft SDKsWindowsv6.1Includeunknwn.idl(108) : error MIDL2025 : syntax error : expecting ] or , near "annotation"
    * browserdownloaddownload_util.cc(469) : error C2065: ‘ITaskbarList3′ : undeclared identifier
    You either have the wrong Platform SDK or it is incorrectly registered. Try installing the Windows 7 SDK or, if already installed, try registering the SDK manually.
  4. If you get errors like this:
    * error C2039: ‘_Swap_adl’ : is not a member of ‘std’
    Then you’ve likely run into a conflict between the Windows SDK and a security patch.  See this MSDN blog post for more details try reinstalling Visual Studio SP1.
  5. If you get errors like this:

    3>c:program files (x86)microsoft directx sdk (june 2010)included3d11shader.h(35) : error C2146: syntax error : missing ‘;’ before identifier ‘D3D11_RESOURCE_RETURN_TYPE’

    3>c:program files (x86)microsoft directx sdk (june 2010)included3d11shader.h(35) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int

    3>c:program files (x86)microsoft directx sdk (june 2010)included3d11shader.h(37) : error C2146: syntax error : missing ‘;’ before identifier ‘D3D11_CBUFFER_TYPE’

    Then make sure the DirectX headers appear first in the include search path (MSVC|Tools|Options|Projects and Solutions|VC++ Directories). After making the change the retrying the build without clobber should work.

If it still doesn’t work, repeating this process probably won’t help.
Cygwin access control issues

If, while building JavaScriptCore, you see errors like:

3>Error in tempfile() using /tmp/dftables-XXXXXXXX.in: Parent directory (/tmp/) is not writable
3> at /cygdrive/c/b/slave/WEBKIT~1/build/webkit/third_party/JavaScriptCore/pcre/dftables line 236
3>make: *** [chartables.c] Error 255

…it’s because the Cygwin installation included in the Chromium source is having trouble mapping the NT ACL to POSIX permissions. This seems to happen when Chromium is checked out into a directory for which Cygwin can’t figure out the permissions in the first place, possibly when the directory is created from within a Cygwin environment before running mkpasswd. Cygwin then imposes its own access control, which is incorrectly restrictive. As a workaround, do one of the following:

  • Edit the NT permissions on third_partycygwin mp to allow Modify and Write actions for Everyone and machineUsers. Cygwin is able to figure this out. Or,
  • Figure out what went wrong with your checkout and try again – try doing the checkout from cmd instead of from a Cygwin shell, then verify that the permissions aren’t completely blank in your Cygwin installation. Or,
  • Bypass Cygwin’s access control (NT’s will still be in effect) by editing webkituildJavaScriptCoreprebuild.bat and webkituildWebCoreprebuild.bat to include the following line before invoking anything that uses Cygwin:

    Note: the nontsec option is not supported in cygwin 1.7 and greater.

  • Edit the cygwin file /etc/fstab and add the noacl option

    none /cygdrive cygdrive binary,posix=0,user,noacl 0 0

Only one of these solutions should be needed.

Native Client Doesn’t Run

If you get this error when building chrome_nacl_win64:

LINK : fatal error LNK1104: cannot open file ‘atlsd.lib’

It means that you didn’t install the 64-bit compiler and tools as described at the top of the page.

First run of gclient fails to install python
If the first run of gclient produces the error:
svn: Can’t move ‘C:Usersusernamedepot_toolspython_bin clTix8.4.3.svn mpentries’ to ‘C:Users hashimotodepot_toolspython_bin clTix8.4.3.svnentries': The file or directory is corrupted and unreadable.
… Failed to checkout python automatically.
Please visit http://python.org to download the latest python 2.x client before continuing.
You can also get the "prebacked" version used at http://src.chromium.org/chrome/trunk/tools/third_party/
See
this link for instructions on turning off Windows Indexing.
Manually registering the Platform SDK

    1. GYP picks up the proper version SDK automatically according to the ‘msbuild_toolset’ variable set in %USERPROFILE%.gypinclude.gypi.
      1. If the variable is not set 7.0A SDK (also known as ‘v100′) is used. (I.e. the one that is included with Visual Studio).
      2. Windows 7.1 SDK is selected by setting the variable to ‘Windows7.1SDK’.    
原文地址:https://www.cnblogs.com/x_wukong/p/5445346.html