5

编译 envoy 生成 compile_commands.json

 2 years ago
source link: https://tangxinfa.github.io/article/7f168bd1-envoy-751f6210-compile_commands.json.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

编译 envoy 生成 compile_commands.json

前面的文章 完美的 c++ 项目代码定义跳转 介绍了对使用 Bazel 进行构建的项目生成 compile_commands.jsonenvoy 是使用 Bazel 进行构建的大型 c++ 开源项目,使用 rtags 的代码跳转功能可以方便地调试、阅读 envoy 源代码。

最新的 envoy 已包含创建 compile_commands.json 相关脚本,但是缺乏相关使用文档,这里我们选择为 envoy 1.7.0 手工创建 compile_commands.json

下载 envoy 1.7.0 源代码

git clone https://github.com/envoyproxy/envoy.git -b v1.7.0

安装 Bazel

参考 envoy/README.md 安装 Bazelisk 以支持使用任意 Bazel 版本

sudo mkdir -p /opt/local/bin
sudo wget -O /opt/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v0.0.8/bazelisk-linux-amd64
sudo chmod +x /opt/local/bin/bazel
export PATH=/opt/local/bin/:$PATH

下载 Bazel_and_CompileCommands

使用 vincent-picaud/Bazel_and_CompileCommands 的 fork 版本,以支持传入构建参数

cd ~/Opensource/
git clone [email protected]:tangxinfa/Bazel_and_CompileCommands.git -b fix-build-arguments

指定 Bazel 版本

Envoy 最新版本通过 .bazelversion 文件指明使用的 Bazel 版本,envoy v1.7.0 需要手工设置。运行命令 ci/run_envoy_docker.sh "bazel version" 得知 envoy v1.7.0 需要 bazel 0.13.0。

export USE_BAZEL_VERSION=0.13.0

指定 Python 版本

Archlinux 默认的 Python 版本为 python3,需要使用 python2

alias python=python2

安装 gcc5

Envoy v1.7.0 使用最新版本的 gcc 进行编译会有大量的编译错误,改用 gcc5

yaourt -S gcc5

修复 tclap 项目地址错误

tclap 项目已从 http://github.com/eile/tclap 迁到 https://github.com/mirror/tclap

替换 bazel/repositories.bzl bazel/repository_locations.bzl 中的 eilemirror

修复 gettid 重复定义的错误

编译过程中有几处 gettid 定义错误,如

In file included from /usr/include/unistd.h:1170:0,
                 from external/com_github_grpc_grpc/src/core/lib/gpr/log_linux.cc:41:
/usr/include/bits/unistd_ext.h:34:16: note: old declaration '__pid_t gettid()'
 extern __pid_t gettid (void) __THROW;
                ^
external/com_github_grpc_grpc/src/core/lib/iomgr/ev_epollex_linux.cc: In function 'long int gettid()':
external/com_github_grpc_grpc/src/core/lib/iomgr/ev_epollex_linux.cc:989:24: error: ambiguating new declaration of 'long int gettid()'
 static long gettid(void) { return syscall(__NR_gettid); }
                        ^

~.cache/bazel 目录下找到对应的文件,并删除 gettid 函数定义

编译 Envoy 生成 compile_commands.json

~/Opensource/Bazel_and_CompileCommands/setup_compile_commands.sh
~/Opensource/Bazel_and_CompileCommands/create_compile_commands.sh \
  --action_env CC=/usr/bin/gcc-5 \
  --action_env CPP=/usr/bin/cpp-5 \
  --action_env CXX=/usr/bin/c++-5 \
  --verbose_failures //source/exe:envoy-static
2019年12月19日 20时 envoy

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK