chromium 编译分享

来源:互联网 发布:手机可以开淘宝网店吗 编辑:程序博客网 时间:2024/05/21 16:55

一. 编译的启示:

1. 选择vs版本为2008,如果不幸选择了2010,然后跟我一样走了这条不归路,那就悲剧了,可能机器环境差别大吧,我后面的狗血经历会介绍

2. 最好通过google提供的depot_tools工具去下载和编译代码吧,这个事google在后面版本中推荐使用的

       (我有比较通过TortoiseSVN下载过chromium的代码和通过工具下载的代码,通过TortoiseSVN下载的代码只有1G左右,但是通过工具下载下来的大概有8G,使用工具过程是不是有部分编译没有研究过,不过通过两种方式下载的代码大小确实不一样,所以还是用gclient搞定吧,毕竟也不复杂)

3. 在生成工程文件.sln,.vcproj之前记住要设置GYP_MSVS_VERSION值,也就是vs的版本,这样可以使得生成的.sln,vcproj文件是你想要的版本。

4. 记住按照官网一步步操作来,别偷懒,遇到问题多google几把。

5. 选择一台猛一点的机器吧,内存最好4G,我机器内存只有2G,太卡了,大量使用硬盘,太慢了,哥脾气真好啊。

经验就这么多了,下面介绍过程。

 

二. 安装过程以及遇到的问题

1. 首先介绍一下我机器的环境:安装了xp sp3 , vs2005, 官网上面知道安装的只有vs2008和vs2010,google了一把(google现在越来越不给力了,经常出现无法打开网页),搜索到一些介绍用vs2005版本的编译指导,但是日期都偏早,通过搜索了解到,chromium工程文件在后面修改了不少(比如:没有.sln文件),而且介绍的很零碎,一些需要安装的软件还要自己去找,果断放弃使用vs2005,选用最新的vs2010。我安装的是Ultimate,按照官网指引做下面几步:

       a)  install Visual Studio 2010 /Visual C++ 2010 Express

1)    Install VS2010 SP1.

2)    Install the Windows 7.1 SDK.

3)   You may need this repairto restore the libraries if the SDK was already installed whenyou installed SP1.

4)   Specify the version of theWindows SDK by setting the 'msbuild_toolset' variable in%USERPROFILE%\.gyp\include.gypi. Create the file if needed:

{

  'variables': {

    'msbuild_toolset': 'Windows7.1SDK',

  },

}

5)   As of 2011-04-01, VS2010 isnot detected automatically by GYP, so to generate the .sln/.vcxproj, you needto

1.    set/exportGYP_MSVS_VERSION=2010 (or create new Windows environment variable)

§ Note: 2010e for expressversions.

2.    gclient runhooks

6)   There is an issue in gyp:GYP-222

 AdditionalManifestFiles elementshould be in Manifest instead of Mt

§ No tooltip due by lack of manifest file in EXE/DLL.

       b)  Install the June 2010 DirectX SDK

1)  Add  $(DXSDK_DIR)\include; to the beginning of the 'IncludePath' propertyin %LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props.

2)  Add  $(DXSDK_DIR)\lib\x86; tothe beginning of the 'LibraryPath' property in the same file. At this point the.props file will look like this:

<?xml version="1.0"encoding="utf-8"?>

<Project DefaultTargets="Build"ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>

    <IncludePath>$(DXSDK_DIR)\include;$(IncludePath)</IncludePath>

    <LibraryPath>$(DXSDK_DIR)\lib\x86;$(LibraryPath)</LibraryPath>

  </PropertyGroup>

</Project>

3)  Similarly,edit%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props:

<?xml version="1.0"encoding="utf-8"?>

<Project DefaultTargets="Build"ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>

    <IncludePath>$(DXSDK_DIR)\include;$(IncludePath)</IncludePath>

    <LibraryPath>$(DXSDK_DIR)\lib\x64;$(LibraryPath)</LibraryPath>

  </PropertyGroup>

</Project>

4)  Do not editthe files above via the Visual Studio UI (via View->Property Manager)because it may overwrite recursive $(IncludePath) and $(LibraryPath) breaking(potentially) Windows SDK selection via the 'msbuild_toolset' variable.

      • Make sure the DirectX include and lib directories appear first in the search path, otherwise you may get build errors
      • (e.g. error C3861: 'XInputEnable': identifier not found).

