chromium windows compile 浏览器编译 vs2017 win10

https://blog.csdn.net/longji/article/details/80967225

01 阅读官方文档
https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md

一个中文翻译文档:https://blog.csdn.net/Vincent95/article/details/78469807

02 安装python2.7.*
depot_tools需要使用python2.7。
https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi

03 配置 depot_tools
下载depot_tools,加压到d:gitchromiumdepot_tools,并把d:gitchromiumdepot_tools加入环境变量。
https://storage.googleapis.com/chrome-infra/depot_tools.zip
把depot_tools的路径加到 PATH 环境变量的最前面,至少要加到python环境变量的前面

04 配置必要的信息
设置git全局配置信息

# user.name 和 user.email 需要使用自己的。
git config --global user.name "5455945"
git config --global user.email "5455945@gmail.com"
git config --global core.autocrlf false
git config --global core.filemode false
git config --global branch.autosetuprebase always

# 这个可以在系统环境变量里面设置,也可以在命令行窗口设置
set GYP_MSVS_VERSION=2017
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_OVERRIDE_PATH="D:installMicrosoft Visual Studio2017Community"
1
2
3
4
5
6
7
8
9
10
11
05 下载代码
参考:https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md#Using-the-Visual-Studio-IDE

fetch chromium

# 不下载历史版本信息,速度较快,后续切换分支时略慢
fetch chromium --no-history

# 如果下载失败
gclient sync --nohooks --with_branch_heads --with_tags --output-json="log.json"
gclient runhooks # 或者 gclient runhooks --force

# 上面成功后,
cd src
git fetch --all
git fetch --tags

git pull
# 到此为止,是master的最新代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
06 切换到相对稳定分支
参考:
https://omahaproxy.appspot.com/
http://www.chromium.org/developers/how-tos/get-the-code/working-with-release-branches

cd src # 在src目录
# 创建新的分支b3440
git checkout -b b3440 branch-heads/3440
# 也可以考虑直接使用tag。比如:git checkout -b b3440 68.0.3440.54
cd .. # zai src的上一级目录(chromium目录)
gclient sync --with_branch_heads --with_tags
1
2
3
4
5
6
07 build时的设置参数
target_cpu=“x86”:指明生成的针对X86架构的CPU。
is_debug=false:指明生成的是Release版本可执行程序。
is_official_build=true:指明使用Chrome官方的编译优化建议。
proprietary_codecs:指明支持H264编码,编译时,自动H264相关组件,打包PE文件中。
enable_nacl=false:指明关闭支持NACL,这是一种Chrome插件,因为安全性,稳定性存在问题,已经很少使用了。
remove_webcore_debug_symbols=true:指明删除内核层支持调试的符号文件,这样,有助于减少文件体积,提高运行速度。

查看gn args 所有可用参数
gn 说明 https://www.chromium.org/developers/gn-build-configuration

:: 很重要的参考资料
gn args --list outDebug
::去掉显示头文件的包含树
::修改srcuild oolchainwinBUILD.gn,将/showIncludes删除掉
1
2
3
4
使用 --filters=//chrome , 会过滤掉一些工程,比如:setup,mini_installer 两个工程,在设置 --filters=//chrome 支持ninja编译,不会生成vs2017的工程。
所以是否使用 --filters=chrome,还需要根据自己的实际需要斟酌。

gn gen out/Debug --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x86" is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C outDebug chrome setup mini_installer
:: 35025文件

gn gen out/Release --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x86" is_component_build=false is_debug=false is_official_build=true google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C outRelease chrome
ninja -C outRelease mini_installer

gn gen out/DebugX64 --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x64" is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C outDebugX64 chrome
:: 35025文件

:: is_component_build=false 和 is_official_build=true 不能同时为true
gn gen out/ReleaseX64 --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x64" is_component_build=false is_debug=false is_official_build=true google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"
ninja -C outReleaseX64 chrome
:: 生成安装包
ninja -C outReleaseX64 mini_installer
ninja -C outReleaseX64 setup
:: 34416文件

:: 关掉clang选项 is_clang=false,需要停用掉vs的头文件警告,修改srcuild oolchainwinBUILD.gn,将/showIncludes删除掉
gn gen out/DebugX64 --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x64" is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true is_clang=false"

:: 指定winsdk版本。如果本机按照多个版本的sdk,可以明确指定使用sdk的版本,目前官网说明使用10.0.17134
:: 注意,winsdk版本号不要加引号
gn gen out/DebugX64 --ide=vs2017 --filters=//chrome --args="target_os="win" target_cpu="x64" --winsdk=10.0.17134.12 is_component_build=true is_debug=true is_official_build=false google_api_key=false google_default_client_id=false google_default_client_secret=false proprietary_codecs=true media_use_ffmpeg=true ffmpeg_branding="Chrome" remove_webcore_debug_symbols=true enable_nacl=false enable_hevc_demuxing=true enable_dolby_vision_demuxing=true enable_mse_mpeg2ts_stream_parser=true enable_hls_sample_aes=true enable_ac3_eac3_audio_demuxing=true"

