Build chromium(Windows)

来源:互联网 发布:jsp精品课程网站源码 编辑:程序博客网 时间:2024/06/05 11:15
 转一篇官网上的文章 用于备忘

https://sites.google.com/a/chromium.org/dev/developers/how-tos/build-instructions-windows

Build Instructions (Windows)

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

目录

  1. 1 Build environment
    1. 1.1 Prerequisite software
      1. 1.1.1 Additional (free) downloads
  2. 2 Building Chromium
    1. 2.1 Accelerating the build
    2. 2.2 Optional
      1. 2.2.1 Rebuild / Clean
      2. 2.2.2Build Chromium with Command Line
      3. 2.2.3 Official/WPO/LTCG build
      4. 2.2.4 Unit tests
      5. 2.2.5 Other tricks
  3. 3 Running Chromium
    1. 3.1 Packaging
  4. 4 Troubleshooting
    1. 4.1 Build failures on Vista
    2. 4.2 Compilation failures
    3. 4.3 Cygwin access control issues
    4. 4.4Manually registering the Platform SDK
      1. 4.4.1     VS2008
      2. 4.4.2     VS2010
    5. 4.5Reinstalling Visual Studio SP1 (VS2008)
    6. 4.6Special Service Pack Preparation Tool for Visual Studio 2008
    7. 4.7 Native Client Doesn't Run
    8. 4.8NTFS recommended for building Native Client for Chrome
    9. 4.9Installing VisualStudio 2010 SP1 after Windows SDK 7.1
    10. 4.10Installing Windows SDK 7.1 into non-default folder

Build environment

Prerequisite software

  • Windows XP SP3 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.
  • Visual Studio Express, Standard, or Pro 2008 or 2010.
    • If you don't own a copy of Visual Studio, you can (freely) download Visual Studio 2008 Express w/SP1
    • For non-Express versions:
      • Make sure that "X64 Compilers and Tools" are installed as part of Visual Studio -Important! If you don't install this now, you won't be able to correct your installation later without uninstalling due to a bug in VS2008 SP1.
      • For VS 20088, if you're using the Standard Edition, make sure to also install C# development. Otherwise cl.exe won't be copied. SeeKB969866.
    • For Express versions, keep in mind that debugging is extremely limited.

