chromium源码获取及编译


前言

UE4项目中用到第三方库libcurl,因该库版本老旧,使用过程中出现漏洞。经查,新版libcurl库已修复该漏洞,故对libcurl进行了版本升级,曾使用nmake、cmake、VS2017进行升级,但漏洞依旧,且lib库文件最大不到5M,与UE4自带libcurl库(大小26M)有很大差距。在源码版UE4自带libcurl库中发现BUILD.EPIC.txt编译说明,乃使用此方法进行编译。此编译过程长达一周之久,其中遇到各种问题,都阻碍着编译的进行,好在都一一解决,现将过程记录如下。


一、使用BUILD.EPIC.sh编译

阅读说明

----------------------------------------------------------------------
TO RUN THE BUILD
----------------------------------------------------------------------
- NOTE: OpenSSL will NOT build if the path contains a space in the path

- that said, this script builds "stand-alone"

- in other words, you can do something like this
  (windows devs, remember to use git bash):

  mkdir -p /isolated
  cp BUILD.EPIC.sh COPY.EPIC.sh /isolated/.
  cd /isolated
  ./BUILD.EPIC.sh

在git bash中执行


!!! MANUAL SETUP REQUIRED !!!
!!! MANUAL SETUP REQUIRED !!!

install VisualStudio 2015 Update2

follow step #2 at:
  https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
  (no need to do step 1 - this build script will do that)

exiting script...

!!! MANUAL SETUP REQUIRED !!!
!!! MANUAL SETUP REQUIRED !!!

+ exit

首战失利,那就按提示打开链接:https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
这是一个编译chromium的文档,我们就照着文档开始编译之旅。

二、检出并编译适用于 Windows 的 Chromium

1.配置环境

系统要求

  • 具有至少 8GB 内存的 64 位 Intel 机器。强烈建议内存大于 16GB。
  • 至少 100GB 的空余磁盘空间,且用 NTFS 格式化的分区。不能用 FAT32,因为某些 Git 打包文件可能大于 4GB。
  • 一个合适版本的 Visual Studio,如下面的描述。
  • Windows 10 或更新的 Windows 系统。

按照文档要求将环境配置好,本人环境如下:

  • CPU:Intel® Core™ i7-9700K CPU @ 3.60GHz 3.60 GHz
  • 内存:64.0 GB
  • 操作系统:Windows 10 企业版
  • 系统类型:64 位操作系统, 基于 x64 的处理器
  • 硬盘剩余:700G
  • VS版本:VS2017,根据文档要求,新版本更好,故又安装VS2022

以上配置已达到配置要求

还必须安装版本 10.0.19041 或更高版本的 Windows 10 SDK。这可以通过单独安装,或选中 Visual Studio Installer 中适当的选项来实现。

打开 Visual Studio Installer,选中所有需要安装的依赖:
在这里插入图片描述
将 Visual Studio 安装在 C: 盘是一个比较方便的选择,但一般来说,C: 盘空间比较有限,我这里将 Visual Studio 安装在了 D: 盘。这种安装位置的非默认安装位置的改变,后面需要专门做一些额外的配置。

SDK Debugging Tools 也必须安装。如果 Windows 10 SDK 是通过 Visual Studio installer 安装的,则可以通过如下步骤安装:控制面板 → 程序 → 程序和功能 → 选择 “Windows Software Development Kit” (对应版本) → 鼠标右键单击,选择 “更改” → 更改 → 选中 “Debugging Tools For Windows” → Change。或者也可以下载单独的 SDK 安装器并使用它安装 Debugging Tools。

2.安装 depot_tools

下载 depot_tools 包 并将它解压到某个位置。

警告:不要 使用 drag-n-drop 或从 Explorer copy-n-paste,这可能不会提取隐藏的 “.git” 目录,这对 depot_tools 自身的自动更新是必须的。可以使用 “Extract all…”。

将 depot_tools 的路径添加到 PATH 环境变量的前面(必须在安装的 Python 的路径的前面)。假设将 depot_tools 包解压在了 F:\src\depot_tools,则打开:
右键单击 “此电脑” → 属性 → 高级系统设置 → 环境变量

如果有管理员权限,则修改 PATH 环境变量,并将 F:\src\depot_tools 放在前面(至少也要把它放在安装了 Python 或 Git 的目录的前面)。
在这里插入图片描述

