Chromium Linux内核编译

系统要求

  • 64位系统,不支持32位
  • 内存最好大于16GB
  • 磁盘大小要超过100GB用于编译
  • 系统选择,google推荐ubuntu14.04,也支持其他平台的编译
  • 参考地址:
    https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md

下载编译工具

$mkdir chromium
$ cd chromium 
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 
$ export PATH=$PATH:/path/to/depot_tools  # 可以放入bashrc

如果下载失败,需要设置代理

# 全局代理   
export http_proxy="http:port" 
# git代理 
git config --global http:port

源码下载

fetch --nohooks --no-history chromium

分支的下载请参考
https://www.chromium.org/developers/how-tos/get-the-code/working-with-release-branches
执行时间比较长,下载的文件大小约为15GB

获取第三方依赖

如果使用的是ubuntu,只需要执行源码中的./build/install-build-deps.sh。如果你使用的是其他的linux发行版,则需要对应于此脚本,安装缺少的依赖。https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md

$ cd src 
$ ./build/install-build-deps.sh

这一步可能会因为posxfix导致安装失败,需要修改下/etc/postfix.main.cf中的inet_interfaces = 127.0.0.1

执行Hooks

这一步,编译工具会获取一些需要的工具包。 gclient runhooks在中间,可能会因为无法下载所需文件而报错。我们需要修改一些文件,来完成这一步。具体如下:

# 需要修改的文件:
src/build/linux/sysroot_scripts/install-sysroot.py:207 
# 修改如下:['curl', '--proxy', 'host:port', '--fail', '--retry', '3', '-L', url, '-o', tarball]

可以看出,这个python脚本是通过调用curl来下载文件的,所以我们为其添加了代理设置。 同时,为了让gclient能够使用代理,我们还需要设置boto,方法如下:
# 在user_home目录下
$ touch .boto
# 编辑 .boto
[boto]
proxy=addr
proxy_port=port
# 加入环境变量 export NO_AUTH_BOTO_CONFIG=~/.boto
如果还下载失败,需要手动下载文件,需要解压的需要手动解压即可。

编译

  • 完整编译
    使用google的ninja开始编译就ok了。注意不要使用out/Default和out/Debug这两个目录,作为输出目录。
# 生成编译目录
$ gn gen out/Release  
# 编译chrome $ ninja -C out/Release chrome
  • 命令行模式编译(headless模式)
# 生成编译目录 
$ mkdir -p out/sf 
$ echo 'import("//build/args/headless.gn")' > out/sf/args.gn $ gn gen out/sf 
# 编译headless_shell 
$ ninja -C out/sf headless_shell 

最好在性能高的服务器上编译,16G内存,12核机器大约需要1个小时左右。8G内存,4核机器便于大约需要5个小时左右。

运行

$ cd out/Release 
$./chrome --disable-setuid-sandbox 

# 无命令行 
$ cd out/sf
$ ./headless_shell http://www.baidu.com 

编译问题

ICU_UTIL_DATA_IMPL' macro redefined解决办法:third_party/icu/BUILD.gn修改这个文件中第46行开始为


Chromium Linux内核编译_第1张图片
图片

修改v8/BUILD.gn第1843行为


Chromium Linux内核编译_第2张图片
图片

瘦身

编译完后二进制文件比较大,可以使用strip命令对其瘦身。

$strip headless_shell

你可能感兴趣的:(Chromium Linux内核编译)