轻松构建 Chromium 基础 (libchrome) 库

Easy building of Chromium base (libchrome) library

我使用 Chromium 代码库已经有一段时间了,已经习惯了它的优秀 base library (aka libchrome)。问题是虽然这个库很棒而且用途广泛,但并不打算在 Chromium 之外使用,所以将它作为一个独立的库使用确实有问题。

Library's page states that for other Google's projects they either released some inner packages or used scons build script which can be used for building the library. Unfortunately neither this script nor its more recent version 允许我编译它。我有一些关于错误标志或丢失输入文件的错误。可能一些与脚本放在同一目录中的补丁可能会有所帮助,但没有描述使用哪个以及以什么顺序使用。

some blog 上,我发现有人建议可以取而代之的是获取整个 Chromium 及其工具链,并将其配置为只构建一个库。但这真的很慢而且不太便携。如果有一天我要开发一些严肃的东西,它会迫使人们下载很多不必要的东西。

你们中有人知道构建该库的一些快速可靠的方法吗?它可能会更复杂,只要它可以通过脚本自动化并且不进行一次设置 PATH 变量并下载几 GB 的开销数据。

mini_chromium 提供基础库的独立构建,但不提供 Windows 构建。如果您需要这些,您必须自己添加。

我想详细说明@krishna 的回答。

建筑mini_Chromium

要安装 mini_chromium,您可以执行以下步骤:

git clone https://chromium.googlesource.com/chromium/mini_chromium
cd mini_chromium

# On POSIX
export GYP_GENERATORS=ninja
gyp --depth=. mini_chromium.gyp
# On Windows
set GYP_GENERATORS=ninja
gyp.bat --depth=. mini_chromium.gyp

ninja -C out/Release base
ninja -C out/Debug   base

这需要只安装 GYP 和 ninja。

构建 libchrome

通过一些额外的努力,我能够构建完整的 libchrome(在 Windows 上),但是它需要大量的黑客攻击,并且如果 Chromium 开发人员更改某些东西很容易崩溃:

# First checkout and initialize shallow Chromium SVN repository
svn checkout --depth empty http://src.chromium.org/chrome/trunk/src/ libchrome
cd libchrome
svn update --set-depth empty chrome/
svn update --set-depth empty third_party/
# Now fill it with only dependencies required to build target 'base'
svn update --set-depth infinity base/
svn update --set-depth infinity build/
svn update --set-depth empty    chrome/VERSION
svn update --set-depth infinity testing/
svn update --set-depth infinity third_party/android_crazy_linker/
svn update --set-depth infinity third_party/ashmem/
svn update --set-depth infinity third_party/libevent/
svn update --set-depth infinity third_party/libxml/
svn update --set-depth infinity third_party/modp_b64/
svn update --set-depth infinity third_party/zlib/
# Now checkout dependencies from outside of main Chromium repository
git clone https://chromium.googlesource.com/chromium/buildtools buildtools
git clone https://chromium.googlesource.com/chromium/testing/gtest testing/gtest
git clone https://chromium.googlesource.com/chromium/deps/icu52.git third_party/icu
git clone https://chromium.googlesource.com/chromium/deps/psyco_win32 third_party/psycho
git clone https://chromium.googlesource.com/external/gyp tools/gyp

此时已获取所有依赖项,但代码仍然无法构建。我们需要修改两个文件来使 thinks 工作:

  • build/gyp_chromium - 在第 30 行附近有一些路径需要在脚本启动时检查。只留下:

    # Add paths so that pymod_do_main(...) can import files.
    sys.path.insert(1, os.path.join(chrome_src, 'build', 'android', 'gyp'))
    sys.path.insert(1, os.path.join(chrome_src, 'tools'))
    
  • build/all.gyp - 删除与 base 无关的依赖项。结果应类似于 this GIST.

完成这些准备工作后,现在我们可以构建目标 base(假设安装了 depot tools):

build/gyp_chromium --depth=. --root-target=base
ninja -C out/Release base
ninja -C out/Debug base

我必须提醒一下,我是在 Windows 上构建的。整个 hacky 解决方法让我下载 500MB 的代码而不是 2.7GB 但它不受支持并且它可以随时停止工作。但可能当它崩溃时,它应该仍然相对容易修复,因为这可能是添加一两个依赖项的问题。

也许你可以看看我的端口:https://github.com/zhchbin/chromium-base 基于 mini_chromium。除了 mini_chromium,我将大部分 chromium/src/base 代码移到了这个独立的存储库中。它现在正在处理 windows 和 linux。