envoyproxy / envoyproxy/envoy

Get include-what-you-use work for Envoy

Open
#12,853 2 comments 1 reaction 0 assignees View on GitHub
area/build help wanted
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 20h
Merged PRs (30d)
428

Description

Title: Get include-what-you-use work for Envoy

Description:
There are lots of include-what-you-use violations in Envoy:
1. over-inclusion: including too many unused headers slows down compilation.
2. transitive-inclusion: some of the missing explicit includes will make further development difficult.

[include-what-you-use](https://include-what-you-use.org/) is powerful to address those violations and fix them.

@htuch mentioned at #10917 that we need to get it work for Envoy.

I tried on my own development environment and it works.

Here are steps to get it work:

1. follow instructions at [Instructions for developers] (https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md) to build iwyu
2. generate compilation database by
```
tools/gen_compilation_database.py --include_headers
```
3. replace `-stdlib=libc++` `-stdlib=libstdc++` in the generated json file `compile_commands.json`

4. run ` iwyu_tool.py -p .` at Envoy root directory. (Please refer to section "Using with a compilation database" from [Instructions for developers] (https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md) for details)

The output shall look like this

```
...
source/common/grpc/google_async_client_impl.cc should add these lines:
#include // for GPR_CLOCK_REALTIME
#include // for gpr_inf_future
#include // for Channel
#include // for ClientAsyncReader...
#include // for WriteOptions
#include // for string_ref
#include // for duration
#include // for tie, tuple
#include "absl/strings/match.h" // for EndsWith
#include "common/grpc/stat_names.h" // for StatNames
#include "common/http/header_map_impl.h" // for RequestHeaderMapImpl
#include "common/protobuf/utility.h" // for PROTOBUF_GET_WRAP...
#include "common/stats/symbol_table_impl.h" // for StatName
#include "envoy/api/api.h" // for Api
#include "envoy/common/time.h" // for TimeSource
#include "envoy/stats/stats.h" // for Counter

source/common/grpc/google_async_client_impl.cc should remove these lines:
- #include "common/config/datasource.h" // lines 9-9
- #include "common/grpc/common.h" // lines 10-10
- #include "common/grpc/google_grpc_creds_impl.h" // lines 11-11
- #include "grpcpp/support/proto_buffer_reader.h" // lines 15-15

The full include-list for source/common/grpc/google_async_client_impl.cc:
#include "common/grpc/google_async_client_impl.h"
#include // for GPR_CLOCK_REALTIME
#include // for gpr_inf_future
#include // for Channel
#include // for ClientAsyncReader...
#include // for WriteOptions
#include // for string_ref
...
```

It will be useful if we can apply the iwyu check to every pull request to check iwyu violations.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.