如果没有管理员权限,可以添加一个用户级 PATH 环境变量,并把 F:\src\depot_tools 放在前面,如果你的系统 PATH 环境变量有 Python 的路径,就有点背了。

然后,还需要以相同方式添加一个 DEPOT_TOOLS_WIN_TOOLCHAIN 系统环境变量,并把它设置为 0。这告诉 depot_tools 使用本地安装的 Visual Studio 版本(默认情况下,depot_tools 将尝试使用一个 Google 内部的版本)。
在这里插入图片描述

可能还需要添加环境变量 vs2017_install 或 vs2019_install 或 vs2022_install 指向安装的 Visual Studio 2017 或 19 或 22,如对于 Visual Studio 2019 设置 set vs2019_install=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional,对于 Visual Studio 2022 设置 set vs2022_install=C:\Program Files\Microsoft Visual Studio\2022\Professional。
在这里插入图片描述

然后从 cmd.exe 命令行,运行:

$ gclient

在第一次运行时,gclient 将会安装所有 Windows 特有的与代码一起工作的东西,包括 msysgit 和 python。

如果从一个 非 cmd shell (如,cygwin,PowerShell)运行 gclient,它可能看上去正常运行了,但 msysgit,python 和其它工具可能不会被正确安装。
如果你在第一次运行 gclient 时看到了关于文件系统的奇怪的错误,可能想要 禁用 Windows Indexing。

本人运行后如下:

F:\src\depot_tools>gclient
fatal: unable to access 'https://chromium.googlesource.com/chromium/tools/depot_tools.git/': Failed to connect to 127.0.0.1 port 10809: Connection refused
Usage: gclient.py <command> [options]

Meta checkout dependency manager for Git.