c)  Install the WDK forthe ATL/MFC headers and libs (else you will get "Missing libraryatlthunk.lib" and "Missing header altbase.h" errors).

1) After you've donethis, create a system-wide environment variable named WDK_DIR viaRun...->SystemPropertiesAdvanced->Environment Variables...->New...(inSystem variables), with the name of WDK_DIR and the location you installed the WDK(e.g. C:\WinDDK\7600.16385.1).

2) Add the followingpaths (highlighted) to%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props:

<?xml version="1.0"encoding="utf-8"?>

<Project DefaultTargets="Build" ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

 <PropertyGroup>

   <IncludePath>$(DXSDK_DIR)\include;$(IncludePath);$(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42</IncludePath>

    <LibraryPath>$(DXSDK_DIR)\lib\x86;$(LibraryPath);$(WDK_DIR)\lib\ATL\i386</LibraryPath>

  </PropertyGroup>

</Project>

3) Add the followingpaths (highlighted) to%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props:

<?xml version="1.0"encoding="utf-8"?>

<Project DefaultTargets="Build"ToolsVersion="4.0"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>

 <IncludePath>$(DXSDK_DIR)\include;$(IncludePath);$(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42</IncludePath>

    <LibraryPath>$(DXSDK_DIR)\lib\x64;$(LibraryPath);$(WDK_DIR)\lib\ATL\amd64</LibraryPath>

 </PropertyGroup>

</Project>

4) Do not editthe files above via the Visual Studio UI (via View->Property Manager)because it may overwrite recursive $(IncludePath) and $(LibraryPath) breaking(potentially) Windows SDK selection via the 'msbuild_toolset' variable.

d) Building Chromium

1)    Get the Chromium depot_tools.

2)    Check out the source code using eitherthe bootstrap tarball or a direct svn checkout.

3)    Open the chrome/chrome.sln solution file in Visual Studio and build thesolution. This can take from 10 minutes to 2 hours. More likely 1 hour.

4)    If you just want the Chromium browser, and none of thetests, 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 asStartup Project. This will make Chromium (as opposed to some random test)build and run when you press F5.

2. 过程中遇到的几个问题:

       1)安装sdk7.1过程中失败了,经过打开viewlog,然后搜索了一把,去掉了vc++ compilers,然后就成功了,在我的机器上面貌似安装sdk 7.0可以成功,但是安装sdk7.1会失败,失败的log忘记保存了,具体原因还没有了解清楚。

       2) 中间找不到DXSDK_DIR,WDK_DIR,gclient,这个是因为没有在环境变量里面添加相应的执行文件的路径。

    3)编译chrome过程中遇到了下面几个问题

a)      error MSB6006: "cmd.exe" exitedwith code 255. 这个error的提示是: 输入行太长。在网上没有找到答案,然后我尝试把chromium工程放在根目录下面,没有效果

b)      cl : Command line error D8030: INTERNALCOMPILER ERROR in '诌嗿赑ﱅ桐哨A痿(䀑謀ﱅ쒃줌诃嗿'。这个error安装了一个补丁就Ok了,vc10的bug,补丁地址:补丁

c)     c1xx : fatal error C1083: Cannot open source file:'../../../../..\build\Debug\\obj\global_intermediate\webkit\CSSPropertyNames.cpp':No such file or directory E:\chromium\src\third_party\WebKit\Source\WebCore\dom\ExceptionCode.h(23):fatal error C1083: Cannot open include file: 'ExceptionCodeDescription.h': Nosuch file or directory

e:\chromium\src\third_party\webkit\source\webcore\dom\EventNames.h(25):fatal error C1083: Cannot open include file: 'EventInterfaces.h': No such fileor directory

这个error就像上面这样的找不到的头文件的,编译完成后多大1000多个,首先全局搜索一把,果然没有找到这些文件,然后google了一通,貌似有不少遇到我同样问题的,但是都没有给出合理的解决方案,有一个解决方案是说要让机器找到cygwin,我看了一下我编译的log,发现我机器编译过程中已经做了注册\third_party\cygwin\setup_env.bat的操作,到相应的注册表下面去确实可以看到路径是对的并且在工程编译过程中pl文件也可以顺利被调起执行。


