Linux下编译CEF chromium源码及交叉编译
官方编译文档:https://bitbucket.org/chromiumembedded/cef/wiki/MasterBuildQuickStart#markdown-header-linux-setup
编译参数推荐:https://bitbucket.org/chromiumembedded/cef/wiki/AutomatedBuildSetup.md#markdown-header-linux-configuration
选择版本:cef104 chromium版本号: 104.0.5112.102
1. 配置代理
代理要自己想办法,这里只写下配置方法,不然chromium
项目根本拉不下来,想查的很多东西国内也没有资料,障碍非常大。
export http_proxy=http://{username}:{passwd}@{IP}:{PORT}
export https_proxy=http://{username}:{passwd}@{IP}:{PORT}
2. 安装依赖
准备目录
mkdir ~/code
mkdir ~/code/automate
mkdir ~/code/chromium_git
安装依赖
cd ~/code
sudo apt-get install curl
curl 'https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT' | base64 -d > install-build-deps.sh
chmod 755 install-build-deps.sh
sudo ./install-build-deps.sh --no-arm --no-chromeos-fonts --no-nacl
3. 下载编译工具:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=/home/marshall/code/depot_tools:$PATH
cd ~/code/automate
wget https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py
4. 下载代码
cd ~/code/chromium_git
python3 ../automate/automate-git.py --download-dir=~/code/chromium_git --depot-tools-dir=~/code/depot_tools --branch=5112 --no-distrib --no-build
这个命令是从官方源码下载,可能会非常慢而且经常出错,一般是超时或者拉库失败,多执行几次直到完全拉取成功,这一步也可以从别的位置(比如以下)手动下载源码放到~/code/chromium_git
目录下
https://gitee.com/mirrors/chromium.git
https://github.com/chromium/chromium
https://chromium.googlesource.com/chromium/src.git
执行同步 (这一步很重要
gclient sync --no-history
这一步会将很多子库资源下载下来,以及sysroot。这一步非常重要,不然后面会报很多很多错
这里llvm可以自己使用手动编译,方法在:https://chromium.googlesource.com/chromium/src/+/main/docs/clang.md
如果执行同步没有下载下来sysroot,可以手动执行:
cd ~/code/
python ./chromium_git/chromium/src/build/linux/sysroot_scripts/install-sysroot.py --arch amd64
python ./chromium_git/chromium/src/build/linux/sysroot_scripts/install-sysroot.py --arch arm64
python ./chromium_git/chromium/src/build/linux/sysroot_scripts/install-sysroot.py --arch mips64el
下载好后会在./chromium_git/chromium/src/build/linux
目录下看到系统文件的目录:
5. 编译cef:
x64:
cd ~/code/
export GN_DEFINES="is_official_build=true use_sysroot=true use_gtk=true is_cfi=false use_allocator=none use_allocator_shim=false symbol_level=1"
export GYP_DEFINES="disable_nacl=1 use_sysroot=1 buildtype=Official use_allocator=none"
export CEF_ARCHIVE_FORMAT=tar.bz2
export DEPOT_TOOLS_UPDATE=0
export CEF_STRIP_TOOL=strip
python3 automate/automate-git.py --download-dir=~/code/chromium_git --depot-tools-dir=~/code/depot_tools --branch=5112 --x64-build --build-target=cefsimple --no-update --no-debug-build
arm64:
export GN_DEFINES="is_official_build=true use_sysroot=true use_gtk=true is_cfi=false use_allocator=none use_allocator_shim=false symbol_level=1"
export GYP_DEFINES="disable_nacl=1 use_sysroot=1 buildtype=Official use_allocator=none"
export CEF_ARCHIVE_FORMAT=tar.bz2
export DEPOT_TOOLS_UPDATE=0
export CEF_INSTALL_SYSROOT=arm64
export CEF_STRIP_TOOL=aarch64-linux-gnu-strip
export GN_DEFINES="enable_widevine=true clang_use_chrome_plugins=false $GN_DEFINES"
export GYP_DEFINES="target_arch=arm64 arm_float_abid=hard enable_vr=false $GYP_DEFINES"
export GN_ARGS="-args=enable_widevine=true clang_use_chrome_plugins=false"
python3 automate/automate-git.py --download-dir=~/code/chromium_git --depot-tools-dir=~/code/depot_tools --branch=5112 --arm64-build --build-target=cefsimple --no-update --no-debug-build
mips64:
export GN_DEFINES="is_official_build=true use_sysroot=true use_gtk=true is_cfi=false use_allocator=none use_allocator_shim=false symbol_level=1"
export GYP_DEFINES="disable_nacl=1 use_sysroot=1 buildtype=Official use_allocator=none"
export CEF_ARCHIVE_FORMAT=tar.bz2
export DEPOT_TOOLS_UPDATE=0
export CEF_INSTALL_SYSROOT=mips64el
export CEF_STRIP_TOOL=mips64el-linux-gnuabi64-strip
export GN_DEFINES="enable_widevine=true clang_use_chrome_plugins=false use_custom_libcxx=false enable_dav1d_decoder=false chrome_pgo_phase=0 dcheck_always_on=false enable_background_mode=false enable_basic_printing=true enable_linux_installer=false enable_nacl=false enable_print_preview=true enable_resource_allowlist_generation=false fatal_linker_warnings=false ffmpeg_branding="Chrome" forbid_non_component_debug_builds=false is_component_build=false is_debug=false optimize_webui=true proprietary_codecs=true target_cpu="mips64el" treat_warnings_as_errors=false use_gnome_keyring=false use_thin_lto=false use_gold=false use_icf=false use_lld=true use_system_libdrm=false $GN_DEFINES"
export GYP_DEFINES="target_arch=mips64el enable_vr=false "$GYP_DEFINES
export GN_ARGS="-args=enable_widevine=true clang_use_chrome_plugins=false"
python3 automate/automate-git.py --download-dir=~/code/chromium_git --depot-tools-dir=~/code/depot_tools --branch=5112 --mips64el-build --build-target=cefsimple --no-update --no-debug-build
6. 源码改动
x64和arm原生代码可以编译通过,但是mips官方已经不再支持,编译过程需要有较多改动:
- 支持mips64el:
automate/automate-git.py
chromium_git/chromium/src/cef/tools/gn_args.py
chromium_git/chromium/src/third_party/swiftshader/third_party/marl/BUILD.gn
在以上文件中找arm64的地方,分别给加上mips64 的else - 遍历代码中所有包含的
LOONGSON
宏(一般是_MIPS_ARCH_LOONGSON
),全部都加上|| defined(__mips64__)
,因为交叉编译mips的编译器没有内置龙芯宏,会导致龙芯的改动无法生效。最终导致页大小不对在龙芯上运行崩溃。还有一些其他错误,包含在!defined(__aarch64__)
宏里,也需要加一下!defined(__mips64__)
chromium_git/chromium/src/base/process/memory_linux.cc
文件中,*result = __libc_malloc(size);
替换成*result = malloc(size);
,解决加了use_allocator_shim=false
参数后的编译错误,不加这个参数编译出来的cef 使用了tcmalloc会在内存分配时崩溃。chromium_git/chromium/src/media/gpu/BUILD.gn
文件改动注释掉assert(enable_av1_decoder)
chromium_git/chromium/src/third_party/breakpad/breakpad/src/common/linux
,这个目录下加上asm-mips
目录(从系统工具链或者以前版本的代码里拷贝过来),然后将src/third_party/breakpad/breakpad/src/common/linux/breakpad_getcontext.S
文件中的#include<asm-mips>
换成#include "asm-mips"
chromium_git/chromium/src/third_party/dav1d/config/linux/
下添加mips64el目录,从之前的源码里拷贝- 如果遇到
vulkan-deps
编译时编译器崩溃,可能是自己编译的llvm导致的,这里不要用自己编译的,还是通过gclient sync
下载原生的二进制编译器程序编译 - 编译ffmpeg项目找不到config.h config_components.h,这个找到源码记录发现官方后来不在支持mips64编译,给mips64el目录干掉了,用最后一个支持版本的文件拷贝过来也不好使,这里的解决方案是:拷贝arm64的,然后按照之前的版本对比arm64 和 mips64el差异改一下
libaom fatal error: 'config/aom_dsp_rtcd.h' file not found
,到chromium_git/chromium/src/third_party/libaom/source/config/linux
目录下直接拷贝一份generic命名为mips64el./clang_x64/flatc: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.26 not found
遇到类似的可执行程序执行错误,是下载下来的工具链在编译系统里无法运行,系统自带的libstdc++版本太低了,这里找到调用可执行程序的py,在前面加上一个环境变量。比如gn_run_binary.py
third_party/openscreen/src/tools/cddl/cddl.py v8/tools/run.py
等,里面加上:
+if sys.platform == "linux" :
+ os.environ["LD_LIBRARY_PATH"] = "../../third_party/llvm-build/Release+Asserts/lib/"
+
- 编译错误:
third_party/crashpad/crashpad/util/net/http_transport_libcurl.cc:241:2: error: Port
,打开文件加上ARCH_CPU_MIPS_FAMILY
宏 sandbox/linux/bpf_dsl/syscall_set.cc:22:15: error: use of undeclared identifier '__NR_64_Linux'
, 在mips的sysroot里,找到debian_sid_mips64el-sysroot/usr/include/mips64el-linux-gnuabi64/asm/unistd.h
,添加:
#define __NR_64_Linux 5000
#define __NR_64_Linux_syscalls 435
-
../../sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc:45:10: fatal error: 'asm/ptrace-abi.h' file not found
在文件里找到arm宏的位置加!defined(__mips64__)
-
third_party/crashpad/crashpad/snapshot/linux/cpu_context_linux.h:170:3: error: use of undeclared identifier 'memcpy'
错误,打开third_party/crashpad/crashpad/snapshot/linux/cpu_context_linux.h
文件,mips宏下加
#include<wchar.h>
#include<string.h>
然后在文件:third_party/crashpad/crashpad/snapshot/linux/cpu_context_linux.cc
里,删掉LOG相关:
- #include "base/logging.h"
- LOG(WARNING) << "pstate truncation: we only expect the SPSR bits to ...
third_party/tflite_support/src/tensorflow_lite_support/cc/task/core/category.h:36:12: error: using integer absolute value function 'abs' when argument is of floating point type
,这里直接将abs改为std::abs- 链接
cef:error: undefined symbol: ff_fft_init_mips
,这个在ffmpeg_generated.gni
文件里找到aarch64/cpu.c
的地方,在arm架构的上下文里添加:
+if ((use_linux_config && current_cpu == "mips64el") || (use_linux_config && current_cpu == "mipsel")) {
+ ffmpeg_c_sources += [
+ "libavcodec/mips/fft_mips.c",
+ "libavcodec/mips/h264pred_init_mips.c",
+ "libavcodec/mips/hpeldsp_init_mips.c",
+ "libavcodec/mips/vp3dsp_init_mips.c",
+ "libavcodec/mips/vp8dsp_init_mips.c",
+ "libavcodec/mips/mpegaudiodsp_mips_float.c",
+ "libavcodec/mips/videodsp_init.c",
+ "libavutil/mips/cpu.c",
+ "libavutil/mips/float_dsp_mips.c",
+ "libavcodec/mips/h264chroma_init_mips.c",
+ "libavcodec/mips/h264dsp_init_mips.c",
+ "libavcodec/mips/h264qpel_init_mips.c",
+ ]
+}
+
+if ((is_android && current_cpu == "mips64el" && ffmpeg_branding == "Chrome") || (is_android && current_cpu == "mipsel" && ffmpeg_branding == "Chrome") || (use_linux_config && current_cpu == "mips
64el" && ffmpeg_branding == "Chrome") || (use_linux_config && current_cpu == "mips64el" && ffmpeg_branding == "ChromeOS") || (use_linux_config && current_cpu == "mipsel" && ffmpeg_branding == "Chr
ome") || (use_linux_config && current_cpu == "mipsel" && ffmpeg_branding == "ChromeOS")) {
+ ffmpeg_c_sources += [
+ "libavcodec/mips/aacdec_mips.c",
+ "libavcodec/mips/aacpsdsp_mips.c",
+ "libavcodec/mips/aacsbr_mips.c",
+ "libavcodec/mips/sbrdsp_mips.c",
+ ]
+}
+
- 手动打包:
/usr/bin/python3 make_distrib.py --output-dir=../binary_distrib/ --allow-partial --ninja-build --mips64el-build
这里同样要修改make_distrib.py 脚本让它支持--mips64el-build