轻松构建Chromium base(libchrome)库

时间:2015-01-09 16:11:36

标签: c++ build chromium

我已经使用Chromium代码库一段时间了,并习惯了它的伟大base library (aka libchrome)。问题在于,尽管这个库很棒且功能多样,但它并不打算在Chromium之外使用,因此将它用作独立的库是非常有问题的。

Library's page指出,对于其他Google的项目,他们要么发布了一些内部包,要么使用scons build script来构建库。不幸的是,这个脚本及其more recent version都不允许我编译它。我对错误的标志或缺少输入文件有一些错误。可能有些补丁放在与脚本相同的目录中可能会有所帮助,但没有描述可以使用的内容和顺序。

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

您是否知道构建该库的快速可靠方法?它可能会更复杂,只要它可以通过脚本自动化,并且不要设置一个PATH个变量并下载几GB的开销数据。

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

也许您可以根据mini_chromium查看我的端口:https://github.com/zhchbin/chromium-base。除了mini_chromium之外,我还将大部分chrome / src / base代码移到了这个独立的存储库中。它现在正在使用Windows和Linux。

答案 2 :(得分:1)

我想详细说明@ 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和忍者。

构建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

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

  • 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但它不受支持,它可以随时停止工作。但是,当它破坏时,它应该仍然相对容易修复,因为这可能是添加一个或两个依赖的问题。