Build Instructions (Windows)

来源:互联网 发布:尼采知乎 编辑:程序博客网 时间:2024/06/07 08:33

Build environment

Setting up the environment for Visual Studio 2010

  1. Prerequisite software:
    • 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.
    • Visual Studio 2010 Professional or Standard.
    • Windows 8 SDK.
    • June 2010 DirectX SDK.
    • (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.

  2. Install Visual Studio 2010
    1. Make sure "X64 Compilers and Tools" are installed.
    2. Install VS2010 SP1.

  3. Install the Windows 8 SDK.

    Note: If you install the SDK in a path different than C:\Program Files (x86)\Windows Kits\8.0 you need to set the following following environment variable:

    GYP_DEFINES=windows_sdk_path="path to sdk"

  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. 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 Include\winrt\asyncinfo.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 "Include\winrt\asyncinfo.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.

      Note: By default the Windows 8 SDK will install to C:\Program Files (x86)\Windows Kits\8.0\. This directory will require admin privileges to write to. Easiest way to do apply this patch is tostart an administrative command prompt, cd to C:\Program Files (x86)\Windows Kits\8.0\Include\winrt\, 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.

  6. (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

    1. Prerequisite software:
      • 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 Windows SDK 7.1 and Windows 8 SDK.
      • June 2010 DirectX SDK.
      • 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.

    2. Install Visual C++ 2010 Express and Windows 7.1 SDK. The installation order is important.
      1. (Optional) Install Visual C++ 2010 Express
      2. Install Windows SDK 7.1. Make sure x64 compiler and tools are installed.
      3. (Optional, only if you use Visual C++ 2010 Express) Install VS2010 SP1.
      4. Install Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1.
      5. Create an empty "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ammintrin.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.0\VC\include\ammintrin.h"

    3. Install the Windows 8 SDK.

      Note: If you install the SDK in a path different than C:\Program Files (x86)\Windows Kits\8.0 you need to set the following following environment variable:

      GYP_DEFINES=windows_sdk_path="path to sdk"

    4. 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 Include\winrt\asyncinfo.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 "Include\winrt\asyncinfo.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.

        Note: By default the Windows 8 SDK will install to C:\Program Files (x86)\Windows Kits\8.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 Kits\8.0\Include\winrt\, 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.

    5. 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

    6. 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:\WinDDK\7600.16385.1).

    7. Set the following environment variable:

      GYP_MSVS_VERSION=2010e

    8. (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

    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. Get the Chromium depot_tools.
    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\tools\win\toolchain\toolchain.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_toolchain\env.bat
    6. cd src
    7. gclient sync
    8. ninja -C out\Debug chrome
    See http://crrev.com/175004 for more details.

        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 out\Debug chrome

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

        out\Debug\chrome.exe

        Building in Visual Studio

        You can use:

            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).
        • Use an x64 OS (otherwise incremental linking is disabled).
        • Have at least 8 GB RAM.  If you have less than 4 GB, you may find builds to be prohibitively slow.
        • Turn on precompiled headers and the component build.
        • Use src/build/some.gyp to only load the targets you care about.
        • 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 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.
        • Consider using ninja -- it's an alternative command-line build tool that's much faster than Visual Studio, especially for incremental builds.
        • Reduce the number of parallel builds: avoid memory swap at any cost!. Chromium requires a lot of memory to link; if you build too many sub-projects simultaneously your PC will slow to a crawl during the linking phase because of the linkers fighting for memory. Go into MSVC's Tools\Options\Projects and Solutions\Build and Run and reduce "maximum number of parallel project builds". By default it is equal to the number of virtual processors (e.g. 8 for a quad core HT CPU). Recommended number for 12 GB of RAM is lower than 8 (see discussions here).  Use an even smaller number if you have less RAM.
        • You may also want to tune your include.gypi file to limit the number of cl.exe processes spawned and reduce context switches (see discussions here).  For example, to limit to only 5 cl.exe and 5 linkers, the include.gypi under your home folder's .gyp should have

          {
            'variables': {
              'msvs_multi_core_compile': 0,
            },
            'target_defaults': {
              'msvs_settings': {
                'VCCLCompilerTool': {
                  'AdditionalOptions': ['/MP5'],
                },
              },
            },
          }

        • Defragment your hard drive regularly.
        • You may want to try incremental linking if you're adventurous or using ninja. It makes linking very fast when you're working incrementally, but is somewhat flaky in Visual Studio, and you may need to do cleans after syncs to avoid spurious errors.


        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 out\Release 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

        See the Visual Studio Macros page and debugging pages.
        Blog post on setting a right-hand print margin

        Running Chromium

        The chrome.exe executable can be found at src/build/Debug/chrome.exe or src/build/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.

        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

        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 (chrome\Debug and chrome\Release. 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 Files\Microsoft SDKs\Windows\v6.1\Include\unknwn.idl(108) : error MIDL2025 : syntax error : expecting ] or , near "annotation"
          * browser\download\download_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)\include\d3d11shader.h(35) : error C2146: syntax error : missing ';' before identifier 'D3D11_RESOURCE_RETURN_TYPE'

          3>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d11shader.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)\include\d3d11shader.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)\include\d3d11shader.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_party\cygwin\tmp to allow Modify and Write actions for Everyone and machine\Users. 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 webkit\build\JavaScriptCore\prebuild.bat and webkit\build\WebCore\prebuild.bat to include the following line before invoking anything that uses Cygwin: 

          set CYGWIN=nontsec

          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:\Users\username\depot_tools\python_bin\tcl\Tix8.4.3\.svn\tmp\entries' to 'C:\Users\rhashimoto\depot_tools\python_bin\tcl\Tix8.4.3\.svn\entries': 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%\.gyp\include.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'.    
        0 0
        原创粉丝点击