:: 使用eclipse调试,指定ide=eclipse,使用 Eclipse IDE for C/C++ Developers x64版本
:: https://www.eclipse.org/downloads/packages/
:: https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2018-09/R/eclipse-cpp-2018-09-win32-x86_64.zip
gn gen out/eclipse --ide=eclipse --winsdk=10.0.17134.12 --filters=//chrome --args="target_os="win" target_cpu="x64" is_component_build=true is_debug=true is_official_build=false google_api_key="zdx-client-oauth-id" google_default_client_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
chromium能够支持的html5选项,可以参考: http://html5test.com/

*在gclient sync的时候遇到了错误,根据提示手动修改了 .py文件。
后来编译的时候又出现错误。卸载了windows wdk,编译正常通过

Chrome浏览器内置功能指令
https://wiki.deepin.io/mediawiki/index.php?title=Chrome浏览器内置功能指令

08 设置远程分支与本地分支对应关系
建立对应远程分支的本地分支,比如:建立对应68的正式发布版本的本地分支,68.0.3440.54,分支为b3440。

git checkout -b b3440 remotes/branch-heads/3440
1
建立本地分支与远程分支的对应关系,远程分支变化,切换到本地分支时,能够直接观察的到,或者使用 git fetch --all时,能够拉到对应分支的变更内容

# git branch --set-upstream-to=远程分支名词 本地分支名称
git branch --set-upstream-to=remotes/branch-heads/3440 b3440
1
2
09 查看分支对应关系
git branch -vv
1
10 取消远程分支对应关系
# git branch --set-unupstream-to=远程分支名词
git branch --set-unupstream-to=remotes/branch-heads/3440
1
2
11 编译生成安装包
ninja -C out/Release chrome setup mini_installer
outReleasesetup.exe --chrome --multi-install

1
2
3
12 几个有用的命令
# 查找当前目录下所有.gn文件 是否包含 executable("chrome")
findstr /S "executable("chrome")" *.gn

删除d:path1目录及子目录下所有*.lock文件
forfiles /P "d:path1" /S /M "*.lock" -C "cmd /c del @path"

# 清楚不用的文件
git clean -df # 注意,这个命令同时会清除git仓库下面的submodule内容,慎用!!
git reset --hard

git reset --hard
git clean -xdf

git pull
:: 解决冲突
git rebase --continue
git pull
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
如果vs2017安装路径不是默认的,runhooks的时候提示的错误中含有 vs2017_install,需要自己在系统环境变量中添加一下vs2017_install环境变量。比如:我的vs2017安装在D:installMicrosoft Visual Studio2017Community。需要这样设置:

set vs2017_install="D:installMicrosoft Visual Studio2017Community"
1
13 关于google api key
如果需要使用google api key,可以在gn中指定 google api key 相关的参数。
获取密钥(ID)教程:
https://www.chromium.org/developers/how-tos/api-keys
获取密钥(ID)地址:
https://cloud.google.com/console
https://console.cloud.google.com/start

google_api_key
google_default_client_id
google_default_client_secret
1
2
3
也可以把这几个参数直接写在文件srcgoogle_apisBUILD.gn 中的
google_api_key
google_default_client_id
google_default_client_secret

对于同一个分支的 gclient sync,我们自己修改代码前和修改代码后不会影响gclient sync的。
git checkout -b bb3578_1 branch-heads/3578
git merge b3578
gclient sync
git checkout -b bb3578_2 branch-heads/3578
gclient sync

14 关于branch-heads/3578问题
在编译branch-heads/3578后,debug x86版本。vs2017调试会出现崩溃现象,单独运行debug release版本都正常。只有调试的时候,出现崩溃。而且很频繁。使用vs2017的15.9.1版本不行,回退到15.8版本,也不行。一次删除扩展插件也没缓解。该问题为解决。

切换到 branch-heads/3538 稳定分支。70.0.3538.110,不修改任何代码,vs2017调试,依然崩溃。
vs2017 社区版本,15.8 14.15 toolset。

最初使用vs2017 老版本,68.0.3440.105调试时,偶尔有崩溃问题 ,频率不高。

后来,代码升级到branch-heads/3578,调试登陆问题,崩溃频率很高。于是升级vs2017到最新版本 15.9.1。崩溃频率更高。
于是各种更新vs2017版本。包括:更好sdk版本15.8 14.15 toolset;14.14 toolset;卸载扩展插件。
重新完整安装15.9.2版本。问题依然存在。

vs2017崩溃无提示。看vs2017报告显示内存不足,观察任务管理器或者ProcessHacker查看,调试是内存最高占用4BG左右。

调试的chromium是x86版本。

目前没找到解决办法。

15 chrome://net-internals
chrome://net-internals/#proxy
chrome://net-internals/#dns

16 插件商店下载相关的源码
显示安装窗口的部分

void DashboardPrivateShowPermissionPromptForDelegatedInstallFunction::
OnWebstoreParseSuccess

kDashboardInvalidManifestError

ExtensionInstallPrompt::GetLocalizedExtensionForDisplay
1
2
3
4
5
6
安装vs的环境要求
https://blog.csdn.net/LostSpeed/article/details/81405462
记得上次弄68版本的时候,一开始好像也遇到过上面博客说的情况。

如果发现vs编译或者调试chromium不行,那就完全卸载vs和sdk,然后用官网的安装工具安装。
————————————————
版权声明:本文为CSDN博主「longji」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/longji/article/details/80967225