Commands are:
  config   creates a .gclient file in the current directory
  diff     displays local diff for every dependencies
  fetch    fetches upstream commits for all modules
  flatten  flattens the solutions into a single DEPS file
  getdep   gets revision information and variable values from a DEPS file
  grep     greps through git repos managed by gclient
  help     prints list of commands or help for a specific command
  metrics  reports, and optionally modifies, the status of metric collection
  pack     generates a patch which can be applied at the root of the tree
  recurse  operates [command args ...] on all the dependencies
  revert   reverts all modifications in every dependencies
  revinfo  outputs revision info mapping for the client and its dependencies
  root     outputs the solution root (or current dir if there isn't one)
  runhooks runs hooks for files that have been modified in the local working copy
  setdep   modifies dependency revisions and variable values in a DEPS file
  status   shows modification status for every dependencies
  sync     checkout/update all modules
  validate validates the .gclient and DEPS syntax
  verify   verifies the DEPS file deps are only from allowed_hosts

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -j JOBS, --jobs=JOBS  Specify how many SCM commands can run in parallel;
                        defaults to 8 on this machine
  -v, --verbose         Produces additional output for diagnostics. Can be
                        used up to three times for more logging info.
  --gclientfile=CONFIG_FILENAME
                        Specify an alternate .gclient file
  --spec=SPEC           create a gclient file containing the provided string.
                        Due to Cygwin/Python brokenness, it can't contain any
                        newlines.
  --no-nag-max          Ignored for backwards compatibility.

改用gclient sync,然后从 cmd.exe 命令行,运行:

gclient sync

执行后,遇到这个问题:

Error: client not configured; see ‘gclient config’

那么要在gclient所在的depot_tools目录创建一个.gclient文件,写上:

solutions = [
  {
    "managed": False,
    "name": "src",
    "url": "https://chromium.googlesource.com/chromium/src.git",
    "custom_deps": {},
    "deps_file": ".DEPS.git",
    "safesync_url": "",
  },
]

在cmd中继续执行gclient sync就好了。

在下载过程中可能会遇到这些问题:
Fetching
fromhttps://src.chromium.org/svn/trunk/tools/third_party/svn_bin.zip
  fatal:
unable toaccess ‘https://chromium.googlesource.com/chromium/tools/depot_tools.git/’:Failed connect to chromium.googlesource.com:9217; No error
  Cannot
rebase:You have unstaged changes.
  Please
commit orstash them.
  Failed
to updatedepot_tools.
如果遇到上述问题,应该是无法连接到chromium服务器,可以使用vpn或者代理。

不过也许你像我一样,即使用了SSR,还是会在下载大量文件后出现无法下载问题。
在这里插入图片描述
这里停到这里就不动了,使用Ctrl+C停止后再执行gclient sync命令,下载到中途又会停止不动。我把googlesource改为了github的地址:https://github.com/chromium/chromium.git
终于可以正常下载了,等了十几个小时后又出现以下问题
在这里插入图片描述
哪怕再重新执行gclient sync还是停留到这个地方。

3.配置代理

此步骤需要根据自己的代理软件参数进行设置
在这里插入图片描述

(1)为CMD设置HTTP/HTTPS代理
打开一个具有管理员权限的CMD
C:>netsh
netsh>winhttp
netsh winhttp>set proxy 127.0.0.1:10809
netsh winhttp>bye

C:>set http_proxy=http://127.0.0.1:10809
C:>set https_proxy=http://127.0.0.1:10809
注:此步骤若关闭当前cmd,重新打开新的cmd需要重新配置代理

(2)为git设置http/https代理
C:>git config –-global http.proxy %http_proxy%
C:>git config –-global https.proxy %https_proxy%

(3)设置NO_AUTH_BOTO_CONFIG
<1>随便找个地方创建一个文本文件,比如 C:\boto.cfg
文本内容:
[Boto]
proxy=127.0.0.1
proxy_port=10809
<2>设置环境变量
C:>set NO_AUTH_BOTO_CONFIG=C:\boto.cfg

备注:
代码同步成功后,记得回复系统设置
(1)恢复netsh winhttp设置为直连
C:>netsh
netsh>winhttp
netsh winhttp>reset proxy
(2)清除git代理
git config --global --unset http.proxy
git config --global --unset https.proxy

(3)如果之前从未使用过git,那么需要进行一下全球的git配置
C:>git config –global user.name “yourname” #yourname改为你希望的用户名
C:>git config –global user.email “youremailaddress@gmail.com” #输入你自己的邮箱

经过以上设置,终于又可以下载了,后来又出现如下错误:

fatal: unable to access >’https://chromium.googlesource.com/chromium/tools/depot_tools.git/‘: Failed to connect to chromium.googlesource.com port 443: Timed out

还是归功于伟大的墙,在环境变量里设置DEPOT_TOOLS_UPDATE为0即可正常下载
在这里插入图片描述
下载完毕以后可以多执行几次gclient sync命令,直到出现
在这里插入图片描述
下载至此大功告成!
在这里插入图片描述
源码竟然有53个多G

4.编译chromium源码

(1)进入源码目录
cd src
(2)生成编译配置文件
gn gen out/Default --ide=vs //out/Default 中 Default并非固定,可以随意取名
这里出现错误: 在这里插入图片描述
输入set命令,发现没有”WINDOWSSDKDIR“变量,这是因为没有找到windows sdk的路径,但我通过VS2017和VS2022安装了SDK,不知道为什么系统找不到。于是我又重新在windows官网下载了win10 SDK,并设置windows sdk路径:

F:\src\depot_tools\src>set WINDOWSSDKDIR=D:\Windows Kits\10

继续
在这里插入图片描述
成功Done,但这里出现错误:
error: [0mcould not open ‘atls.lib’: no such file or directory
这是由于缺少“atls.lib”文件,是VS自带ATL x64库的库文件,通过everything搜索文件后发现它在VS2017中:
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\lib\x64\atls.lib
在VS2022中并没有发现这个库文件,但系统只有VS2022的路径,没有VS2017的路径,所以我把这个文件复制到VS2022路径中:
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\lib\x64\atls.lib
(3)编译代码
autoninja -C out/Default chrome
又出现这个错误:
在这里插入图片描述
看来是还缺少一个文件:‘atls.amd64.pdb’,从VS2017目录中也一并复制到VS2022中,再次执行编译命令
在这里插入图片描述
又可以顺畅地编译了
完成之后多执行几次命令:ninja -C out/Default chrome
在这里插入图片描述
直到出现ninja:no work to do,大功告成!
在这里插入图片描述
编译成功后,目录大小达到了108G。


三、总结

chromium在源码获取和编译的过程中,资料少、速度慢、问题多,一个问题接着一个问题,一周以来电脑就没有关过机,熬人又熬机。但是坚持下来了,耐心地研究问题和查阅网络资料,结果还是没有辜负我一片诚心。
感谢网络上各位大佬的支持。

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值