google了一把后发现在http://code.google.com/p/webkit-mirror/source/browse/Source/WebCore/dom/make_exception_code_description.pl?r=a550abd1ee346479d49e30ab6a7ba484c5f1633e这个Perl文件中找到了生成"$outputDir/ExceptionCodeDescription.h"的脚本,由此猜测我机器上面找不到的文件应该不是工程自带的(我同步了几次chromium代码,都没有找到ExceptionCodeDescription.h文件),而是由脚本生成的,在chromium工程下面查找文件make_exception_code_description.pl,果然在\third_party\WebKit\Source\WebCore\dom目录下面找到了,然后到网上求解,证明我之前的猜测是对的,搜索了一下我编译chromium生成的log,找到了perl解释有些.pl文件的记录,就更坚定了我的猜测。

 

这里问题就来了,为什么要生成这些头文件的pl没有被执行或者是执行但是没有生成我们想要的头文件呢?又去搜索了一通最后得出的结论是跟*.gyp文件有关,比如:WebCore.gyp文件的解析。我不了解.gyp((GenerateYour Projects)文件,所以没有继续深究了,中间的编译过程太长,搞得焦躁了。

 

但是有几个东西挺有意思的:1. 为什么要用perl用来生成这些头文件,而不是直接写呢(跟平台相关?如果是的话它是怎么做到的呢,有什么值得借鉴的)2. .gyp格式的文件可以了解一下,google为什么要搞一个这种格式的,为什么不直接用perl得了。

 

3. 遇到了上面的几个问题后,在网上找了一段时间没有搞定,决定换一个环境,安装vs2008,然后继续按照官网的介绍安装了一下环境

 

       a)  Visual Studio 2008(professionaledition)         

1. Install VS2008 SP1 (unless you already have SP1,e.g. because you downloaded VS2008 Express w/SP1 via the link above).

2.    Install KB967631KB960075, and KB957912.

3.    Install the Windows 7.1 SDK

                      i.         Read the instructions on the SDK download page! Read itagain!

                     ii.         You might need to reboot. You can save space by notinstalling the documentation and code samples.

4.    Integrate the SDK with Visual Studio

                              i.       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.1 -legacy

                             ii.       If build still fails, try registering the SDK manually.

                            iii.       If you had a previous version of the SDK installed beforeinstalling, verify that your VC++ directories are set to use the newest and notan earlier SDK.  See registering the SDK manually for details.

5.    If you are not using Visual Studio 2008Express, install KB971092. Yes, that's a 365 MB update. :/

6.    If you are using Visual Studio 2008 TeamSystem and plan to use the profiler, install KB958842

       b) Installthe June 2010 DirectXSDK                    

1. Visual Studio 2008:

o   Open Tools > Options > Projects and Solutions > VC++ Directories.

o   Under "Include files" add $(DXSDK_DIR)include to the start of the list.

o   Under "Library files" add $(DXSDK_DIR)lib\x86 to the start of the list.

       c) IInstallthe WDK forthe ATL headers and libs.

Verify MSVC|Tools|Options|Projects andSolutions|VC++ Directories has Include: [WDK]include\atl71 and Lib: [WDK]lib\Atl\i386 where [WDK] is the WDK install directory.

       d) BuildingChromium

1.    Get the Chromium depot_tools.

2.    Check out the source code using eitherthe bootstrap tarball or a direct svn checkout.

3.    Open the chrome/chrome.sln solution file in Visual Studio and build thesolution. This can take from 10 minutes to 2 hours. More likely 1 hour.

4.    If you just want the Chromium browser, and none of thetests, 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 asStartup Project. This will make Chromium (as opposed to some random test)build and run when you press F5.


       4.  换了环境后,重新把前面的代码工程文件生成vs2008的,然后rebuild整个工程,过了好久好久终于成功了

 

三. 涉及的网址

chromium地址:https://src.chromium.org/svn/trunk/src

chromium开发网站地址:http://www.chromium.org/developers

webkit地址:http://www.webkit.org/