envoy
envoy copied to clipboard
Cannot Generate Compile Commands After Building Envoy on Ubuntu
I’ve successfully compiled Envoy from source on Ubuntu 24.04 using the following command:
ENVOY_DOCKER_BUILD_DIR=/mnt/data/ ./ci/run_envoy_docker.sh './ci/do_ci.sh dev'
Everything works, and I can run tests without any issues. However, I am unable to generate compile commands as described in the ci/README.md. I tried the following command:
ENVOY_DOCKER_BUILD_DIR=/mnt/data/ ./ci/run_envoy_docker.sh 'ENVOY_GEN_COMPDB_OPTIONS="--vscode --exclude_contrib" ./ci/do_ci.sh refresh_compdb'
This results in the following error, where the build fails due to ld not being found:
ENVOY_SRCDIR=/source
ENVOY_BUILD_TARGET=//source/exe:envoy-static
ENVOY_BUILD_ARCH=x86_64
Setting test_tmpdir to /build/tmp.
building using 8 CPUs
building for x86_64
Starting local Bazel server and connecting to it...
INFO: Analyzed target //tools/proto_format:proto_sync (665 packages loaded, 14754 targets configured).
INFO: Found 1 target...
ERROR: /build/bazel_root/base-envoy-compdb/external/com_google_protobuf/src/google/protobuf/editions/BUILD:47:10: Linking external/com_google_protobuf/src/google/protobuf/editions/internal_defaults_escape [for tool] failed: (Exit 1): gcc failed: error executing command (from target @com_google_protobuf//src/google/protobuf/editions:internal_defaults_escape)
(cd /build/bazel_root/base-envoy-compdb/sandbox/processwrapper-sandbox/9/execroot/envoy && \
exec env - \
BAZEL_VOLATILE_DIRTY=1 \
PATH=/bin:/usr/bin:/usr/local/bin \
PWD=/proc/self/cwd \
/usr/bin/gcc @bazel-out/k8-opt-exec-2B5CBBC6/bin/external/com_google_protobuf/src/google/protobuf/editions/internal_defaults_escape-2.params)
# Configuration: 2eccf2a2a91c7ef3bd4ee007873573a1355917ac1e32859bda620a7818032621
# Execution platform: @local_config_platform//:host
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
collect2: fatal error: cannot find 'ld'
compilation terminated.
Target //tools/proto_format:proto_sync failed to build
INFO: Elapsed time: 8.777s, Critical Path: 1.51s
INFO: 10 processes: 8 internal, 2 processwrapper-sandbox.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target
I’ve also tried to run the following command from within the container, which gives the same error as above:
ENVOY_GEN_COMPDB_OPTIONS="--vscode --exclude_contrib" ./ci/run_envoy_docker.sh './ci/do_ci.sh refresh_compdb'
The only workaround I’ve found that works is to add the setup_clang_toolchain call to the refresh_compdb target in the ci/do_ci.sh, which successfully generates the compile commands:
refresh_compdb)
setup_clang_toolchain # ADDED LINE
# Override the BAZEL_STARTUP_OPTIONS to setting different output directory.
# So the compdb headers won't be overwritten by another bazel run.
for i in "${!BAZEL_STARTUP_OPTIONS[@]}"; do
if [[ ${BAZEL_STARTUP_OPTIONS[i]} == "--output_base"* ]]; then
COMPDB_OUTPUT_BASE="${BAZEL_STARTUP_OPTIONS[i]}"-envoy-compdb
BAZEL_STARTUP_OPTIONS[i]="${COMPDB_OUTPUT_BASE}"
BAZEL_STARTUP_OPTION_LIST="${BAZEL_STARTUP_OPTIONS[*]}"
export BAZEL_STARTUP_OPTION_LIST
fi
done
# ........ REST OF THE CODE
Is there a particular issue I am missing, or is there a problem with the compilation process when generating compile commands ?
cc @wbpcode
@mtmucha Hi, thanks for reporting this. I think this is because we change the active env of our CI recently and you patch is the correct way to fix it.
It would be appreciated if you can create a PR for that. Of course, if you have no time, I am happy to fix it. :)
@wbpcode Hello, no problem. I'm happy to help. The pull request has been created.
Hello, @wbpcode
While running the Refresh Compilation Database vs code task (or alternatively the refresh_compdb.sh script), I encountered the same issue described by @mtmucha.
The problem can be resolved by adding the following lines to the script (which is a duplicate of the setup_clang_toolchain function of the do_ci.sh script).
Can the refresh_compdb.sh file be removed and replaced with ci/do_ci.sh refresh_compdb in the tasks.json file?
If not, would it be okay if I make a pull request to duplicate the setup_clang_toolchain function into refresh_compdb.sh?
This is my suggestion to apply to VSCode tasks: change
Or this one to apply to specific scripts: change
Can the refresh_compdb.sh file be removed and replaced with ci/do_ci.sh refresh_compdb in the tasks.json file?
SGTM.
I opened https://github.com/envoyproxy/envoy/pull/37668 for this. I would greatly appreciate it if you could review it at your convenience.