Additional (free) downloads

    1. Visual Studio 2008
      1. Install VS2008 SP1 (unless you already have SP1, e.g. because you downloaded VS2008 Express w/SP1 via the link above).
      2. Install KB967631,KB960075, and KB957912.
      3. Install the Windows 7.1 SDK
        1. Read the instructions on the SDK download page! Read it again!
        2. You might need to reboot. You can save space by not installing the documentation and code samples.
        3. Integrate the SDK with Visual Studio
          1. Start > All Programs > Microsoft Windows SDK > Visual Studio Registration > Windows SDK Configuration Tool.
            If this program crashes, try running it from the command line with: windowssdkver -version:v7 -legacy
          2. If build still fails, try registering the SDK manually.
          3. If you had a previous version of the SDK installed before installing v7.0, verify that your VC++ directories are set to use v7.0 and not an earlier SDK.  See registering the SDK manually for details.
        4. If you are not using Visual Studio 2008 Express, install KB971092. Yes, that's a 365 MB update. :/
        5. If you are using Visual Studio 2008 Team System and plan to use the profiler, installKB958842.

        6. Visual Studio 2010 / Visual C++ 2010 Express
          1. Install VS2010 SP1.
          2. Install the Windows 7.1 SDK.
          3. You may need this repair to restore the libraries if the SDK was already installed when you installed SP1.
          4. As of 2011-04-01, VS2010 is not detected automatically by GYP, so to generate the .sln/.vcxproj, you need to
            1. set/export GYP_MSVS_VERSION=2010 (or create new Windows environment variable)
              • Note: 2010e for express versions.
            2. gclient runhooks
          5. Note: As of 2011-07-12 you may see some warnings from GYP about missing files from JavaScriptCore.gyp. You can ignore these.
          6. You may want to double-check that VisualStudio 2010 is using the right SDK by renaming Include and Lib in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A when trying to build. If your compile fails after this (likely complaining of missing includes), see the Troubleshooting section on manually installing the SDK.

        7. Install the DirectX SDK
          • Visual Studio 2008:
            • Open Tools > Options > Projects and Solutions > VC++ Directories.
            • Under "Include files" add $(DXSDK_DIR)include to the start of the list.
            • Under "Library files" add $(DXSDK_DIR)lib\x86 to the start of the list.
          • Visual Studio 2010:
            1. Go to View > Property Manager (can take a while to load).
            2. Expand any projects' property sheet (i.e. chrome) and expand either Debug or Release.
            3. Right click on "Microsoft.Cpp.Win32.user" (this is your user configuration) and go to "Properties"
            4. Under "VC++ Directories", "Include Directories" insert $(DXSDK_DIR)\include; to the beginning of the include list
            5. Under "VC++ Directories", "Library Directories" insert $(DXSDK_DIR)\lib\x86; to the beginning of the library list.
          • Make sure the DirectX include and lib directories appear first in the search path, otherwise you may get build errors.

        8. If you use Visual Studio 2008 Express:
          1. Install the WDK for the ATL headers and libs.
            1. Verify MSVC|Tools|Options|Projects and Solutions|VC++ Directories has Include: [WDK]include\atl71 and Lib: [WDK]lib\Atl\i386 where [WDK] is the WDK install directory.
          2. To build x64 targets (e.g. x64 Native Client) on Visual Studio 2008 Express:
            1. Download http://www.cppblog.com/Files/xcpp/VCE64BIT_WIN7SDK.zip, unzip, and follow the README instructions.
            2. For further information on that and x64 target building with Visual Studio 2008 Express (if you care), see http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/ and http://www.cppblog.com/xcpp/archive/2009/09/09/vc2008express_64bit_win7sdk.html.

        9. If you're using Visual C++ 2010 Express:
          • Install the WDK for the ATL/MFC headers and libs (else you will get "Missing library atlthunk.lib" and "Missing header altbase.h" errors).
            1. After you've done this, 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).
            2. Restart Visual C++ 2010 Express or the command line environment (if they're open, otherwise they won't have this environment variable set).
            3. Open chrome.sln, go to View->Property Manager from top menu, wait for this pane to load.
            4. Expand chrome->Debug and right click "Microsoft.Cpp.Win32.user" and click "Properties".
            5. Under "VC++ Directories" add
              • $(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42; to the include list and
              • $(WDK_DIR)\lib\ATL\i386; to the library list.
            6. If you want to build nacl, do the same for 64-bit. Expand chrome_nacl_win64->Debug | x64, right click "Microsoft.Cpp.x64.user" and click "Properties".
            7. Under "VC++ Directories" add
              • $(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42; to the include list and
              • $(WDK_DIR)\lib\ATL\amd64; to the library list.
        10. (Optional) Install cygwin.

          Building Chromium

          1. Get the Chromium depot_tools.
          2. Check out the source code using either the bootstrap tarball or a direct svn checkout.
          3. 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.
          4. If you just want the Chromium browser, and none of the tests, you can speed up your build by right-clicking thechrome project in the solution explorer and selectingBuild. You may want to make sure this project is the Startup project (which will display as bold) by right-clicking it and selectingSet as Startup Project. This will make Chromium (as opposed to some random test) build and run when you pressF5.

          Accelerating the build

          Be prepared: the build of whole solution can take hour(s) longer on a power horse 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. You may want to use some.gyp.
          • 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). During compilation and linking there are a lot of memory been used and disk I/O happening.  It's not a good idea to have all I/Os staying in the way on the same disk that memory manager doing its swap.
          • Reduce number of parallel builds. The Chromium requires a lot of memory to link; if you build to many sub-projects simultaneously your PC will slow to crawl during the linking phase because of the linkers fighting for the swap. 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 number of virtual processors (e. g. it will be 16 on the two I7s because of the hyper-threading). Recommended number for 12 GB of RAM is lower than 8 (see discussions here).  Reduce more for less RAM.
          • You may also want to tune your include.gypi file to limit number of cl.exe spawned and reduce context switches (see discussions here).  For example, to limit 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. It makes linking very fast when you're working incrementally, but is somewhat flaky, and you may need to do cleans after syncs to avoid spurious errors.

          Optional

          Rebuild / Clean

          You can use Rebuild and Clean on individual projects to rebuild them. However, because of the large number of files generated by the build system, avoid using Rebuild Allor Clean All - these do not erase everything! Instead delete the entire output directory (chrome\Debug or chrome\Release).

          Build Chromium with Command Line

          You would need to have Visual Studio installed, but not running. Navigate to source directory (src/chrome) and type the following command: 

          C:\trunk\src\chrome> devenv.exe /build Debug chrome.sln /project chrome.vcproj

          You can also use devenv.com with the same command-line. This will show the output of the various build commands, which can be useful when trying to track down errors during building.

          Note for Windows Vista: the devenv command may silently fail if Visual Studio has been configured to always run as Administrator. You can check or disable this by right clicking the Visual Studio application icon, then select Properties -> Compatibility -> Run this program as administrator.

          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 Chromeinstead of Chromium to get the Google Chrome resources.
          2. gclient runhooks
          3. src\build\all.sln
          4. Select 'Release' configuration
          5. Right-click on 'chrome' project and click 'Build'. You don't want to build the tests.
          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 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. SeeDebugging Chromium for more information.

          Once you're comfortable with building Chromium, read theContributing 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/chrome
          ./tools/build/win/make_zip.sh Release my-chromium

          This will create my-chromium.zip. You can change Release toDebug 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 andchrome\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 andwebkit\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.

          Manually registering the Platform SDK

              VS2008

          1. Open Visual Studio, Tools > Options... > Projects and Solutions > VC++ Directories
          2. Assuming your base SDK directory is C:\Program Files\Microsoft SDKs\Windows\v7.1, remove any existing entries v6.0 and v6.1 and add the following:
          • In Executable Files, insert on top C:\Program Files\Microsoft SDKs\Windows\v7.1\bin
          • In Include Files, insert on top C:\Program Files\Microsoft SDKs\Windows\v7.1\Include and C:\Program Files\Microsoft SDKs\Windows\v7.0\Include\gl
          • In Library Files, insert on top C:\Program Files\Microsoft SDKs\Windows\v7.1\lib
          • In Exclude directories, insert on top C:\Program Files\Microsoft SDKs\Windows\v7.1\Include and C:\Program Files\Microsoft SDKs\Windows\v7.0\Include\gl

              VS2010

          1. In Explorer, change the security C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props to allow you to write to it (will require administrative priviledges).
          2. Edit the file and replace v7.0A with v7.1
          3. Restart Visual Studio 2010.

                  The build should now pick up the 7.1 SDK, which you can verify by renaming the v7.0A Include and Lib directories (Visual Studio seems to require an executable from the v7.0A bin directory, haven't found where that is wired in yet).    

            Reinstalling Visual Studio SP1 (VS2008)

            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 thisMSDN blog post for more details.  The workaround is to re-download and over-install SP1 for Visual Studio 2008.  Note that at this point you're going to need to re-install all of the hotfixes from above and you should verify that the SDK directories are correct and fix them if not (see "Manually registering the Platform SDK" above).

            Special Service Pack Preparation Tool for Visual Studio 2008

            If you are having weird compilation problems on Visual Studio 2008, you may have missed some small prints when downloading the Service Pack 1. Here's an excerpt for you:
            • If you previously installed a Visual Studio 2008 Hotfix or Visual Studio 2008 SP1 pre-release, you must run the Service Pack Preparation tool before installing Visual Studio 2008 SP1.

            Native Client Doesn't Run

            If you're on 64-bit Windows, you need to build the chrome_nacl_win64 project manually.  It isn't a hard project dependency so that it doesn't break 32-bit builds.

            If you try to build it and get this error:
            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. Unfortunately, due to a bug in Visual Studio 2008 SP1, you can't add them after the fact once you've installed SP1.  As a workaround, first uninstall SP1, then go to the Windows control panel and "uninstall/change" Visual Studio 2008.  Open up the C++ feature and check the x64 compiler and tools feature.  Once that install finishes, reinstall SP1.  Now you should be able to build chrome_dll_nacl_win64.

            ALTERNATIVELY, you may be able to avoid the SP1 uninstall/install using this update from Microsoft:
            https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=27638
            See this post for more information:
            http://connect.microsoft.com/VisualStudio/feedback/details/487382/installing-visual-studio-2008-sp1-disables-ability-to-make-changes-to-
            visual-studio-installed-features

            NTFS recommended for building Native Client for Chrome


            The Native Client toolchain requires hardlinks to install properly.  We recommend that you only use NTFS for your project.  In particular, ExFAT is known to not work properly, and will result in errors similar to this:

            ________ running 'c:\depot_tools\python_bin\python.exe src/build/download_nacl_toolchains.py --x86-version 6494 --nacl-newlib-only --file-hash mac_x86_newlib 1b0855435c03c435a011c6105a509624b2a4edaa --file-hash win_x86_newlib 5038a47b5a9a49acdc36cbe311aec7bce575c164 --file-hash linux_x86_newlib 01e245dc6dca16bea5cf840dbc77e3aa138f234f' in 'F:\src\k0'
            tmptar/tar: sdk/nacl-sdk/bin/i686-nacl-ar.exe: Cannot hard link to `sdk/nacl-sdk/bin/i686-nacl-addr2line.exe': Operation not permitted

            Installing VisualStudio 2010 SP1 after Windows SDK 7.1

            There is a bug in VisualStudio 2010 SP1 that it will corrupt existing Windows SDK 7.1 installation.  Microsoft KB 2519277 is the fix:
            http://support.microsoft.com/?kbid=2519277.

            Installing Windows SDK 7.1 into non-default folder

            There is a bug in Windows SDK 7.1 that it always configures its own environment into the default folder regardless what you specified during install. There's not a known way to get around it, so just install it into default folder.

            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/svn/trunk/tools/third_party/

            See
            this link for instructions on turning off Windows Indexing.
            原创粉丝点击