1

编译自己的Chromium (win10)

 2 years ago
source link: https://www.saltyfish.win/posts/chromium-build-win/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

编译自己的Chromium (win10)

2021-12-28

自己动手编译Chromium浏览器

Chrome与Chromium和Android与AOSP一样。Chromium + Google Chrome SDK = Chrome, AOSP + Google Mobile Services = Android。

Chromium开发比起Android开发不要太好。Chromium本身可以看作是一个C++写成的binary,是一个组件稍微有点多的application,所以整个编译流程走的是比较传统的compile+link,每次改动只影响到几个.o,所以大部分时间其实都花在第一次编译上了,之后改了代码以后的增量编译非常快。(Android就是噩梦了,这里按下不表)

所以一个5800x这类的CPU就能很愉快的玩耍了。内存的话不管编译啥都比较吃内存,16G起步,不然降速比较明显。硬盘这年头没人用机械盘了吧,要留够100G空间。

具体一定要参照官方指南:这里,以下为简介。

Visual Studio

Chromium repo是一个巨大的git repo,然后外带一个工具来sync其他的pre-built binary,叫gclient。Chromium有一套自己的git command wrapper,用起来是比较方便的。

首先我们需要装VS2019,虽然现在2022已经出了一段时间了但是Chromium还是没升级到这个新的上面,大概率还要等几个月。

官网选社区Community版本就足够了。下载下来是一个下载器,注意这里不要直接安装(因为默认是安装2022版),先取消然后自己选2019,环境是C++开发,然后还要附带上几个组件Desktop development with C++MFC/ATL support与至少Win10 SDK 10.0.19041起步的sdk。

等安装完成了还要装一个Win 10 SDK Debugging tool,不然也过不了编译。打开VS之后Control Panel → Programs → Programs and Features → Select the “Windows Software Development Kit” → Change → Change → Check “Debugging Tools For Windows” → Change

depot_tools

这个就是chromium用的git wrapper。参照指南,下载zip,然后整体解压,因为这个也是个git repo,一定要把.git文件夹带上。然后打开环境变量,把目录加到第一条PATH里面(优先级需要最高,因为要保证git和python命令都能调用到这里面)。还需要加一个DEPOT_TOOLS_WIN_TOOLCHAIN环境变量并设置成0。还需要加一个vs2019_install指向VS的安装目录(我的目录是C:\Program Files (x86)\Microsoft Visual Studio\2019\Community

$ gclient 应该是没问题的

where python 应该是指向上述tool目录里的python的

Clone

对我们来说可选,毕竟不打算向官方交代码,无所谓了。

$ git config --global user.name "My Name"
$ git config --global user.email "[email protected]"
$ git config --global core.autocrlf false
$ git config --global core.filemode false
$ git config --global branch.autosetuprebase always

新建文件夹chromium,然后执行fetch chromium --no-history开始拉代码(加no-history可以少拉下来很多东西,毕竟我们不需要本地开倒车)。

然后就是漫长的等待。

结束以后代码都在src文件夹里。

Build

gn gen out/Default是生成build配置到out/Default目录内,目录内的args.gn就是编译配置文件,默认应该是空的。然后autoninja -C out\Default chrome编译就行了。大概等一个多小时(或者几个小时,取决于CPU)就完成了,out/Default下面就有chrome.exe了。

然后会发现这个浏览器巨慢。因为这个是debug编译,我们还需要一个release版。

gn gen out/release生成一个新的配置,进args.gn加上如下的配置来生成release build。

chrome_pgo_phase = 0
is_official_build = true

然后autoninja -C out\release chrome就会在out/release下编译一个正常的版本。

PS: 平时开发建议用debug版本,虽然卡但是增量编译会快一些

H264 support

H264这个比较敏感。Chrome的H264解码用的是Google自己的闭源库(因为开源协议),Chromium默认编译不带解码库,开编译选项以后可以带上ffmpeg解码。

在args.gn里加上如下开关

proprietary_codecs = true
rtc_initialize_ffmpeg = true
rtc_use_h264 = true
use_openh264 = true
ffmpeg_branding = "Chrome"

Enjoy!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK